From c389472152006a9b11eedd564de46062c778d270 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 20 Dec 2023 02:23:48 -0500 Subject: [PATCH] I hope I didn't break anything (rollback ig ) fix a few issues + QOL stuff. honestly just read the code. --- core/models.py | 13 +++++ core/templates/core/index.html | 103 +++++++++++++++++++-------------- core/templates/core/qr.html | 5 +- core/templatetags/qr.py | 2 +- core/views/qr.py | 6 +- 5 files changed, 79 insertions(+), 50 deletions(-) diff --git a/core/models.py b/core/models.py index 744071a..9cbdfd8 100644 --- a/core/models.py +++ b/core/models.py @@ -198,6 +198,10 @@ def update_current_qr_i(self, i: int): def is_full(self): return self.members.count() >= self.hunt.max_team_size + @property + def completed_hunt(self): + return self.current_qr_i >= self.hunt.total_locations + @property def is_empty(self): return self.members.count() == 0 @@ -303,6 +307,15 @@ class Hunt(models.Model): def __str__(self): return self.name + @property + def total_locations(self) -> int: + mid = min( + self.path_length, self.middle_locations.count() + ) # if mid-locations are less than path length, use mid-locations as it will have been cut + mid += 1 if self.ending_location else 0 + mid += 1 if self.starting_location else 0 + return mid + @classmethod def closest_hunt(cls) -> Hunt | None: now = timezone.now() diff --git a/core/templates/core/index.html b/core/templates/core/index.html index abb9483..b7000b6 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1,65 +1,80 @@ {% extends "core/base.html" %} {% load i18n %} {% load static %} +{% load qr %} {% block title %} -{% translate "Scavenger Hunt" %} + {% translate "Scavenger Hunt" %} {% endblock %} {% block header %} -{% blocktranslate with username=request.user.username %} -welcome, {{ username }}! -{% endblocktranslate %} + {% blocktranslate with username=request.user.username %} + welcome, {{ username }}! + {% endblocktranslate %} {% endblock %} {% block head_end %} - + {% endblock %} {% block body %} -{% if IN_HUNT or FUTURE_HUNT_EXISTS %} - {% if request.user.in_team and IN_HUNT %} - {% url 'qr_first' as first_url %} {% comment %}todo: add logic to swich text to /current{% endcomment %} - {% url 'qr_current' as current_url %} - {% blocktranslate %} - {{ hunt_name }} has started! go decrypt your first hint! - {% endblocktranslate %} -
- {% url 'team_invite' as invite_url %} - {% blocktranslate %} - or, would you like to invite more team members? - {% endblocktranslate %} - {% else %} -

- {% if request.user.in_team %} - {% blocktranslate with team=request.user.current_team.name %} - your team: {{ team }} - {% endblocktranslate %} - {% if not IN_HUNT or request.user.team.hunt.allow_creation_post_start %} + {% if IN_HUNT or FUTURE_HUNT_EXISTS %} + {% if request.user.in_team %} + {% if IN_HUNT %} + {% if request.user.current_team.current_qr_i == 0 %} + {{ hunt_name }} has started! go decrypt your + first hint! + {% elif request.user.current_team.completed_hunt %} {# The team is done the hunt #} + + {% hunt_ending_text request.user.current_team.hunt %} +
+ {% blocktranslate %} Oh ho ho? + What lieth there? Tis the light at the end of the tunnel!! Congratulations valiant scavenger and thank you for playing! +
+
+ You can view all of the logic hints {% endblocktranslate %}{% translate 'here' %}. | {% translate 'You found:' %} {{ request.user.current_team.hunt.total_locations }}{% translate ' Qr Codes' %} - {% translate "invite more team members" %} - {% translate "leave team" %} - {% endif %} - {% endif %} -

- - {% endif %} -{% else %} -

+ {% else %} + {{ hunt_name }} is in progress! go decrypt your + current hint! + {% endif %} +
+ {% endif %} + +

+ {% if not IN_HUNT or request.user.current_team.hunt.allow_creation_post_start %} + + {% endif %} +

+ + {% else %} + {% if not request.user.in_team %} + + {% endif %} + + {% endif %} + {% else %} {# Not in a hunt and no future hunt is scheduled #} +

{% blocktranslate %} - no future scavenger hunt is scheduled, please check back later + no future scavenger hunt is scheduled, please check back later {% endblocktranslate %} {% endif %} -

+ {% endblock %} diff --git a/core/templates/core/qr.html b/core/templates/core/qr.html index 51ef056..6661c1e 100644 --- a/core/templates/core/qr.html +++ b/core/templates/core/qr.html @@ -19,12 +19,13 @@ src.onmessage = (e) => { console.log('msg', e) } - // src.onmessage = (e) => location.reload() + // src.onmessage = (e) => location.reload() this a cool idea but we need to add more to it. setInterval(() => console.log(src.readyState), 1000) {% endif %} {% endblock %} + {% block body %}
{% if not first and qr is not None %} @@ -66,7 +67,7 @@
{% endif %} {% else %} - {% ending_block request.user.current_team.hunt %} + {% hunt_ending_text request.user.current_team.hunt %} {% translate 'Oh ho? What lieth there? Tis the light at the end of the tunnel!
Congratulations valiant scavenger and thank you for playing!' %} {% endif %} diff --git a/core/templatetags/qr.py b/core/templatetags/qr.py index 9a7fda2..1fe208c 100644 --- a/core/templatetags/qr.py +++ b/core/templatetags/qr.py @@ -18,7 +18,7 @@ def join_url(code): @register.simple_tag -def ending_block(hunt): +def hunt_ending_text(hunt): pattern = r"{{(.*?)}}" match = re.search(pattern, hunt.ending_text) diff --git a/core/views/qr.py b/core/views/qr.py index f2327f3..d62979d 100644 --- a/core/views/qr.py +++ b/core/views/qr.py @@ -129,17 +129,17 @@ def qr(request, key): if request.user.is_debuggable: return redirect(qr_code.get_admin_url()) context["qr_code"]: QrCode + current_i = min(request.user.current_team.current_qr_i, len(codes) - 1) if qr_code is None: # User just tried brute-forcing keys... lol context["offpath"] = True return render(request, "core/qr.html", context=context) elif ( - qr_code.id == codes[request.user.current_team.current_qr_i - 1] - and len(codes) > 1 + qr_code.id == codes[current_i - 1] and len(codes) > 1 ): # the user reloaded the page after advancing...or there is only one qr code in the hunt return redirect(reverse("qr_current")) elif ( - qr_code.id != codes[request.user.current_team.current_qr_i] + qr_code.id != codes[current_i] ): # fix index out of range (should have been the above anyhow) """ Either the user skipped ahead (is on path) or they found a random qr code (not on path)