Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Jan 2, 2024
2 parents 5478629 + a6d9e53 commit 254b4b1
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 61 deletions.
24 changes: 22 additions & 2 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,27 @@ class LogicPuzzleAdmin(admin.ModelAdmin):
class TeamAdmin(admin.ModelAdmin):
readonly_fields = ("path",)
inlines = [InviteInLine, TeamMemberInline]
search_fields = ("name", "members__username")
search_fields = (
"name",
"members__username",
"members__first_name",
"members__last_name",
)
list_display = (
"name",
"hunt",
"current_qr_i",
"member_count",
)
list_filter = ("hunt__name",)
ordering = (
"hunt",
"current_qr_i",
)

@staticmethod
def member_count(obj):
return obj.members.count()

@admin.display(description="The path that the team has/completed")
def path(self, team):
Expand Down Expand Up @@ -141,6 +160,7 @@ class UserAdmin(UserAdmin_):
"first_name",
"last_name",
"email",
"current_team",
)
actions = [
set_as_logic_setter,
Expand All @@ -153,7 +173,7 @@ class UserAdmin(UserAdmin_):
"username",
) # Scavenger does not control or store passwords. So, we don't need this field.
admin_field[2][1]["fields"] = tuple(
["send_to_admin"] + list(admin_field[2][1]["fields"])
list(admin_field[2][1]["fields"]) + ["send_to_admin"]
)

fieldsets = tuple(
Expand Down
17 changes: 15 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class User(AbstractUser):
send_to_admin = models.BooleanField(
default=False,
null=False,
help_text="If when a user scans a QR code, they should be sent to the admin page instead of the hint page. Useful for debugging.",
help_text="If when a user scans a QR code, they should be sent to the admin page instead of the hint page. Useful for debugging. User must be staff. (is_staff)",
)

@property
def is_debuggable(self):
def can_debug(self):
return self.send_to_admin and self.is_staff

@property
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions core/static/core/qr.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ main {
}

.text-container{
margin: auto;
width: 50%;

padding-left: 2em;
padding-right: 2em;
}
Expand All @@ -33,6 +36,9 @@ main {
.logic {
font-size: 2rem
}
.logic span {
font-size: 1rem;
}
.container {
display: grid;
place-items: center;
Expand Down
103 changes: 59 additions & 44 deletions core/templates/core/index.html
Original file line number Diff line number Diff line change
@@ -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 %}
<link rel="stylesheet" href="{% static 'core/index.css' %}"/>
<link rel="stylesheet" href="{% static 'core/index.css' %}"/>
{% 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 <a href="{{ first_url }}">first hint</a>!
{% endblocktranslate %}
<br />
{% url 'team_invite' as invite_url %}
{% blocktranslate %}
or, would you like to <a href="{{ invite_url }}">invite more team members</a>?
{% endblocktranslate %}
{% else %}
<h3>
{% 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
<a href={% url 'qr_first' %}>first hint</a>!
{% elif request.user.current_team.completed_hunt %} {# The team is done the hunt #}

{% hunt_ending_text request.user.current_team.hunt %}
<br>
{% blocktranslate %} Oh ho ho?
What lieth there? Tis the light at the end of the tunnel!! Congratulations valiant scavenger and thank you for playing!
<br>
<br>
You can view all of the logic hints {% endblocktranslate %}<a href={% url 'logic_clues' %}>{% translate 'here' %}</a>. | {% translate 'You found:' %} {{ request.user.current_team.hunt.total_locations }}{% translate ' Qr Codes' %}

<a class="button" href="{% url 'team_invite' %}">{% translate "invite more team members" %}</a>

<a class="button" href="{% url 'team_leave' %}">{% translate "leave team" %}</a>
{% endif %}
{% endif %}
</h3>
<ul class="nodot">
{% if not request.user.in_team %}
<li>
<a class="button" href="{% url 'join' %}">{% translate "join a team" %}</a>
</li>
<li>
<a class="button" href="{% url 'team_create' %}">{% translate "create a team" %}</a>
</li>
{% endif %}
</ul>
{% endif %}
{% else %}
<h2>
{% else %}
{{ hunt_name }} is in progress! go decrypt your
<a href={% url 'qr_current' %}>current hint</a>!
{% endif %}
<br/>
{% endif %}

<h3>
{% if not IN_HUNT or request.user.current_team.hunt.allow_creation_post_start %}
<ul class="nodot">
<li>
<a class="button"
href="{% url 'team_invite' %}">{% translate "invite more team members" %}</a>
</li>

<li><a class="button" href="{% url 'team_leave' %}">{% translate "leave team" %}</a></li>
</ul>
{% endif %}
</h3>

{% else %}
{% if not request.user.in_team %}
<ul class="nodot"> {# If The user is not in a team #}

<li>
<a class="button" href="{% url 'join' %}">{% translate "join a team" %}</a>
</li>
<li>
<a class="button" href="{% url 'team_create' %}">{% translate "create a team" %}</a>
</li>
</ul>
{% endif %}

{% endif %}
{% else %} {# Not in a hunt and no future hunt is scheduled #}
<h2>
{% blocktranslate %}
no future scavenger hunt is scheduled, please check back later
no future scavenger hunt is scheduled, please check back later
{% endblocktranslate %}
{% endif %}
</h2>
</h2>
{% endblock %}
15 changes: 8 additions & 7 deletions core/templates/core/qr.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
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)
</script>
{% endif %}
{% endblock %}


{% block body %}
<div class="text-container">
{% if not first and qr is not None %}
{% if not first and qr is not None and on_qr %}
<div class="hint-top">
{% translate "your team found:" %} <br />
{% hint qr request.user.current_team as hint %}
<span class="hint-content">{{ hint |mistune }}</span>
{% if request.user.is_superuser %}
<span style="font-size: 1rem">({{ qr }} <a class="link" href="{% url 'admin:core_qrcode_change' object_id=qr.id %}">{% translate "change" %}</a>)</span>
<span style="font-size: 0.5rem"><a class="link" href="{% url 'admin:core_qrcode_change' object_id=qr.id %}">{% translate "change" %}</a>)</span>
{% endif %}
</div>
<hr class="separator"/>
{% endif %}
{% if not offpath %}
<div class="hint">
Expand All @@ -55,18 +55,19 @@
{% hint nexthint request.user.current_team as hint %}
<span class="hint-content">{{ hint|mistune }}</span>
{% if request.user.is_superuser %}
<span style="font-size: 1rem">({{ nexthint }} <a class="link" href="{% url 'admin:core_qrcode_change' object_id=nexthint.id %}">change</a>)</span>
<span style="font-size: 0.5rem"><a class="link" href="{% url 'admin:core_qrcode_change' object_id=nexthint.id %}">{% translate "change" %}</a>)</span>
{% endif %}

{% if logic_hint %}
<hr class="separator"/>
<div class="logic">
<p style="font-size: 1.5rem">Logic Hint:</p>
<p>{{ logic_hint }}</p>
<span >{{ logic_hint }}</span>
<p style="font-size: 1.3rem">you can view all of your logic hints <a href={% url 'logic_clues' %}>here</a> </p>
</div>
{% 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! <br /> Congratulations valiant scavenger and thank you for playing!' %}
{% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/templatetags/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions core/views/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ def qr(request, key):
context = dict(first=False)
codes = QrCode.code_pks(request.user.current_team)
qr_code: QrCode | None = QrCode.objects.filter(key=key).first()
if request.user.is_debuggable:
if request.user.can_debug:
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)
Expand Down Expand Up @@ -183,7 +183,7 @@ def qr_current(request):
if i == 0: # on first qr code
return redirect(reverse("qr_first"))
i -= 1 # we want the index that they are AT not the next one
context = dict(current=True)
context = dict(current=True, on_qr=False)
codes = QrCode.codes(request.user.current_team)
context["qr"] = codes[i]
context["nexthint"] = None if len(codes) <= (j := i + 1) else codes[j]
Expand Down

0 comments on commit 254b4b1

Please sign in to comment.