Skip to content

Commit

Permalink
add team recrution page
Browse files Browse the repository at this point in the history
  • Loading branch information
nyiyui committed Dec 12, 2022
1 parent ed3e492 commit 07e93c4
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 19 deletions.
4 changes: 2 additions & 2 deletions scavenger2022/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def __str__(self):


def generate_invite_code():
return secrets.token_hex(3)
return secrets.token_hex(4)


class Invite(models.Model):
invites = models.IntegerField(default=0)
team = models.ForeignKey(Team, on_delete=models.CASCADE)
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name="invites")
code = models.CharField(max_length=32, unique=True)
8 changes: 8 additions & 0 deletions scavenger2022/core/static/core/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ a:visited {
.imgicon {
height: 3rem;
.}

.qrcode {
padding: 1rem;
}

.qrcode > img {
margin: auto;
}
1 change: 1 addition & 0 deletions scavenger2022/core/static/core/qrcode.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions scavenger2022/core/templates/core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
{% load i18n %}

{% block title %}
Index
Scavenger Hunt
{% endblock %}

{% block body %}
{% if not request.user.is_authenticated %}
Please <a href="{% url 'oauth_login' %}">login</a>.
{% else %}
{% if request.user.team is None %}
<ul>
<li>Join a team: either scan your team leader's QR code or click the link</li>
<li><a href="{% url 'team_new' %}">Make a team</a></li>
<li><a href="{% url 'team_new' %}">{% translate "Make a team" %}</a></li>
<li><form action="{% url 'team_solo' %}" method="post">
{% csrf_token %}
<input type="submit" value="{% translate 'Go solo '%}" />
<input class="fakea" type="submit" value="{% translate 'Go solo '%}" />
</form></li>
</ul>
{% else %}
TODO: go to first hint
{% if request.user.team is not None %}
Go to your <a href="{% url 'qr_first' %}">first hint</a>.
{% if not request.user.team.solo %}
Or <a href="{% url 'team_recruit' %}">invite team members</a>.
{% endif %}
{% endif %}
{% endif %}
{% endblock %}
28 changes: 28 additions & 0 deletions scavenger2022/core/templates/core/team_recruit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "core/base.html" %}
{% load static %}

{% block title %}
Invite Members
{% endblock %}

{% block header %}
Invite Members
{% endblock %}

{% block head_end %}
<script src="{% static 'core/qrcode.min.js' %}"></script>
{% endblock %}

{% block body %}
{% for invite in request.user.team.invites.all %}
Either you can send the <a href="{% url 'join' %}?code={{ invite.code }}">join link</a>, or let them scan the QR code below:
<div class="qrcode" id="qrcode"></div>
<script>
new QRCode(document.getElementById("qrcode"), {
text: "{% url 'join' %}?code={{ invite.code }}",
correctLevel: QRCode.CorrectLevel.H,
})
</script>
{% endfor %}
{% endblock %}

1 change: 1 addition & 0 deletions scavenger2022/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
path("team/join/", team.join, name="join"),
path("team/new", team.make, name="team_new"),
path("team/solo", team.solo, name="team_solo"),
path("team/recruit", team.recruit, name="team_recruit"),
]
14 changes: 12 additions & 2 deletions scavenger2022/core/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from django.views.decorators.http import require_http_methods
from django.utils.translation import gettext as _

from ..models import Team, Invite
from ..models import Team, Invite, generate_invite_code
from ..forms import TeamJoinForm, TeamMakeForm
from .qr import team_required


@login_required
Expand Down Expand Up @@ -66,8 +67,10 @@ def make(request):
form = TeamMakeForm(request.POST)
if form.is_valid():
form.save()
request.user.team = form.instance
team = request.user.team = form.instance
request.user.save()
invite = Invite(team=team, code=generate_invite_code())
invite.save()
messages.success(
request,
_("Made team %(team_name)s")
Expand All @@ -85,3 +88,10 @@ def solo(q):
team.save()
q.user.save()
return redirect(reverse("index"))


@login_required
@require_http_methods(["GET"])
@team_required
def recruit(q):
return render(q, "core/team_recruit.html")
18 changes: 9 additions & 9 deletions scavenger2022/poetry.lock

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

0 comments on commit 07e93c4

Please sign in to comment.