Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Dec 10, 2023
1 parent f2d522f commit befd944
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

def clear_teams(apps, schema_editor):
Team = apps.get_model("core", "team")
Team.objects.all().delete() # delete all teams IRREVERSIBLE

Team.objects.all().delete() # delete all teams IRREVERSIBLE


class Migration(migrations.Migration):
dependencies = [
("core", "0020_alter_logicpuzzlehint_qr_index_and_more"),
Expand Down Expand Up @@ -57,9 +58,11 @@ class Migration(migrations.Migration):
"unique_together": {("user", "team")},
},
),
migrations.RunPython(clear_teams, reverse_code=None), # if you want to "reverse" change this to migrations.RunPython.noop though it will not bring back the teams
migrations.RemoveField(model_name="team", name="members"), # added manually
migrations.AddField( # changed from alter to add
migrations.RunPython(
clear_teams, reverse_code=None
), # if you want to "reverse" change this to migrations.RunPython.noop though it will not bring back the teams
migrations.RemoveField(model_name="team", name="members"), # added manually
migrations.AddField( # changed from alter to add
model_name="team",
name="members",
field=models.ManyToManyField(
Expand Down
51 changes: 26 additions & 25 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ def in_team(self) -> bool:
"""Returns True if the user is in a team for the current or upcoming hunt."""
return self.current_team is not None




def generate_hint_key():
return secrets.token_urlsafe(48)


class QrCode(models.Model):
id = models.AutoField(primary_key=True)
# creator = models.ForeignKey(
# User,
# on_delete=models.SET_NULL,
# null=True,
# blank=False,
# related_name="qr_codes",
# help_text="User that created the QR code",
# )
# creator = models.ForeignKey(
# User,
# on_delete=models.SET_NULL,
# null=True,
# blank=False,
# related_name="qr_codes",
# help_text="User that created the QR code",
# )
created_at = models.DateTimeField(auto_now_add=True)
short = models.CharField(
max_length=64, help_text="Short string to remember the place."
Expand Down Expand Up @@ -146,14 +145,16 @@ class Hint(models.Model):
def __str__(self):
return self.hint


class TeamMembership(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
team = models.ForeignKey("Team", on_delete=models.CASCADE)

class Meta:
# Create a unique constraint to enforce one team per user per hunt
unique_together = ('user', 'team')

unique_together = ("user", "team")


class Team(models.Model):
# owner = models.ForeignKey(User, on_delete=models.PROTECT, related_name="teams_ownership") potentially add this later
id = models.AutoField(primary_key=True)
Expand All @@ -163,17 +164,17 @@ class Team(models.Model):
) # todo use this field to have a club-like page so you can join an open team (future feature)
current_qr_i = models.IntegerField(default=0)
solo = models.BooleanField(default=False)
members = models.ManyToManyField(User,
related_name="teams", related_query_name="teams", through=TeamMembership
members = models.ManyToManyField(
User, related_name="teams", related_query_name="teams", through=TeamMembership
)
hunt = models.ForeignKey("Hunt", on_delete=models.CASCADE, related_name="teams")

def leave(self, member: User):
if self.members.filter(id=member.id).first() is None:
raise IndexError("User is not in team")
# remove the member
self.members.through.remove(member)

def update_current_qr_i(self, i: int):
self.current_qr_i = max(self.current_qr_i, i)
self.save()
Expand Down Expand Up @@ -365,14 +366,14 @@ class Meta:

class LogicPuzzleHint(models.Model):
id = models.AutoField(primary_key=True)
# creator = models.ForeignKey(
# User,
# on_delete=models.SET_NULL,
# null=True,
# blank=False,
# related_name="logic_hints",
# help_text="User that created the QR code",
# )
# creator = models.ForeignKey(
# User,
# on_delete=models.SET_NULL,
# null=True,
# blank=False,
# related_name="logic_hints",
# help_text="User that created the QR code",
# )
hint = models.TextField(
max_length=1024,
help_text="Hint for the logic puzzle",
Expand Down
2 changes: 1 addition & 1 deletion core/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def make(request):
else:
form = TeamMakeForm()
return render(request, "core/team_new.html", dict(form=form))


@login_required
@require_http_methods(["GET"])
Expand Down

0 comments on commit befd944

Please sign in to comment.