Skip to content

Commit

Permalink
replace is_meta and doesnt_count puzzle fields with puzzle_type
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Feb 10, 2021
1 parent 353062f commit 579a3ca
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 16 deletions.
10 changes: 5 additions & 5 deletions huntserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def clean_answer(self):

class Meta:
model = models.Puzzle
fields = ('hunt', 'puzzle_name', 'puzzle_number', 'puzzle_id', 'answer', 'is_meta',
'doesnt_count', 'puzzle_page_type', 'puzzle_file', 'resource_file',
fields = ('hunt', 'puzzle_name', 'puzzle_number', 'puzzle_id', 'answer', 'puzzle_type',
'puzzle_page_type', 'puzzle_file', 'resource_file',
'solution_file', 'extra_data', 'num_required_to_unlock', 'unlock_type',
'points_cost', 'points_value', 'solution_is_webpage', 'solution_resource_file')

Expand All @@ -202,15 +202,15 @@ class Media:

list_filter = ('hunt',)
search_fields = ['puzzle_id', 'puzzle_name']
list_display = ['combined_id', 'puzzle_name', 'hunt', 'is_meta']
list_display = ['combined_id', 'puzzle_name', 'hunt', 'puzzle_type']
list_display_links = ['combined_id', 'puzzle_name']
ordering = ['-hunt', 'puzzle_number']
inlines = (ResponseInline,)
radio_fields = {"unlock_type": admin.VERTICAL}
fieldsets = (
(None, {
'fields': ('hunt', 'puzzle_name', 'answer', 'puzzle_number', 'puzzle_id', 'is_meta',
'doesnt_count', 'puzzle_page_type', 'puzzle_file', 'resource_file',
'fields': ('hunt', 'puzzle_name', 'answer', 'puzzle_number', 'puzzle_id', 'puzzle_type',
'puzzle_page_type', 'puzzle_file', 'resource_file',
'solution_is_webpage', 'solution_file', 'solution_resource_file',
'extra_data', 'unlock_type')
}),
Expand Down
2 changes: 1 addition & 1 deletion huntserver/hunt_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def leaderboard(request, criteria=""):
teams = curr_hunt.real_teams.exclude(location="off_campus")
else:
teams = curr_hunt.real_teams.all()
sq1 = Solve.objects.filter(team__pk=OuterRef('pk'), puzzle__is_meta=True).order_by()
sq1 = Solve.objects.filter(team__pk=OuterRef('pk'), puzzle__puzzle_type=Puzzle.META_PUZZLE).order_by()
sq1 = sq1.values('team').annotate(c=Count('*')).values('c')
sq1 = Subquery(sq1, output_field=PositiveIntegerField())
all_teams = teams.annotate(metas=sq1, solves=Count('solved'))
Expand Down
23 changes: 23 additions & 0 deletions huntserver/migrations/0073_auto_20210207_2300.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.13 on 2021-02-08 04:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0072_auto_20201103_1539'),
]

operations = [
migrations.AddField(
model_name='puzzle',
name='puzzle_type',
field=models.CharField(choices=[('STD', 'A standard puzzle'), ('MET', 'A meta puzzle'), ('NON', 'An unscored puzzle')], default='STD', help_text='The type of puzzle.', max_length=3),
),
migrations.AlterField(
model_name='puzzle',
name='puzzle_page_type',
field=models.CharField(choices=[('PDF', 'Puzzle page displays a PDF'), ('LNK', 'Puzzle page links a webpage'), ('WEB', 'Puzzle page displays a webpage'), ('EMB', 'Puzzle is html embedded in the webpage')], default='WEB', help_text='The type of webpage for this puzzle.', max_length=3),
),
]
30 changes: 30 additions & 0 deletions huntserver/migrations/0074_auto_20210207_2304.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.13 on 2021-02-08 04:04

from django.db import migrations


def set_puzzle_type(apps, schema_editor):
Puzzle = apps.get_model('huntserver', 'Puzzle')
for puzzle in Puzzle.objects.all().iterator():
if(puzzle.is_meta):
puzzle.puzzle_type = "MET"
elif(puzzle.doesnt_count):
puzzle.puzzle_type = "NON"
else:
puzzle.puzzle_type = "STD"
puzzle.save()


def reverse_func(apps, schema_editor):
pass # code for reverting migration, if any


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0073_auto_20210207_2300'),
]

operations = [
migrations.RunPython(set_puzzle_type, reverse_func)
]
26 changes: 26 additions & 0 deletions huntserver/migrations/0075_auto_20210208_0939.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.13 on 2021-02-08 14:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0074_auto_20210207_2304'),
]

operations = [
migrations.RemoveField(
model_name='puzzle',
name='doesnt_count',
),
migrations.RemoveField(
model_name='puzzle',
name='is_meta',
),
migrations.AlterField(
model_name='puzzle',
name='puzzle_type',
field=models.CharField(choices=[('STD', 'Standard'), ('MET', 'Meta'), ('FIN', 'Final'), ('NON', 'Non-puzzle')], default='STD', help_text='The type of puzzle.', max_length=3),
),
]
26 changes: 19 additions & 7 deletions huntserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ class Meta:
(EMBED_PUZZLE, 'Puzzle is html embedded in the webpage'),
]

STANDARD_PUZZLE = 'STD'
META_PUZZLE = 'MET'
FINAL_PUZZLE = 'FIN'
NON_PUZZLE = 'NON'

puzzle_type_choices = [
(STANDARD_PUZZLE, 'Standard'),
(META_PUZZLE, 'Meta'),
(FINAL_PUZZLE, 'Final'),
(NON_PUZZLE, 'Non-puzzle'),
]

hunt = models.ForeignKey(
Hunt,
on_delete=models.CASCADE,
Expand All @@ -252,20 +264,20 @@ class Meta:
answer = models.CharField(
max_length=100,
help_text="The answer to the puzzle, not case sensitive")
is_meta = models.BooleanField(
default=False,
verbose_name="Is a metapuzzle",
help_text="Is this puzzle a meta-puzzle?")
puzzle_type = models.CharField(
max_length=3,
choices=puzzle_type_choices,
default=STANDARD_PUZZLE,
blank=False,
help_text="The type of puzzle."
)
puzzle_page_type = models.CharField(
max_length=3,
choices=puzzle_page_type_choices,
default=WEB_PUZZLE,
blank=False,
help_text="The type of webpage for this puzzle."
)
doesnt_count = models.BooleanField(
default=False,
help_text="Should this puzzle not count towards scoring?")
puzzle_file = models.FileField(
upload_to=get_puzzle_file_path,
storage=PuzzleOverwriteStorage(),
Expand Down
2 changes: 1 addition & 1 deletion huntserver/staff_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def lookup(request):
team = Team.objects.get(pk=request.GET.get("team_pk"))
team.latest_submissions = team.submission_set.values_list('puzzle')
team.latest_submissions = team.latest_submissions.annotate(Max('submission_time'))
sq1 = Solve.objects.filter(team__pk=OuterRef('pk'), puzzle__is_meta=True).order_by()
sq1 = Solve.objects.filter(team__pk=OuterRef('pk'), puzzle__puzzle_type=Puzzle.META_PUZZLE).order_by()
sq1 = sq1.values('team').annotate(c=Count('*')).values('c')
sq1 = Subquery(sq1, output_field=PositiveIntegerField())
all_teams = team.hunt.team_set.annotate(metas=sq1, solves=Count('solved'))
Expand Down
4 changes: 2 additions & 2 deletions huntserver/templates/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ <h1>Puzzle Progress</h1>
<th>#</br>P</th>
<th>Last&nbsp;Time</th>
{% for puzzle in puzzle_list %}
<th {% if puzzle.is_meta %} class="metapuzzle" {% endif %}
{% if puzzle.doesnt_count %} class="nocount" {% endif %}
<th {% if puzzle.puzzle_type == puzzle.META_PUZZLE %} class="metapuzzle" {% endif %}
{% if puzzle.puzzle_type == puzzle.NON_PUZZLE %} class="nocount" {% endif %}
data-id='{{ puzzle.puzzle_id }}'>
{{ puzzle.puzzle_name }}
</th>
Expand Down

0 comments on commit 579a3ca

Please sign in to comment.