Skip to content

Commit

Permalink
Merge pull request #90 from clopedion/main
Browse files Browse the repository at this point in the history
Support showing links to solutions
  • Loading branch information
TheOriginalSoni authored Nov 12, 2024
2 parents 3eada08 + ecba19c commit b133a60
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 19 deletions.
4 changes: 4 additions & 0 deletions myus/myus/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Meta:
"member_limit",
"guess_limit",
"leaderboard_style",
"solution_style",
]


Expand All @@ -103,6 +104,7 @@ class Meta:
"member_limit",
"guess_limit",
"leaderboard_style",
"solution_style",
]


Expand Down Expand Up @@ -142,6 +144,8 @@ class Meta:
"slug",
"content",
"answer",
"answer_response",
"solution_url",
"points",
"order",
"progress_points",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 5.0.2 on 2024-11-12 04:30

from django.db import migrations, models


class Migration(migrations.Migration):

replaces = [
("myus", "0012_hunt_solution_style_puzzle_solution_url"),
("myus", "0013_alter_puzzle_solution_url"),
("myus", "0014_alter_puzzle_solution_url"),
]

dependencies = [
("myus", "0011_alter_puzzle_answer_response"),
]

operations = [
migrations.AddField(
model_name="hunt",
name="solution_style",
field=models.CharField(
choices=[
("VIS", "Solutions are always visible"),
("HID", "Solutions are always hidden"),
("SOL", "Solution displayed after puzzle is solved"),
],
default="HID",
max_length=3,
),
),
migrations.AddField(
model_name="puzzle",
name="solution_url",
field=models.CharField(
blank=True,
default="",
help_text="URL of solution.",
max_length=500,
verbose_name="Solution URL",
),
),
]
17 changes: 17 additions & 0 deletions myus/myus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ class LeaderboardStyle(models.TextChoices):
leaderboard_style = models.CharField(
max_length=3, choices=LeaderboardStyle, default=LeaderboardStyle.DEFAULT
)

class SolutionStyle(models.TextChoices):
VISIBLE = "VIS", "Solutions are always visible"
HIDDEN = "HID", "Solutions are always hidden"
AFTER_SOLVE = "SOL", "Solution displayed after puzzle is solved"

solution_style = models.CharField(
max_length=3, choices=SolutionStyle, default=SolutionStyle.HIDDEN
)

slug = models.SlugField(help_text="A short, unique identifier for the hunt.")

def public_puzzles(self):
Expand All @@ -80,6 +90,13 @@ class Puzzle(models.Model):
blank=True,
help_text="The puzzle body. For most puzzles, we suggest just providing an external URL; however, you can put short text-only puzzles here, or include a small amount of flavortext or explanatory text with a URL.",
)
solution_url = models.CharField(
max_length=500,
blank=True,
default="",
verbose_name="Solution URL",
help_text="URL of solution.",
)
answer = models.CharField(max_length=500)
answer_response = models.CharField(
max_length=500,
Expand Down
6 changes: 5 additions & 1 deletion myus/myus/templates/view_puzzle.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
» {{ puzzle.name }}
{% endblock %}
{% block main %}
<h1>Puzzle: {{ puzzle.name }}</h1>
{% if show_solution %}
<h1>Puzzle: {{ puzzle.name }} (<a href="{{puzzle.solution_url}}">Solution</a>) </h1>
{% else %}
<h1>Puzzle: {{ puzzle.name }} </h1>
{% endif %}

<div class="guesses">
{% if request.user.is_anonymous %}
Expand Down
26 changes: 8 additions & 18 deletions myus/myus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ def view_puzzle(
else:
guess_form = GuessForm()

show_solution = False
if puzzle.solution_url != "":
if hunt.solution_style == Hunt.SolutionStyle.VISIBLE or (
hunt.solution_style == Hunt.SolutionStyle.AFTER_SOLVE and solved
):
show_solution = True

return render(
request,
"view_puzzle.html",
Expand All @@ -335,6 +342,7 @@ def view_puzzle(
"team": team,
"puzzle": puzzle,
"solved": solved,
"show_solution": show_solution,
"guesses_limited": guesses_limited,
"guesses_remaining": guesses_remaining,
"guesses_at_limit": guesses_at_limit,
Expand Down Expand Up @@ -466,24 +474,6 @@ class Meta:
fields = ["guess", "response"]


class PuzzleForm(forms.ModelForm):
content = forms.CharField(widget=MarkdownTextarea, required=False)

class Meta:
model = Puzzle
fields = [
"name",
"slug",
"content",
"answer",
"answer_response",
"points",
"order",
"progress_points",
"progress_threshold",
]


@redirect_from_hunt_id_to_hunt_id_and_slug
@login_required
def new_puzzle(request, hunt_id: int, slug: Optional[str] = None):
Expand Down

0 comments on commit b133a60

Please sign in to comment.