Skip to content

Commit

Permalink
Added the ability to edit information pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Mar 19, 2020
1 parent 60f3d58 commit f0e8153
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 149 deletions.
1 change: 0 additions & 1 deletion docs/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Info Views
==========

.. autofunction:: huntserver.info_views.index(request)
.. autofunction:: huntserver.info_views.current_hunt_info(request)
.. autofunction:: huntserver.info_views.previous_hunts(request)
.. autofunction:: huntserver.info_views.registration(request)
.. autofunction:: huntserver.info_views.user_profile(request)
Expand Down
50 changes: 50 additions & 0 deletions huntserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from django.contrib.auth.models import User, Group
from django.utils.safestring import mark_safe
from django.template.defaultfilters import truncatechars
from django.contrib.sites.models import Site
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.forms import FlatpageForm

# Register your models here.
from . import models
Expand Down Expand Up @@ -306,8 +310,53 @@ class UserProxyAdmin(admin.ModelAdmin):
search_fields = ['email', 'username', 'first_name', 'last_name']


class FlatPageProxyObject(FlatPage):
class Meta:
proxy = True
app_label = 'huntserver'
verbose_name = "info page"
verbose_name_plural = "info pages"


class FlatpageProxyForm(FlatpageForm):
class Meta:
model = FlatPageProxyObject
fields = '__all__'


# Define a new FlatPageAdmin
class FlatPageProxyAdmin(FlatPageAdmin):
list_filter = []
fieldsets = (
(None, {'fields': ('url', 'title', 'content')}),
(None, {
'classes': ('hidden',),
'fields': ('sites',)
}),
('Advanced options', {
'classes': ('collapse',),
'fields': (
'registration_required',
'template_name',
),
}),
)

def get_form(self, request, obj=None, **kwargs):
kwargs['form'] = FlatpageProxyForm
form = super(FlatPageAdmin, self).get_form(request, obj, **kwargs)
form.base_fields['sites'].initial = Site.objects.get(pk=1)
form.base_fields['content'].widget = HtmlEditor(attrs={'style': 'width:90%; height:400px;'})
form.base_fields['url'].help_text = ("Example: '/contact-us/' translates to " +
"/info/contact-us/. Make sure to have leading and " +
"trailing slashes.")
return form


admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.unregister(Site)
admin.site.unregister(FlatPage)

admin.site.register(models.Hint, HintAdmin)
admin.site.register(models.Hunt, HuntAdmin)
Expand All @@ -322,3 +371,4 @@ class UserProxyAdmin(admin.ModelAdmin):
admin.site.register(models.Unlockable)
admin.site.register(models.Unlock, UnlockAdmin)
admin.site.register(UserProxyObject, UserProxyAdmin)
admin.site.register(FlatPageProxyObject, FlatPageProxyAdmin)
5 changes: 2 additions & 3 deletions huntserver/hunt_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from .models import Puzzle, Hunt, Submission, Message, Unlockable, Prepuzzle, Hint
from .forms import AnswerForm, HintRequestForm
from .info_views import current_hunt_info

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -144,7 +143,7 @@ def prepuzzle(request, prepuzzle_num):

else:
if(not (puzzle.released or request.user.is_staff)):
return current_hunt_info(request)
return redirect('current_hunt_info')
form = AnswerForm()
context = {'form': form, 'puzzle': puzzle}
return HttpResponse(Template(puzzle.template).render(RequestContext(request, context)))
Expand All @@ -159,7 +158,7 @@ def hunt_prepuzzle(request, hunt_num):
return prepuzzle(request, curr_hunt.prepuzzle.pk)
else:
# Maybe we can do something better, but for now, redirect to the main page
return current_hunt_info(request)
return redirect('current_hunt_info')


def current_prepuzzle(request):
Expand Down
6 changes: 0 additions & 6 deletions huntserver/info_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ def index(request):
return render(request, "index.html", {'curr_hunt': curr_hunt, 'team': team})


def current_hunt_info(request):
""" Information about the current hunt, mostly static with the exception of hunt info """
curr_hunt = Hunt.objects.get(is_current_hunt=True)
return render(request, "hunt_info.html", {'curr_hunt': curr_hunt})


def previous_hunts(request):
""" A view to render the list of previous hunts, will show any hunt that is 'public' """
old_hunts = []
Expand Down
43 changes: 43 additions & 0 deletions huntserver/migrations/0054_auto_20200318_2145.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 2.2 on 2020-03-19 01:45

from django.db import migrations
from django.template.loader import get_template
from django.contrib.sites.models import Site


def setup_pages(apps, schema_editor):
FlatPage = apps.get_model('flatpages', 'FlatPage')

source = get_template("contact_us.html").template.source.split("</readme> -->")[1]
fp = FlatPage.objects.create(url='/contact-us/', title='Contact Us', content=source)
fp.sites.add(1)

source = get_template("resources.html").template.source.split("</readme> -->")[1]
fp = FlatPage.objects.create(url='/extra/resources/', title='Resources', content=source)
fp.sites.add(1)

source = get_template("hunt_info.html").template.source.split("</readme> -->")[1]
fp = FlatPage.objects.create(url='/hunt-info/', title='Current Hunt Info', content=source)
fp.sites.add(1)
return


def remove_pages(apps, schema_editor):
FlatPage = apps.get_model('flatpages', 'FlatPage')
FlatPage.objects.filter(url='/contact-us/').delete()
FlatPage.objects.filter(url='/extra/resources/').delete()
FlatPage.objects.filter(url='/hunt-info/').delete()
return


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0053_auto_20200310_1503'),
('flatpages', '0001_initial'),
('sites', '0002_alter_domain_unique'),
]

operations = [
migrations.RunPython(setup_pages, remove_pages)
]
27 changes: 27 additions & 0 deletions huntserver/migrations/0055_flatpageproxyobject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 2.2 on 2020-03-19 23:30

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('flatpages', '0001_initial'),
('huntserver', '0054_auto_20200318_2145'),
]

operations = [
migrations.CreateModel(
name='FlatPageProxyObject',
fields=[
],
options={
'verbose_name': 'info page',
'verbose_name_plural': 'info pages',
'proxy': True,
'indexes': [],
'constraints': [],
},
bases=('flatpages.flatpage',),
),
]
29 changes: 10 additions & 19 deletions huntserver/templates/contact_us.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
{% extends "info_base.html" %}
{% load hunt_tags %}
<!-- <readme> This file is the source for the contact-us info page when creating the server.
Don't edit this file after server creation, use the admin editor instead </readme> -->

{% block includes %}
<script src="{{ STATIC_URL }}jquery.min.js"></script>
{% endblock includes %}

{% block content %}

<div class="container">
<h1> Contact Us </h1>
<div id='qa'>
<p>
Email the <a href="mailto:{% contact_email %}?subject=Puzzle%20Hunt%20Question">HALP?! LINE</a> ({% contact_email %}) with "Puzzle Hunt" somewhere in the subject line.
</p>
<p>Visit us on our <a href="https://www.facebook.com/groups/puzzlehuntCMU">Facebook Page</a>.
You can also find us on <a href="https://thebridge.cmu.edu/organization/puzzlehuntcmu">The Bridge</a>.</p>
</div>
</div>
{% endblock content %}
<h1> Contact Us </h1>
<div id='qa'>
<p>
Email the <a href="mailto:{% contact_email %}?subject=Puzzle%20Hunt%20Question">HALP?! LINE</a> ({% contact_email %}) with "Puzzle Hunt" somewhere in the subject line.
</p>
<p>Visit us on our <a href="https://www.facebook.com/groups/puzzlehuntCMU">Facebook Page</a>.
You can also find us on <a href="https://thebridge.cmu.edu/organization/puzzlehuntcmu">The Bridge</a>.</p>
</div>
13 changes: 13 additions & 0 deletions huntserver/templates/flatpages/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "info_base.html" %}
{% load hunt_tags %}

{% block includes %}
<script src="{{ STATIC_URL }}jquery.min.js"></script>
{% endblock includes %}

{% block content %}

<div class="container">
{{ flatpage.content|render_with_context }}
</div>
{% endblock content %}
119 changes: 55 additions & 64 deletions huntserver/templates/hunt_info.html
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
{% extends "info_base.html" %}
{% load humanize %}
{% load hunt_tags %}

{% block includes %}
<script src="{{ STATIC_URL }}jquery.min.js"></script>
{% endblock includes %}

{% block content %}

<div class="container">
<h1 class="title">{{curr_hunt.hunt_name}}</h1>
<h2 class="title">{{ curr_hunt.display_start_date|date:" m/d/y " }} {{ curr_hunt.display_start_date|time:"h:iA" }} - {{ curr_hunt.display_end_date|time:"h:iA" }}<br>
Starts in {{ curr_hunt.location }}</h3>
<div id='qa'>
<h2>What are the puzzles like?</h2>
<p>For examples of the kinds of puzzles we'll give you, check out our <a href="{% url 'huntserver:previous_hunts' %}">Past Hunts</a></p>
<p>Or these similar hunts:</p>
<ul>
<li><a href="http://www.collegepuzzlechallenge.com/">Microsoft College Puzzle Challenge</a></li>
<li><a href="http://www.mit.edu/~puzzle/">The MIT Mystery Hunt</a></li>
</ul>
<h2>Sounds fun! How does my team win?</h2>
<p>
Each puzzle yields a solution (like a word or a phrase). You'll be combining answers to
puzzles with a mechanic that will be explained more on the day of the hunt.
Eventually players reach the endgame, a bonus round for those who
complete the puzzles the fastest.
</p>
<h2>How do I register?</h2>
<p>Register your team of {{curr_hunt.team_size|apnumber}} (or fewer if you want) <a href="{% url 'huntserver:registration' %}">here!</a>
</p>

<h2>What should I bring?</h2>
<p>
<ul>
<li>A team of no more than {{curr_hunt.team_size|apnumber}} people. Humans only, please. Robots are discouraged; they mess up the sensors.</li>
<li>Laptops. All of our puzzles will be online. </li>
<li>Scissors. These will be helpful. </li>

</ul>
</p>
<!-- <readme> This file is the source for the resources info page when creating the server.
Don't edit this file after server creation, use the admin editor instead </readme> -->

<h2>How long will it last?</h2>
<p>The hunt is expected to run 8 hours. If there isn't a winner by 8 hours in (rare), we'll inform all teams to keep playing and continue until there's a winner.</p>

<h2>Will there be food?</h2>
<p>
Yes, there will be food, usually pizza. If you have dietary restrictions, please list them in the appropriate box when registering.
</p>

<h2>Is there anything else I should know?</h2>
<p>
<ul>
<li>There may be some running around campus required.</li>
<li>You CAN register a partial team and we'll do our best to try to match all of the partial teams on the day of.</li>
<li>Nothing on this and the registration page is a puzzle crucial for completing the hunt. No, really, this is not a puzzle.</li>
</ul>
</p>

<h2>Wait, I have more questions!</h2>
<p>Email the <a href="mailto:{% contact_email %}?subject=Puzzle%20Hunt%20Question">HALP?! LINE</a> ({% contact_email %}) with "Puzzle Hunt" somewhere in the subject line.</p>
</div>
</div>
{% endblock content %}
{% load humanize %}
<h1 class="title">{{curr_hunt.hunt_name}}</h1>
<h2 class="title">{{ curr_hunt.display_start_date|date:" m/d/y " }} {{ curr_hunt.display_start_date|time:"h:iA" }} - {{ curr_hunt.display_end_date|time:"h:iA" }}<br>
Starts in {{ curr_hunt.location }}</h3>
<div id='qa'>
<h2>What are the puzzles like?</h2>
<p>For examples of the kinds of puzzles we'll give you, check out our <a href="{% url 'huntserver:previous_hunts' %}">Past Hunts</a></p>
<p>Or these similar hunts:</p>
<ul>
<li><a href="http://www.collegepuzzlechallenge.com/">Microsoft College Puzzle Challenge</a></li>
<li><a href="http://www.mit.edu/~puzzle/">The MIT Mystery Hunt</a></li>
</ul>
<h2>Sounds fun! How does my team win?</h2>
<p>
Each puzzle yields a solution (like a word or a phrase). You'll be combining answers to
puzzles with a mechanic that will be explained more on the day of the hunt.
Eventually players reach the endgame, a bonus round for those who
complete the puzzles the fastest.
</p>
<h2>How do I register?</h2>
<p>Register your team of {{curr_hunt.team_size|apnumber}} (or fewer if you want) <a href="{% url 'huntserver:registration' %}">here!</a>
</p>

<h2>What should I bring?</h2>
<p>
<ul>
<li>A team of no more than {{curr_hunt.team_size|apnumber}} people. Humans only, please. Robots are discouraged; they mess up the sensors.</li>
<li>Laptops. All of our puzzles will be online. </li>
<li>Scissors. These will be helpful. </li>

</ul>
</p>

<h2>How long will it last?</h2>
<p>The hunt is expected to run 8 hours. If there isn't a winner by 8 hours in (rare), we'll inform all teams to keep playing and continue until there's a winner.</p>

<h2>Will there be food?</h2>
<p>
Yes, there will be food, usually pizza. If you have dietary restrictions, please list them in the appropriate box when registering.
</p>

<h2>Is there anything else I should know?</h2>
<p>
<ul>
<li>There may be some running around campus required.</li>
<li>You CAN register a partial team and we'll do our best to try to match all of the partial teams on the day of.</li>
<li>Nothing on this and the registration page is a puzzle crucial for completing the hunt. No, really, this is not a puzzle.</li>
</ul>
</p>

<h2>Wait, I have more questions!</h2>
<p>Email the <a href="mailto:{% contact_email %}?subject=Puzzle%20Hunt%20Question">HALP?! LINE</a> ({% contact_email %}) with "Puzzle Hunt" somewhere in the subject line.</p>
</div>
2 changes: 1 addition & 1 deletion huntserver/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2>Who are we?</h2>
</p>
<h2>What is a Puzzlehunt?</h2>
<p>
Very simply put, it's a full-day event where people get together to solve carefully designed puzzles which somehow link together on a larger scale.
Very simply put, it's an event where people get together to solve carefully designed puzzles which somehow link together on a larger scale.
<br>
A puzzlehunt is typically characterized by its structure. In addition to several normal puzzles, each round has a meta-puzzle, which requires teams to have solved most of the normal puzzles to even unlock, and often requires solvers to incorporate answers from that round's normal puzzles to make sense of.
<br>
Expand Down
8 changes: 6 additions & 2 deletions huntserver/templates/info_base.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{% extends 'base.html' %}
{% load bootstrap_tags %}
{% load static %}
{% load flatpages %}

{% block base_includes %}
<link rel="stylesheet" type="text/css" href="{% static "huntserver/info_base.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "huntserver/navbar.css" %}">
{% endblock base_includes %}

{% block left-header %}
{% get_flatpages '/extra/' as flatpages %}
<li class='{% active_page request "index" %} visible-sm visible-xs'><a href="{% url 'huntserver:index' %}"> Homepage </a></li>
<li class='{% active_page request "current_hunt_info" %}'><a href="{% url 'huntserver:current_hunt_info' %}"> Hunt Info</a></li>
<li class='{% active_page request "current_hunt" %}'><a href="{% url 'huntserver:current_hunt' %}"> Current Hunt </a></li>
<li class='{% active_page request "current_hunt_info" %}'><a href="{% url 'huntserver:current_hunt_info' %}"> Hunt Info</a></li>
<li class='{% active_page request "previous_hunts" %}'><a href="{% url 'huntserver:previous_hunts' %}"> Previous Hunts </a></li>
<li class='{% active_page request "resources" %}'><a href="{% url 'huntserver:resources' %}"> Puzzle Resources </a></li>
{% for page in flatpages|dictsort:"url" %}
<li class='{% active_page request page.url %}'><a href="/info{{ page.url }}"> {{ page.title }} </a></li>
{% endfor %}
<li class='{% active_page request "contact_us" %}'><a href="{% url 'huntserver:contact_us' %}"> Contact Us </a></li>
{% endblock %}

0 comments on commit f0e8153

Please sign in to comment.