web/quotes: shipit
This commit is contained in:
parent
da459ee5c1
commit
de8bb349f0
11 changed files with 82 additions and 10 deletions
|
@ -18,6 +18,8 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("", views.home, name="home"),
|
||||
re_path(r"(?P<quote_id>[0-9]+)/", views.show_quote, name="show_quote"),
|
||||
re_path(r"(?P<quote_id>[0-9]+)/$", views.show_quote, name="show_quote"),
|
||||
re_path(r"(?P<quote_id>[0-9]+)/delete/$", views.delete_quote, name="delete_quote"),
|
||||
path("new/", views.add_quote),
|
||||
path("all/", views.list_quotes),
|
||||
]
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
||||
</head>
|
||||
|
||||
<body class="bg-bfobGray-dark text-bfobGray font-sans leading-normal tracking-normal">
|
||||
<body class="bg-bfobGray-dark text-bfobGray font-sans leading-normal tracking-normal text-lg">
|
||||
|
||||
<div class="container mx-auto max-w-screen-md">
|
||||
<section class="flex justify-between items-center">
|
||||
|
@ -23,13 +23,14 @@
|
|||
<div class="flex justify-between">
|
||||
{% if user.is_authenticated %}
|
||||
<a href="/new/" class="px-4 py-1 rounded-l-full text-sm border border-bfobOrange border-r-0 text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">+</a>
|
||||
<a href="/all/" class="px-4 py-1 text-sm border border-bfobOrange border-r-0 text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">all</a>
|
||||
<form action="/accounts/logout/" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="next" value="/accounts/logged_out/">
|
||||
<button type="submit" class="px-4 py-1 rounded-r-full text-sm border border-bfobOrange text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">Logout</button>
|
||||
<button type="submit" class="px-4 py-1 rounded-r-full text-sm border border-bfobOrange text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">logout</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<a href="/accounts/discord/login/?process=login&next={{ request.path }}" class="px-4 py-1 rounded-full text-sm border border-bfobOrange text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">Login</a>
|
||||
<a href="/accounts/discord/login/?process=login&next={{ request.path }}" class="px-4 py-1 rounded-full text-sm border border-bfobOrange text-bfobOrange hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark">login</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<div>
|
||||
<p><a href="/{{ quote.id }}/">#{{ quote.id }}</a></p>
|
||||
<pre>{{ quote.quote }}</pre>
|
||||
<p class="text-sm">added by <span class="font-mono">{{ quote.added_by.username }}</span> on <span class="font-mono">{{ quote.added_at }}</span></p>
|
||||
{% if request.user == quote.added_by %}
|
||||
<a href="/{{ quote.id }}/delete/" class="text-sm underline">del</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
14
web/quotes/templates/quotedb/delete_quote.html
Normal file
14
web/quotes/templates/quotedb/delete_quote.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Delete #{{ quote.id }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="text-bfobOrange font-bnto text-2xl">Delete Quote #{{ quote.id }}?</h2>
|
||||
|
||||
<pre>{{ quote.quote }}</pre>
|
||||
|
||||
<form action="" method="POST">
|
||||
{% csrf_token %}
|
||||
<button class="border border-bfobOrange text-bfobOrange p-2 hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark" type="submit">Delete it forever</button>
|
||||
</form>
|
||||
{% endblock %}
|
6
web/quotes/templates/quotedb/deleted_quote.html
Normal file
6
web/quotes/templates/quotedb/deleted_quote.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends "alert.html" %}
|
||||
|
||||
{% block title %}Deleted #{{ quote_id }}{% endblock %}
|
||||
|
||||
{% block content_title %}<span class="text-bfobOrange">Deleted</span> #{{ quote_id }}{% endblock %}
|
||||
{% block content_text %}Farewell, poor Yorick. I hardly knew em.{% endblock %}
|
|
@ -5,5 +5,5 @@
|
|||
{% block content %}
|
||||
<h2 class="text-bfobOrange font-bnto text-2xl">...were you expecting something?</h2>
|
||||
|
||||
{% include "quotedb/_quote.html" with quote=quote only %}
|
||||
{% include "quotedb/_quote.html" %}
|
||||
{% endblock %}
|
||||
|
|
24
web/quotes/templates/quotedb/list.html
Normal file
24
web/quotes/templates/quotedb/list.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}List{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="text-bfobOrange font-bnto text-2xl">quote list</h2>
|
||||
|
||||
<div class="border-b border-bfobGray">
|
||||
{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}">prev</a>{% endif %}
|
||||
{% if page.has_next %}{% if page.has_previous %} | {% endif %}<a href="?page={{ page.next_page_number }}">next</a>{% endif %}
|
||||
</div>
|
||||
|
||||
{% comment %}{% include "quotedb/_quote.html" %}{% endcomment %}
|
||||
{% for quote in page %}
|
||||
<div class="border-b border-bfobGray">
|
||||
{% include "quotedb/_quote.html" %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div>
|
||||
{% if page.has_previous %}<a href="?page={{ page.previous_page_number }}">prev</a>{% endif %}
|
||||
{% if page.has_next %}{% if page.has_previous %} | {% endif %}<a href="?page={{ page.next_page_number }}">next</a>{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -8,8 +8,8 @@
|
|||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="grid grid-cols-1 gap-4 my-5">
|
||||
<textarea name="quote"></textarea>
|
||||
<button class="border border-bfobGray p-2" type="submit">Add Quote</button>
|
||||
<textarea name="quote" class="font-mono h-24 bg-bfobGray-dark border border-bfobOrange text-bfobGray placeholder-current" placeholder="<lukegb> hello I am luke, type things in me owo" autofocus></textarea>
|
||||
<button class="border border-bfobOrange text-bfobOrange p-2 hover:border-transparent hover:bg-bfobOrange hover:text-bfobGray-dark" type="submit">Add Quote</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
{% block content %}
|
||||
<h2 class="text-bfobOrange font-bnto text-2xl">Quote #{{ quote.id }}</h2>
|
||||
|
||||
{% include "quotedb/_quote.html" with quote=quote only %}
|
||||
{% include "quotedb/_quote.html" %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -11,10 +11,10 @@ module.exports = {
|
|||
extend: {
|
||||
colors: {
|
||||
bfobGray: {
|
||||
dark: '#373535',
|
||||
dark: '#222222',
|
||||
DEFAULT: '#7E7F7F',
|
||||
},
|
||||
bfobOrange: '#F48735',
|
||||
bfobOrange: '#F38120',
|
||||
},
|
||||
fontFamily: {
|
||||
bnto: ['BigNoodleTooOblique'],
|
||||
|
|
Loading…
Reference in a new issue