Skip to content

Commit

Permalink
Added basic foobar razzia copy called fnugfald razzia
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenlaust committed Nov 2, 2023
1 parent 58b2d74 commit 3399a25
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
5 changes: 3 additions & 2 deletions stregreport/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

class BreadRazzia(models.Model):
class Meta:
permissions = (("host_razzia", "Can host a foobar or bread razzia"),)
permissions = (("host_razzia", "Can host a foobar, fnugfald or bread razzia"),)

BREAD = 'BR'
FOOBAR = 'FB'
RAZZIA_CHOICES = [(BREAD, "Brødrazzia"), (FOOBAR, "Foobar razzia")]
FNUGFALD = 'FF'
RAZZIA_CHOICES = [(BREAD, "Brødrazzia"), (FOOBAR, "Foobar razzia"), (FNUGFALD, "Fnugfald razzia")]
members = models.ManyToManyField(Member, through='RazziaEntry')
start_date = models.DateTimeField(auto_now_add=True)
razzia_type = models.CharField(max_length=2, choices=RAZZIA_CHOICES, default=BREAD)
Expand Down
4 changes: 4 additions & 0 deletions stregreport/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
urlpatterns = [
re_path(r'^admin/stregsystem/razzia/bread/(?P<razzia_id>\d+)/$', views.razzia, {'razzia_type' : BreadRazzia.BREAD, 'title': 'Brødrazzia'}, name="bread_view"),
re_path(r'^admin/stregsystem/razzia/foobar/(?P<razzia_id>\d+)/$', views.razzia, {'razzia_type' : BreadRazzia.FOOBAR, 'title': 'Foobar razzia'}, name="foobar_view"),
re_path(r'^admin/stregsystem/razzia/fnugfald/(?P<razzia_id>\d+)/$', views.razzia, {'razzia_type' : BreadRazzia.FNUGFALD, 'title': 'Fnugfald razzia'}, name="fnugfald_view"),
re_path(r'^admin/stregsystem/razzia/bread/(?P<razzia_id>\d+)/members$', views.razzia_members, {'razzia_type' : BreadRazzia.BREAD, 'title': 'Brødrazzia'}),
re_path(r'^admin/stregsystem/razzia/foobar/(?P<razzia_id>\d+)/members$', views.razzia_members, {'razzia_type' : BreadRazzia.FOOBAR, 'title': 'Foobar razzia'}),
re_path(r'^admin/stregsystem/razzia/fnugfald/(?P<razzia_id>\d+)/members$', views.razzia_members, {'razzia_type' : BreadRazzia.FNUGFALD, 'title': 'Fnugfald razzia'}),
re_path(r'^admin/stregsystem/razzia/bread/$', views.razzia_menu, {'razzia_type' : BreadRazzia.BREAD, 'new_text': "New bread razzia", 'title': 'Brødrazzia'}),
re_path(r'^admin/stregsystem/razzia/foobar/$', views.razzia_menu, {'razzia_type' : BreadRazzia.FOOBAR, 'new_text': "New foobar razzia", 'title': 'Foobar razzia'}),
re_path(r'^admin/stregsystem/razzia/fnugfald/$', views.razzia_menu, {'razzia_type' : BreadRazzia.FNUGFALD, 'new_text': "New fnugfald razzia", 'title': 'Fnugfald razzia'}),
re_path(r'^admin/stregsystem/razzia/bread/new$', views.new_razzia, {'razzia_type' : BreadRazzia.BREAD}, name="razzia_new_BR"),
re_path(r'^admin/stregsystem/razzia/foobar/new$', views.new_razzia, {'razzia_type' : BreadRazzia.FOOBAR}, name="razzia_new_FB"),
re_path(r'^admin/stregsystem/razzia/fnugfald/new$', views.new_razzia, {'razzia_type' : BreadRazzia.FNUGFALD}, name="razzia_new_FF"),
re_path(r'^admin/stregsystem/razzia/wizard_guide/$', views.razzia_wizard),
re_path(r'^admin/stregsystem/razzia/wizard/$', views.razzia_view, name="razzia_view"),
re_path(r'^admin/stregsystem/report/sales/$', views.sales, name="salesreporting"),
Expand Down
7 changes: 4 additions & 3 deletions stregreport/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ def razzia_view_single(request, razzia_id, queryname, razzia_type=BreadRazzia.BR
last_entry = entries[0]
within_wait = last_entry.time > timezone.now() - wait_time
# if member has already checked in within the last hour, don't allow another check in
if already_checked_in and within_wait and razzia_type == BreadRazzia.FOOBAR:
if already_checked_in and within_wait and (razzia_type == BreadRazzia.FOOBAR or razzia_type == BreadRazzia.FNUGFALD):
drunkard = True
# time until next check in is legal
remaining_time_secs = int(((last_entry.time + wait_time) - timezone.now()).total_seconds() % 60)
remaining_time_mins = int(((last_entry.time + wait_time) - timezone.now()).total_seconds() // 60)
if not already_checked_in or (razzia_type == BreadRazzia.FOOBAR and not within_wait):
if not already_checked_in or ((razzia_type == BreadRazzia.FOOBAR or razzia_type == BreadRazzia.FNUGFALD) and not within_wait):
RazziaEntry(member=member, razzia=razzia).save()

templates = {
BreadRazzia.BREAD: 'admin/stregsystem/razzia/bread.html',
BreadRazzia.FOOBAR: 'admin/stregsystem/razzia/foobar.html',
BreadRazzia.FNUGFALD: 'admin/stregsystem/razzia/fnugfald.html',
}
return render(request, templates[razzia_type], locals())

Expand All @@ -92,7 +93,7 @@ def new_razzia(request, razzia_type=BreadRazzia.BREAD):
razzia = BreadRazzia(razzia_type=razzia_type)
razzia.save()

views = {BreadRazzia.BREAD: 'bread_view', BreadRazzia.FOOBAR: 'foobar_view'}
views = {BreadRazzia.BREAD: 'bread_view', BreadRazzia.FOOBAR: 'foobar_view', BreadRazzia.FNUGFALD: 'fnugfald_view'}

return redirect(views[razzia_type], razzia_id=razzia.pk)

Expand Down
34 changes: 34 additions & 0 deletions stregsystem/templates/admin/stregsystem/razzia/fnugfald.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "admin/stregsystem/razzia/razzia_search.html" %}

{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Hjem</a>&nbsp;&rsaquo;&nbsp;<a href="../../../">Stregsystem</a>&nbsp;&rsaquo;&nbsp;<a href="../">Fnugfald razzia</a></div>{% endblock %}

{% block member_present %}
<div class="status">
{% if drunkard %}
<script>
// fade/flash background color to more easily notify foobar crew
let ofs = 0;
let el = document.body;
window.setInterval(function(){
el.style.background = 'rgba(255,255,0,'+Math.abs(Math.sin(ofs))+')';
ofs += 0.02;
}, 10);
</script>
<div class="fa fa-exclamation-triangle failure" aria-hidden="true"></div>
{% else %}
<div class="fa {% if already_used %} fa-exclamation-circle sucess {% else %} fa-check-circle sucess {% endif %}" aria-hidden="true"></div>
{% endif %}
</div>
{% if drunkard %}
{{member.firstname}} {{member.lastname}} ({{member.username}}) <b>wait {{ remaining_time_mins }}m {{ remaining_time_secs }}s </b> before next free beer
{% else %}
{{member.firstname}} {{member.lastname}} ({{member.username}}) {% if already_checked_in %} last checked in at {{last_entry.time}} {% endif %}
{% endif %}

{% endblock %}

{% block drunkard_present %}
fa-exclamation-triangle
{% if drunkard %} checked in within the previous hour, wait {{ remaining_time }}{% endif %}
{% endblock %}

0 comments on commit 3399a25

Please sign in to comment.