Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force Current version into styling #17

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
0b49c39
Added start/end via current hunt
JasonLovesDoggo Dec 3, 2023
0e57709
I'm clownin
JasonLovesDoggo Dec 3, 2023
701f97c
switched all references of settings.start or end to Hunt start/end
JasonLovesDoggo Dec 3, 2023
c4c3745
format
Dec 3, 2023
b2889e9
.idea then I sleep
JasonLovesDoggo Dec 3, 2023
22e8030
time sensitive + cleaner
JasonLovesDoggo Dec 3, 2023
5b189c0
updated .gitignore
JasonLovesDoggo Dec 3, 2023
775a010
updated .gitignore
JasonLovesDoggo Dec 3, 2023
cfca466
Updates credits
JasonLovesDoggo Dec 3, 2023
9982a27
migrations go brrt
JasonLovesDoggo Dec 3, 2023
e47586a
format
Dec 3, 2023
c1df39b
Added some helper fields to Hunt
JasonLovesDoggo Dec 3, 2023
9c65374
reamed after_start to during_hunt to reflect it's internal changes
JasonLovesDoggo Dec 3, 2023
f643162
renamed Hunt.early_access_users to Hunt.testers
JasonLovesDoggo Dec 3, 2023
d65e2fd
Merge remote-tracking branch 'origin/temp' into temp
JasonLovesDoggo Dec 3, 2023
1aec86c
add manual migration (untested)
JasonLovesDoggo Dec 3, 2023
86ca833
add scavenger.iml to gitignore since I have different configs on win/…
JasonLovesDoggo Dec 4, 2023
29a39ea
Fixed incorrect ternary op
JasonLovesDoggo Dec 4, 2023
2c4ac15
adds black.
JasonLovesDoggo Dec 4, 2023
4e0506e
added dynamic hunt naming
JasonLovesDoggo Dec 4, 2023
5dc0256
Updated usages to support joining a team before the event started
JasonLovesDoggo Dec 4, 2023
c3c008a
format
Dec 4, 2023
33b493c
docs: improved docs for starting, middle and ending locations.
JasonLovesDoggo Dec 4, 2023
6654503
format
Dec 4, 2023
a42184a
fix: assigning hunt as bool
JasonLovesDoggo Dec 4, 2023
29f0dae
remove useless assignment
JasonLovesDoggo Dec 4, 2023
49d7986
remove useless assignment
JasonLovesDoggo Dec 4, 2023
13dc668
fix typo
JasonLovesDoggo Dec 4, 2023
56ec5cd
fix typo
JasonLovesDoggo Dec 4, 2023
a479ae5
fix change to list
JasonLovesDoggo Dec 4, 2023
5114158
format
Dec 4, 2023
3fc3d80
what
JasonLovesDoggo Dec 4, 2023
a6f64fc
typehinting
JasonLovesDoggo Dec 4, 2023
8de9654
fix reference to old/new Queryset
JasonLovesDoggo Dec 4, 2023
bfa56b2
little TODO
JasonLovesDoggo Dec 4, 2023
5411871
format
Dec 4, 2023
afa8ed8
added checking for skipping
JasonLovesDoggo Dec 4, 2023
a310f26
Merge remote-tracking branch 'origin/temp' into temp
JasonLovesDoggo Dec 4, 2023
3f2d8a4
allow user to reload the page lol
JasonLovesDoggo Dec 4, 2023
4b01d1f
comments for calc time
JasonLovesDoggo Dec 4, 2023
9d5dd6a
format
Dec 4, 2023
cba3ac0
Updates context_processors to support all ranges of events (will refa…
JasonLovesDoggo Dec 5, 2023
2b64529
refactor: rename nextqr to nexthint
JasonLovesDoggo Dec 5, 2023
54813cd
Merge remote-tracking branch 'origin/temp' into temp
JasonLovesDoggo Dec 5, 2023
c9f84b6
format
Dec 5, 2023
e47d052
fix typo
JasonLovesDoggo Dec 5, 2023
8560a20
Merge remote-tracking branch 'origin/temp' into temp
JasonLovesDoggo Dec 5, 2023
ffae7bf
style: improved class naming
JasonLovesDoggo Dec 5, 2023
cba5686
FINALLY fixes timer
JasonLovesDoggo Dec 5, 2023
a004d18
renames nextqr to nexthint as it's simplythe hint not the qr result
JasonLovesDoggo Dec 5, 2023
11adf06
adds global hunt processor (displays current or closest (ended or upc…
JasonLovesDoggo Dec 5, 2023
4ba0938
style: fmt
JasonLovesDoggo Dec 5, 2023
a2f69d3
oop, removed debug print
JasonLovesDoggo Dec 5, 2023
bfc9d03
correct error message
JasonLovesDoggo Dec 5, 2023
20ac7eb
I18N: remove eng "translations" and remake ja_JP
JasonLovesDoggo Dec 5, 2023
5417e7f
format
Dec 5, 2023
e8f520d
updated hunt context proc to show if there is a future hunt
JasonLovesDoggo Dec 5, 2023
bdfd490
fix: index shows scav started after end
JasonLovesDoggo Dec 5, 2023
8999b60
Merge remote-tracking branch 'origin/temp' into temp
JasonLovesDoggo Dec 5, 2023
648c1a1
I rly can't nix
JasonLovesDoggo Dec 5, 2023
bc92280
fix: error on creating new hunt's
JasonLovesDoggo Dec 5, 2023
759f9ce
fix: wrong settings for middle locations / ending_location
JasonLovesDoggo Dec 5, 2023
5ce3779
remove null for M2M
JasonLovesDoggo Dec 5, 2023
eb83b0c
add migration for prev commits
JasonLovesDoggo Dec 5, 2023
1470434
feat: allow isolating teams PER EVENT 😲😲😲😲 (still needs some fixing)
JasonLovesDoggo Dec 5, 2023
e973ba2
ADMIN
JasonLovesDoggo Dec 5, 2023
57ef811
optimize imports
JasonLovesDoggo Dec 5, 2023
ff45a3d
fix HOW
JasonLovesDoggo Dec 5, 2023
329788e
limit team names per hunt
JasonLovesDoggo Dec 5, 2023
a14c3cf
whoopsie that's a bool
JasonLovesDoggo Dec 5, 2023
6f4b06e
update all instances of user.team to use the new user.current_team
JasonLovesDoggo Dec 5, 2023
e349549
remigrate things
JasonLovesDoggo Dec 5, 2023
f72356c
rename belongs_to to hunt
JasonLovesDoggo Dec 5, 2023
749550a
fix: .get to .filter as .get doesnt return None
JasonLovesDoggo Dec 5, 2023
e1bfac2
block_if_current_hunt
JasonLovesDoggo Dec 5, 2023
754ec2a
format
Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ __pycache__
.direnv
/db.sqlite3
/venv
.idea/workspace.xml
.idea/misc.xml
.idea/scavenger.iml
```
7 changes: 6 additions & 1 deletion .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

27 changes: 0 additions & 27 deletions .idea/runConfigurations/Scavenger_.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/scavenger.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

457 changes: 0 additions & 457 deletions .idea/workspace.xml

This file was deleted.

62 changes: 33 additions & 29 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
from django.contrib import admin
from django.contrib import admin, messages
from django.contrib.auth.admin import UserAdmin as UserAdmin_
from django.contrib.auth.models import Group
from django.db.models import QuerySet
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.urls import reverse
from django.db.models import QuerySet

from .forms import *


@admin.action(
permissions=["change"],
description=_("Set selected users as a Location Setter"),
description=_("Set selected users as a Logic Puzzle Setter"),
)
def set_as_location_setter(modeladmin, request, queryset: QuerySet[User]):
def set_as_logic_setter(modeladmin, request, queryset: QuerySet[User]):
for user in queryset:
user.is_staff = True
# set their group to location setter
user.groups.add(Group.objects.get(name="Location Setter"))
user.groups.add(Group.objects.get_or_create(name="Logic Logic Puzzle Setters"))


@admin.action(
permissions=["change"],
description=_("Set selected users as a Logic Puzzle Setter"),
description=_("Remove selected users as a Logic Puzzle Setter"),
)
def set_as_logic_setter(modeladmin, request, queryset: QuerySet[User]):
def remove_as_logic_setter(modeladmin, request, queryset: QuerySet[User]):
for user in queryset:
user.is_staff = True
# set their group to location setter
user.groups.add(Group.objects.get(name="Logic Logic Puzzle Setters"))
user.groups.remove(Group.objects.get(name="Logic Logic Puzzle Setters"))


class HintsInLine(admin.StackedInline):
Expand All @@ -54,26 +52,13 @@ class LogicPuzzleAdmin(admin.ModelAdmin):
ordering = ("qr_index",)


@admin.action(description="Mark selected teams as inactive")
def set_inactive(modeladmin, request, queryset):
if request.user.is_superuser:
queryset.update(is_active=False)


@admin.action(description="Mark selected teams as active")
def set_active(
modeladmin, request, queryset
): # note you could probably remove this one.
if request.user.is_superuser:
queryset.update(is_active=True)


class TeamAdmin(admin.ModelAdmin):
readonly_fields = ("path", "members")
inlines = [
InviteInLine,
]
actions = [set_inactive, set_active]
search_fields = ("name", "members__username")
list_filter = ("hunt",)

@admin.display(description="Path")
def path(self, team):
Expand Down Expand Up @@ -113,21 +98,40 @@ def url(self, qr):
if qr.id:
return format_html(
mark_safe('<a href="{}">{}</a>'),
(url := reverse("qr", kwargs=dict(key=qr.key))),
reverse("qr", kwargs=dict(key=qr.key)),
_("Link to Hint Page"),
)
else:
return ""


class HuntAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
# todo: add warning if admin attempts to change path length or middle locations when hunt has started (will basically re-randomize the hunt (I THINK))

# extras = 1 if obj.starting_location else 0
# extras += 1 if obj.ending_location else 0
super().save_model(request, obj, form, change)
if obj.path_length > obj.middle_locations.count():
messages.warning(
request,
"The path length is longer than the amount of locations. "
"If you do not increase middle locations or decrease path length, "
"the path length will be reduced to the amount of locations.",
)
# raise ValidationError(
# "The path length is longer than the amount of locations. Please increase the amount of locations or decrease the path length."
# )


class UserAdmin(UserAdmin_):
readonly_fields = (
"username",
"first_name",
"last_name",
"email",
)
actions = [set_as_location_setter, set_as_logic_setter]
actions = [set_as_logic_setter, remove_as_logic_setter]
admin_field = list(UserAdmin_.fieldsets)
admin_field[0][1]["fields"] = (
"username",
Expand All @@ -148,5 +152,5 @@ class UserAdmin(UserAdmin_):
admin.site.register(Team, TeamAdmin)
admin.site.register(QrCode, QrCodeAdmin)
admin.site.register(LogicPuzzleHint, LogicPuzzleAdmin)
admin.site.register(Hunt)
admin.site.register(Hunt, HuntAdmin)
admin.site.register(Invite)
65 changes: 57 additions & 8 deletions core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
import datetime

from django.conf import settings
from django.contrib import messages
from django.utils import timezone

from core.models import Hunt


def hunt(request) -> dict:
"""
returns:
hunt: the current hunt or the closest hunt
FUTURE_HUNT_EXISTS: bool, if a future hunt exists
"""

return dict(
hunt=Hunt.current_hunt() or Hunt.closest_hunt(),
FUTURE_HUNT_EXISTS=Hunt.next_hunt() is not None,
)


def start(request) -> dict:
"""
returns info about the current/closest hunt
return dict:
START: start time of the current/closest hunt
BEFORE_START: bool, if the current time is before the start time
TIME_UNTIL_START: timedelta, time until the start time
END: end time of the current/closest hunt
BEFORE_END: bool, if the current time is before the end time
TIME_UNTIL_END: timedelta, time until the end time
IN_HUNT: bool, if the current time is between the start and end time
"""
now = timezone.now()
if Hunt.objects.count() == 0:
messages.add_message(
request,
messages.WARNING,
"No hunts are in the database. Please contact an admin to add a hunt to the database",
)
event_start = now + datetime.timedelta(weeks=75)
event_end = event_start + datetime.timedelta(hours=3)
elif (hunt := Hunt.current_hunt()) is not None:
event_start = hunt.start
event_end = hunt.end
elif Hunt.next_hunt() is not None:
hunt = Hunt.next_hunt()
event_start = hunt.start
event_end = hunt.end
else:
closest_hunt = Hunt.closest_hunt()
event_start = closest_hunt.start
event_end = closest_hunt.end

def start(request):
return dict(
START=(start := settings.START),
START_BEFORE=start > datetime.datetime.utcnow(),
START_UNTIL=start - datetime.datetime.utcnow(),
END=(end := settings.END),
END_BEFORE=end > datetime.datetime.utcnow(),
END_UNTIL=end - datetime.datetime.utcnow(),
START=event_start,
BEFORE_START=event_start > now,
TIME_UNTIL_START=event_start - now,
END=event_end,
BEFORE_END=event_end > now,
TIME_UNTIL_END=event_end - now,
IN_HUNT=(event_start < now < event_end),
)
Binary file removed core/locale/en_CA/LC_MESSAGES/django.mo
Binary file not shown.
Loading