-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Items remaining countdown, "add item" form, etc.
- Loading branch information
1 parent
7360b00
commit 684aeb8
Showing
10 changed files
with
215 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,5 @@ | |
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('', include("hat.urls")) | ||
path('', include("hat.urls")), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div id="counter" hx-swap-oob="true"> | ||
<h2>Are we there yet?</h2> | ||
{% if remaining_items == 0 %} | ||
<span class="announcement"> | ||
Yes! | ||
</span> | ||
{% elif remaining_items < 3 %} | ||
<span class="announcement"> | ||
Almost! There are only {{ remaining_items }} agenda items left! | ||
</span> | ||
{% else %} | ||
<span class="announcement"> | ||
NO. There are {{ remaining_items }} agenda items left. | ||
</span> | ||
{% endif %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,34 @@ | |
<head> | ||
<meta charset="UTF-8"> | ||
<title>Agenda Hat</title> | ||
<link rel="stylesheet" href="{% static 'hat/hat.css' %}" | ||
<link rel="stylesheet" href="{% static 'hat/hat.css' %}"> | ||
<script src="https://unpkg.com/[email protected]"></script> | ||
<script src="https://unpkg.com/[email protected]"></script> | ||
</head> | ||
<body> | ||
<h1>Agenda Hat</h1> | ||
<div class="sidebar left"> | ||
<h1>Agenda Hat</h1> | ||
<button hx-get="{% url 'new-item' %}" hx-target="#hat-pull" hx-swap="outerHTML">Add Something...</button> | ||
<a href="{% url 'pull-item' %}"><button>Next Item</button></a> | ||
</div> | ||
<div class="hat-container"> | ||
<div class="hat-pull {{ hat_class }}"> | ||
<div class="hat-pull {{ hat_class }}" id="hat-pull"> | ||
<img src="{% static 'hat/hand.png' %}"> | ||
<p> | ||
<div class="message"> | ||
{{ item.text }} | ||
</p> | ||
</div> | ||
</div> | ||
<img class="hat {{ hat_class }}" src="{% static 'hat/tophat.png' %}" alt="hat!"> | ||
</div> | ||
<div class="sidebar right"> | ||
{% include 'hat/counter-snippet.html' %} | ||
<ul> | ||
{% for item in past_items %} | ||
<li> | ||
<del>{{ item.text }}</del> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Agenda Hat</title> | ||
<link rel="stylesheet" href="{% static 'hat/hat.css' %}" | ||
</head> | ||
<body> | ||
<h1>Agenda Hat</h1> | ||
<div class="hat-container"> | ||
<div class="hat-pull {{ hat_class }}"> | ||
<img src="{% static 'hat/hand.png' %}"> | ||
<p> | ||
{{ item.text }} | ||
</p> | ||
</div> | ||
<img class="hat {{ hat_class }}" src="{% static 'hat/tophat.png' %}" alt="hat!"> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% load static %} | ||
|
||
<div id="hat-pull" class="hat-pull {{ hat_class }} new"> | ||
<img src="{% static 'hat/hand.png' %}"> | ||
<div class="message new"> | ||
<form> | ||
{% csrf_token %} | ||
{{ form.text }} | ||
<button hx-post="{% url 'new-item' %}" hx-target="#hat-pull" hx-swap="outerHTML settle:0.5s swap:0.5s" | ||
_="on click add .lock to #hat-pull"> | ||
Submit | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
{% include 'hat/counter-snippet.html' with remaining_items=remaining_items %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from django.urls import path | ||
from .views import pull_item | ||
from .views import pull_item, index, CreateItemView | ||
|
||
|
||
urlpatterns = [ | ||
path('', pull_item) | ||
path("", index, name="index"), | ||
path("next", pull_item, name="pull-item"), | ||
path("add", CreateItemView.as_view(), name="new-item"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
from django.shortcuts import render | ||
from django.urls import reverse_lazy | ||
from django.utils import timezone | ||
from django.views.generic import CreateView | ||
|
||
import random | ||
|
||
from .models import Item | ||
|
||
|
||
def get_remaining_items(): | ||
return Item.objects.filter(pulled=False).count() | ||
|
||
def index(request): | ||
return render(request, 'hat/hat.html', { | ||
'hat_class': 'index', # todo: make timedelta in line 12 configurable | ||
'past_items': Item.objects.filter(pulled=True, pulled_at__range=(timezone.now() - timezone.timedelta(hours=6), timezone.now())), | ||
'remaining_items': Item.objects.filter(pulled=False).count(), | ||
}) | ||
|
||
|
||
def pull_item(request): | ||
item = '' | ||
hat_class = '' | ||
try: | ||
item = random.choice(Item.objects.filter(pulled=False)) | ||
item.pulled = True | ||
item.pulled_at = timezone.now() | ||
item.save() | ||
except IndexError: | ||
hat_class = 'finished' | ||
|
||
return render(request, 'hat/hat.html', { | ||
'item': item, | ||
'hat_class': hat_class, | ||
}) | ||
'past_items': Item.objects.filter(pulled=True, pulled_at__range=(timezone.now() - timezone.timedelta(hours=6), timezone.now())), | ||
'remaining_items': Item.objects.filter(pulled=False).count(), | ||
}) | ||
|
||
|
||
class CreateItemView(CreateView): | ||
model = Item | ||
template_name = "hat/new_item.html" | ||
fields = [ | ||
'text', | ||
] | ||
success_url = reverse_lazy('new-item') | ||
print(Item.objects.filter(pulled=False)) | ||
extra_context = { | ||
'remaining_items': get_remaining_items | ||
} | ||
|
||
|