diff --git a/web/quotes/quotedb/urls.py b/web/quotes/quotedb/urls.py index 4f1072259c..3758839cfe 100644 --- a/web/quotes/quotedb/urls.py +++ b/web/quotes/quotedb/urls.py @@ -18,6 +18,8 @@ from . import views urlpatterns = [ path("", views.home, name="home"), - re_path(r"(?P[0-9]+)/", views.show_quote, name="show_quote"), + re_path(r"(?P[0-9]+)/$", views.show_quote, name="show_quote"), + re_path(r"(?P[0-9]+)/delete/$", views.delete_quote, name="delete_quote"), path("new/", views.add_quote), + path("all/", views.list_quotes), ] diff --git a/web/quotes/quotedb/views.py b/web/quotes/quotedb/views.py index 3713ba63be..9ad1cbaefc 100644 --- a/web/quotes/quotedb/views.py +++ b/web/quotes/quotedb/views.py @@ -1,3 +1,4 @@ +from django.core.paginator import Paginator from django.shortcuts import get_object_or_404, render, redirect from django.forms import ModelForm @@ -15,6 +16,18 @@ def home(request): ) +def list_quotes(request): + quotes = models.Quote.objects.all().order_by("-pk") + items_per_page = 10 + p = Paginator(quotes, items_per_page) + try: + page_num = int(request.GET.get("page", "1"), 10) + except: + page_num = 1 + page = p.page(page_num) + return render(request, "quotedb/list.html", {"paginator": p, "page": page}) + + def show_quote(request, quote_id): quote = get_object_or_404(models.Quote, id=int(quote_id)) return render(request, "quotedb/show_quote.html", {"quote": quote}) @@ -38,3 +51,11 @@ def add_quote(request): form = AddQuoteForm() return render(request, "quotedb/new.html", {"form": form}) + + +def delete_quote(request, quote_id): + quote = get_object_or_404(models.Quote, id=int(quote_id), added_by=request.user) + if request.method == "POST": + quote.delete() + return render(request, "quotedb/deleted_quote.html", {"quote_id": quote_id}) + return render(request, "quotedb/delete_quote.html", {"quote": quote}) diff --git a/web/quotes/templates/base.html b/web/quotes/templates/base.html index 3fbcb06502..edb11d200a 100644 --- a/web/quotes/templates/base.html +++ b/web/quotes/templates/base.html @@ -11,7 +11,7 @@ - +
@@ -23,13 +23,14 @@
{% if user.is_authenticated %} + + all
{% csrf_token %} - +
{% else %} - Login + login {% endif %}
diff --git a/web/quotes/templates/quotedb/_quote.html b/web/quotes/templates/quotedb/_quote.html index ab176cd33f..319bd60911 100644 --- a/web/quotes/templates/quotedb/_quote.html +++ b/web/quotes/templates/quotedb/_quote.html @@ -1,4 +1,8 @@

#{{ quote.id }}

{{ quote.quote }}
+

added by {{ quote.added_by.username }} on {{ quote.added_at }}

+ {% if request.user == quote.added_by %} + del + {% endif %}
diff --git a/web/quotes/templates/quotedb/delete_quote.html b/web/quotes/templates/quotedb/delete_quote.html new file mode 100644 index 0000000000..51046f4dcf --- /dev/null +++ b/web/quotes/templates/quotedb/delete_quote.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block title %}Delete #{{ quote.id }}{% endblock %} + +{% block content %} +

Delete Quote #{{ quote.id }}?

+ +
{{ quote.quote }}
+ +
+ {% csrf_token %} + +
+{% endblock %} diff --git a/web/quotes/templates/quotedb/deleted_quote.html b/web/quotes/templates/quotedb/deleted_quote.html new file mode 100644 index 0000000000..e5fe8fc8e3 --- /dev/null +++ b/web/quotes/templates/quotedb/deleted_quote.html @@ -0,0 +1,6 @@ +{% extends "alert.html" %} + +{% block title %}Deleted #{{ quote_id }}{% endblock %} + +{% block content_title %}Deleted #{{ quote_id }}{% endblock %} +{% block content_text %}Farewell, poor Yorick. I hardly knew em.{% endblock %} diff --git a/web/quotes/templates/quotedb/home.html b/web/quotes/templates/quotedb/home.html index 6ab0994d05..6a6c1f8eb1 100644 --- a/web/quotes/templates/quotedb/home.html +++ b/web/quotes/templates/quotedb/home.html @@ -5,5 +5,5 @@ {% block content %}

...were you expecting something?

-{% include "quotedb/_quote.html" with quote=quote only %} +{% include "quotedb/_quote.html" %} {% endblock %} diff --git a/web/quotes/templates/quotedb/list.html b/web/quotes/templates/quotedb/list.html new file mode 100644 index 0000000000..0e44c1723c --- /dev/null +++ b/web/quotes/templates/quotedb/list.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block title %}List{% endblock %} + +{% block content %} +

quote list

+ +
+ {% if page.has_previous %}prev{% endif %} + {% if page.has_next %}{% if page.has_previous %} | {% endif %}next{% endif %} +
+ +{% comment %}{% include "quotedb/_quote.html" %}{% endcomment %} +{% for quote in page %} +
+ {% include "quotedb/_quote.html" %} +
+{% endfor %} + +
+ {% if page.has_previous %}prev{% endif %} + {% if page.has_next %}{% if page.has_previous %} | {% endif %}next{% endif %} +
+{% endblock %} diff --git a/web/quotes/templates/quotedb/new.html b/web/quotes/templates/quotedb/new.html index ca105a0a6d..8bcc5bdc3f 100644 --- a/web/quotes/templates/quotedb/new.html +++ b/web/quotes/templates/quotedb/new.html @@ -8,8 +8,8 @@
{% csrf_token %}
- - + +
{% endblock %} diff --git a/web/quotes/templates/quotedb/show_quote.html b/web/quotes/templates/quotedb/show_quote.html index 3b6a983023..56c24098bd 100644 --- a/web/quotes/templates/quotedb/show_quote.html +++ b/web/quotes/templates/quotedb/show_quote.html @@ -5,5 +5,5 @@ {% block content %}

Quote #{{ quote.id }}

-{% include "quotedb/_quote.html" with quote=quote only %} +{% include "quotedb/_quote.html" %} {% endblock %} diff --git a/web/quotes/theme/static_src/tailwind.config.js b/web/quotes/theme/static_src/tailwind.config.js index d2056259d9..f58dbb23b7 100644 --- a/web/quotes/theme/static_src/tailwind.config.js +++ b/web/quotes/theme/static_src/tailwind.config.js @@ -11,10 +11,10 @@ module.exports = { extend: { colors: { bfobGray: { - dark: '#373535', + dark: '#222222', DEFAULT: '#7E7F7F', }, - bfobOrange: '#F48735', + bfobOrange: '#F38120', }, fontFamily: { bnto: ['BigNoodleTooOblique'],