From 43eefd6bc133f493baab35d4ca04e0596388cbb2 Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Sat, 2 Mar 2024 16:30:18 +1300 Subject: [PATCH] [guivis/KeepPolling#6] - Add some styles and fonts - views and templates for landing page and polls subpage --- keeppolling/urls.py | 19 +++++ landing/templates/landing/landing.html | 11 +++ landing/urls.py | 11 +++ landing/views.py | 13 +++- polls/templates/polls/poll_details.html | 14 ++++ polls/templates/polls/poll_entry.html | 6 ++ polls/templates/polls/polls.html | 12 ++++ polls/urls.py | 16 +++++ polls/views.py | 41 ++++++++++- static/css/fonts.css | 96 +++++++++++++++++++++++++ static/css/style.css | 57 +++++++++++++++ templates/base_template.html | 21 +++++- 12 files changed, 312 insertions(+), 5 deletions(-) create mode 100644 landing/templates/landing/landing.html create mode 100644 landing/urls.py create mode 100644 polls/templates/polls/poll_details.html create mode 100644 polls/templates/polls/poll_entry.html create mode 100644 polls/templates/polls/polls.html create mode 100644 polls/urls.py create mode 100644 static/css/fonts.css diff --git a/keeppolling/urls.py b/keeppolling/urls.py index d07df15..7895465 100644 --- a/keeppolling/urls.py +++ b/keeppolling/urls.py @@ -16,6 +16,7 @@ Including another URLconf """ from django.contrib import admin from django.urls import path, include +from django.views.generic import RedirectView urlpatterns = [ path( @@ -28,4 +29,22 @@ urlpatterns = [ "django.contrib.auth.urls", ), ), + path( + "", + RedirectView.as_view( + url="landing/", + ), + ), + path( + "landing/", + include( + "landing.urls", + ), + ), + path( + "polls/", + include( + "polls.urls", + ), + ), ] diff --git a/landing/templates/landing/landing.html b/landing/templates/landing/landing.html new file mode 100644 index 0000000..702acb9 --- /dev/null +++ b/landing/templates/landing/landing.html @@ -0,0 +1,11 @@ +{% extends "base_template.html" %} + +{% block content %} + +
+
+ +{% endblock %} diff --git a/landing/urls.py b/landing/urls.py new file mode 100644 index 0000000..e37a72e --- /dev/null +++ b/landing/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from landing.views import landing + +urlpatterns = [ + path( + "", + landing, + name="landing", + ), +] diff --git a/landing/views.py b/landing/views.py index 91ea44a..ed23e85 100644 --- a/landing/views.py +++ b/landing/views.py @@ -1,3 +1,14 @@ +from django.contrib.auth.decorators import login_required from django.shortcuts import render -# Create your views here. + +@login_required +def landing( + request, +): + context = {} + return render( + request, + template_name="landing/landing.html", + context=context, + ) diff --git a/polls/templates/polls/poll_details.html b/polls/templates/polls/poll_details.html new file mode 100644 index 0000000..19af3af --- /dev/null +++ b/polls/templates/polls/poll_details.html @@ -0,0 +1,14 @@ +
+
+ {{ poll.question }} +
+
+ {% for option in options %} +
+ Option: {{ option.text }} +
+ {% empty %} + No options defined for Question! + {% endfor %} +
+
\ No newline at end of file diff --git a/polls/templates/polls/poll_entry.html b/polls/templates/polls/poll_entry.html new file mode 100644 index 0000000..7fa7452 --- /dev/null +++ b/polls/templates/polls/poll_entry.html @@ -0,0 +1,6 @@ +
+ {{ poll.question }} +
diff --git a/polls/templates/polls/polls.html b/polls/templates/polls/polls.html new file mode 100644 index 0000000..550e8d3 --- /dev/null +++ b/polls/templates/polls/polls.html @@ -0,0 +1,12 @@ +
+
+ {% for poll in polls %} + {% include "polls/poll_entry.html" with poll=poll %} + {% empty %} + No Polls! Define one in the Admin Panel. + {% endfor %} +
+
+ Select a Poll on the Left +
+
\ No newline at end of file diff --git a/polls/urls.py b/polls/urls.py new file mode 100644 index 0000000..bb965cd --- /dev/null +++ b/polls/urls.py @@ -0,0 +1,16 @@ +from django.urls import path + +from polls.views import polls, poll_details + +urlpatterns = [ + path( + "", + polls, + name="polls", + ), + path( + "", + poll_details, + name="poll-details", + ), +] diff --git a/polls/views.py b/polls/views.py index 91ea44a..bd7803f 100644 --- a/polls/views.py +++ b/polls/views.py @@ -1,3 +1,40 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 -# Create your views here. +from polls.models import Poll, Option + + +def polls( + request, +): + context = {} + + context["polls"] = Poll.objects.all() + + return render( + request, + template_name="polls/polls.html", + context=context, + ) + + +def poll_details( + request, + poll_id, +): + poll = get_object_or_404( + Poll, + pk=poll_id, + ) + + context = {} + + context["poll"] = poll + context["options"] = Option.objects.filter( + poll=poll, + ) + + return render( + request, + template_name="polls/poll_details.html", + context=context, + ) diff --git a/static/css/fonts.css b/static/css/fonts.css new file mode 100644 index 0000000..0706cc1 --- /dev/null +++ b/static/css/fonts.css @@ -0,0 +1,96 @@ +@import url('https://fonts.googleapis.com/css2?family=Kanit:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'); + +.h0 { + font-size: 48px; +} + +.kanit-thin { + font-family: "Kanit", sans-serif; + font-weight: 100; + font-style: normal; +} +.kanit-extralight { + font-family: "Kanit", sans-serif; + font-weight: 200; + font-style: normal; +} +.kanit-light { + font-family: "Kanit", sans-serif; + font-weight: 300; + font-style: normal; +} +.kanit-regular { + font-family: "Kanit", sans-serif; + font-weight: 400; + font-style: normal; +} +.kanit-medium { + font-family: "Kanit", sans-serif; + font-weight: 500; + font-style: normal; +} +.kanit-semibold { + font-family: "Kanit", sans-serif; + font-weight: 600; + font-style: normal; +} +.kanit-bold { + font-family: "Kanit", sans-serif; + font-weight: 700; + font-style: normal; +} +.kanit-extrabold { + font-family: "Kanit", sans-serif; + font-weight: 800; + font-style: normal; +} +.kanit-black { + font-family: "Kanit", sans-serif; + font-weight: 900; + font-style: normal; +} +.kanit-thin-italic { + font-family: "Kanit", sans-serif; + font-weight: 100; + font-style: italic; +} +.kanit-extralight-italic { + font-family: "Kanit", sans-serif; + font-weight: 200; + font-style: italic; +} +.kanit-light-italic { + font-family: "Kanit", sans-serif; + font-weight: 300; + font-style: italic; +} +.kanit-regular-italic { + font-family: "Kanit", sans-serif; + font-weight: 400; + font-style: italic; +} +.kanit-medium-italic { + font-family: "Kanit", sans-serif; + font-weight: 500; + font-style: italic; +} +.kanit-semibold-italic { + font-family: "Kanit", sans-serif; + font-weight: 600; + font-style: italic; +} +.kanit-bold-italic { + font-family: "Kanit", sans-serif; + font-weight: 700; + font-style: italic; +} +.kanit-extrabold-italic { + font-family: "Kanit", sans-serif; + font-weight: 800; + font-style: italic; +} +.kanit-black-italic { + font-family: "Kanit", sans-serif; + font-weight: 900; + font-style: italic; +} diff --git a/static/css/style.css b/static/css/style.css index e69de29..3c7656a 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -0,0 +1,57 @@ +@import url("https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"); +* { + -webkit-font-smoothing: antialiased; + box-sizing: border-box; +} +html, +body { + margin: 0px; + height: 100%; +} +body { + display: flex; + flex-direction: column; +} + +header { + display: flex; + padding: 16px; +} + +.title { + flex-grow: 1; +} + +.content { + flex-grow: 1; + z-index: 2; + height: auto; + min-height: 400px; + left: 0px; + right: 0px; + background-color: rgb(225, 234, 214); + border-radius: 16px; + box-shadow: 0px 5px 50px #e5e0dd; + padding: 16px; + margin-bottom: 64px; + overflow-y: scroll; +} + +footer { + z-index: 3; + position: fixed; + bottom: 0px; + left: 0px; + right: 0px; + display: flex; + height: 64px; + padding: 8px 16px; + align-items: center; + background-color: rgb(250, 234, 234); +} + +.polls { + display: grid; + grid-template-rows: 100%; + grid-template-columns: 1fr 1fr; +} diff --git a/templates/base_template.html b/templates/base_template.html index 8788036..3a86c05 100644 --- a/templates/base_template.html +++ b/templates/base_template.html @@ -11,6 +11,7 @@ {% load static %} +