Skip to content

Commit

Permalink
fixes invites
Browse files Browse the repository at this point in the history
reformat.
  • Loading branch information
JasonLovesDoggo committed Dec 3, 2023
1 parent 3e929af commit d3606e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
1 change: 1 addition & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ class UserAdmin(UserAdmin_):
admin.site.register(QrCode, QrCodeAdmin)
admin.site.register(LogicPuzzleHint, LogicPuzzleAdmin)
admin.site.register(Hunt)
admin.site.register(Invite)
3 changes: 3 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class Invite(models.Model):
invites = models.IntegerField(default=0)
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name="invites")
code = models.CharField(max_length=32, unique=True)

def __str__(self):
return str(self.team.name)


class Hunt(models.Model):
Expand Down
22 changes: 0 additions & 22 deletions core/tasks.py

This file was deleted.

16 changes: 11 additions & 5 deletions core/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def join(request):
@login_required
@require_http_methods(["GET", "POST"])
def make(request):
if settings.START < datetime.datetime.now() and not request.user.team is None:
if settings.START < datetime.datetime.now() and request.user.team is not None:
messages.error(
request,
_("Since the hunt has already begun, making new teams is disallowed."),
Expand All @@ -75,6 +75,9 @@ def make(request):
raw.save()
request.user.team = raw
request.user.save()
Invite.objects.get_or_create(
team=raw, code=generate_invite_code(), invites=0
)
messages.success(
request,
_("Made team %(team_name)s")
Expand All @@ -88,9 +91,9 @@ def make(request):

@login_required
def solo(q: HttpRequest):
team = Team.objects.create(
solo=True, hunt=Hunt.current_hunt(), name=f"{q.user.username}'s Solo Team"
)
team = Team.objects.create(
solo=True, hunt=Hunt.current_hunt(), name=f"{q.user.username}'s Solo Team"
)
q.user.team = team
q.user.save()
return redirect(reverse("index"))
Expand All @@ -101,5 +104,8 @@ def solo(q: HttpRequest):
@team_required
def invite(q):
invites = Invite.objects.filter(team=q.user.team).values_list("code", flat=True)
print(invites) # todo fix
if invites.count() == 0:
print("No invites found, creating one")
Invite.objects.create(team=q.user.team, code=generate_invite_code(), invites=0)
return invite(q)
return render(q, "core/team_invite.html", context=dict(invites=invites))

0 comments on commit d3606e8

Please sign in to comment.