diff --git a/db.sqlite3 b/db.sqlite3 index 8d74012..4249e6f 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/mysite/settings.py b/mysite/settings.py index 877f5d5..7a27f5c 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -117,7 +117,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = '/static/' +STATICFILES_DIRS = [BASE_DIR] # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/mysite/urls.py b/mysite/urls.py index 3257d5a..b5d5113 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -1,7 +1,10 @@ from django.contrib import admin from django.urls import include, path +from polls.views import HomeView + urlpatterns = [ + path('', HomeView.as_view(), name='home'), path("polls/", include("polls.urls")), path('admin/', admin.site.urls), ] diff --git a/polls/static/polls/base.css b/polls/static/polls/base.css new file mode 100644 index 0000000..afd26f9 --- /dev/null +++ b/polls/static/polls/base.css @@ -0,0 +1,191 @@ +/*! NAVBAR */ + +header { + background-color: #1C1C1C; + color: #fff; + padding: 20px; + text-align: center; + display: flex; + justify-content: center; + align-items: center; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); + border-radius: 10px; +} + +.nav-container { + display: flex; + justify-content: center; + align-items: center; +} + +.nav-left h1 a { + text-decoration: none; + color: #fff; + font-size: 24px; +} + + +.nav-right ul { + list-style: none; + padding: 0; + margin: 0; + display: flex; + align-items: center; +} + +.nav-right li { + margin: 0 10px; +} + +.nav-right a { + text-decoration: none; + color: #fff; + font-weight: bold; + padding: 10px 20px; + border: 2px solid #fff; + border-radius: 5px; + transition: background-color 0.3s ease, color 0.3s ease; +} + +.nav-right a:hover { + background-color: #fff; + color: #007bff; +} + +/*! HOME AND POLL CARD */ + +.hero-section { + background-size: cover; + background-position: center; + text-align: center; + color: #1c1c1c; +} + +.hero-content { + max-width: 800px; + margin: 0 auto; +} + +h1 { + font-size: 36px; + margin-bottom: 20px; +} + +.polls-section { + background-size: cover; + background-position: center; + text-align: center; + color: #1c1c1c; +} + +.poll-cards { + display: flex; + flex-wrap: wrap; + gap: 20px; + justify-content: center; + margin-top: 30px; +} + +.poll-card { + background-color: #fff; + border: 1px solid #e0e0e0; + padding: 20px; + border-radius: 5px; + box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1); + transition: transform 0.3s ease; + cursor: pointer; +} + +.poll-card:hover { + transform: translateY(-5px); +} + +/*! DETAILED */ + +.poll-details { + padding: 30px; + background-color: #fff; + border-radius: 10px; + box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1); +} + +.poll-form { + text-align: center; +} + +.poll-question { + font-size: 24px; + margin-bottom: 20px; +} + +.error-message { + color: red; + margin-bottom: 10px; +} + +.choice { + display: flex; + align-items: center; + margin: 10px 0; +} + +.choice input[type="radio"] { + margin-right: 10px; +} + +.choice-text { + font-size: 18px; +} + +.vote-button { + background-color: #007bff; + color: #fff; + padding: 10px 20px; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s ease, color 0.3s ease; +} + +.vote-button:hover { + background-color: #0056b3; +} + +/*! RESULT */ + +.poll-results { + text-align: center; + padding: 30px; + background-color: #fff; + border-radius: 10px; + box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1); +} + +.poll-question { + font-size: 24px; + margin-bottom: 20px; +} + +.choice-list { + list-style: none; + padding: 0; + margin: 20px 0; + text-align: left; +} + +.choice-item { + font-size: 18px; + margin: 10px 0; +} + +.vote-again { + display: inline-block; + margin-top: 20px; + text-decoration: none; + color: #007bff; + transition: color 0.3s ease; +} + +.vote-again:hover { + color: #0056b3; +} \ No newline at end of file diff --git a/polls/static/polls/style.css b/polls/static/polls/style.css index 2fdfd86..e69de29 100644 --- a/polls/static/polls/style.css +++ b/polls/static/polls/style.css @@ -1,6 +0,0 @@ -li a { - color: green; -} -body { - background: white url("images/background.jpg") no-repeat; -} \ No newline at end of file diff --git a/polls/templates/polls/base.html b/polls/templates/polls/base.html new file mode 100644 index 0000000..ae54f87 --- /dev/null +++ b/polls/templates/polls/base.html @@ -0,0 +1,25 @@ +{% load static %} + + + MySite Polls + + + + +
+
+ + +
+ {% block content %} + {% endblock content %} +
+ + diff --git a/polls/templates/polls/detail.html b/polls/templates/polls/detail.html index 6df8776..8ca20b6 100644 --- a/polls/templates/polls/detail.html +++ b/polls/templates/polls/detail.html @@ -1,12 +1,24 @@ -
- {% csrf_token %} -
-

{{ question.question_text }}

- {% if error_message %}

{{ error_message }}

{% endif %} - {% for choice in question.choice_set.all %} - -
- {% endfor %} -
- -
\ No newline at end of file +{% extends 'polls/base.html' %} + +{% block content %} +
+
+
+ {% csrf_token %} +
+ {{ question.question_text }} + {% if error_message %} +

{{ error_message }}

+ {% endif %} + {% for choice in question.choice_set.all %} +
+ + +
+ {% endfor %} +
+ +
+
+
+{% endblock content %} diff --git a/polls/templates/polls/home.html b/polls/templates/polls/home.html new file mode 100644 index 0000000..ad8a1c8 --- /dev/null +++ b/polls/templates/polls/home.html @@ -0,0 +1,26 @@ +{% extends 'polls/base.html' %} + +{% block content %} +
+
+
+

Welcome to KU Polls

+

Explore and participate in our weird poll questions.

+
+
+
+

Recent Polls

+

Total number of polls: {{ total_polls }}

+
+ {% if latest_question_list %} + {% for question in latest_question_list %} + + {% endfor %} + {% else %} +

No polls are available.

+ {% endif %} +
+
+{% endblock content %} diff --git a/polls/templates/polls/index.html b/polls/templates/polls/index.html index 04410ae..ee0d853 100644 --- a/polls/templates/polls/index.html +++ b/polls/templates/polls/index.html @@ -1,13 +1,18 @@ -{% load static %} +{% extends 'polls/base.html' %} - - -{% if latest_question_list %} - -{% else %} -

No polls are available.

-{% endif %} \ No newline at end of file +{% block content %} +
+

Recent Polls

+
+ {% if latest_question_list %} + {% for question in latest_question_list %} + + {% endfor %} + {% else %} +

No polls are available.

+ {% endif %} +
+
+{% endblock content %} diff --git a/polls/templates/polls/result.html b/polls/templates/polls/result.html deleted file mode 100644 index 33b67b2..0000000 --- a/polls/templates/polls/result.html +++ /dev/null @@ -1,9 +0,0 @@ -

{{ question.question_text }}

- - - -Vote again? \ No newline at end of file diff --git a/polls/templates/polls/results.html b/polls/templates/polls/results.html index 33b67b2..dd55c8d 100644 --- a/polls/templates/polls/results.html +++ b/polls/templates/polls/results.html @@ -1,9 +1,17 @@ -

{{ question.question_text }}

+{% extends 'polls/base.html' %} - - -Vote again? \ No newline at end of file +{% block content %} +
+
+
+

{{ question.question_text }}

+
+
    + {% for choice in question.choice_set.all %} +
  • {{ choice.choice_text }} — {{ choice.votes }} vote{{ choice.votes|pluralize }}
  • + {% endfor %} +
+ Vote again? +
+
+{% endblock content %} diff --git a/polls/views.py b/polls/views.py index 57448fd..320229c 100644 --- a/polls/views.py +++ b/polls/views.py @@ -3,50 +3,19 @@ from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.views import generic from django.utils import timezone +from django.views.generic import TemplateView from .models import Choice, Question -# def index(request): -# latest_question_list = Question.objects.order_by("-pub_date")[:5] -# context = {"latest_question_list": latest_question_list} -# return render(request, "polls/index.html", context) +class HomeView(TemplateView): + template_name = 'polls/home.html' - -# def index(request): -# lastest_question_list = Question.objects.order_by("-pub_date")[:5] -# template = loader.get_template("polls/index.html") -# context = { -# "lastest_question_list": lastest_question_list -# } -# return HttpResponse(template.render(context, request)) - - -# def detail(request, question_id): -# try: -# question = Question.objects.get(pk=question_id) -# except Question.DoesNotExist: -# raise Http404("Question does not exist") -# return render(request, "polls/detail.html", {"question": question}) - - -# def detail(request, question_id): -# question = get_object_or_404(Question, pk=question_id) -# return render(request, "polls/detail.html", {"question": question}) - - -# def results(request, question_id): -# response = "You're looking at the results of question %s." -# return HttpResponse(response % question_id) - - -# def results(request, question_id): -# question = get_object_or_404(Question, pk=question_id) -# return render(request, "polls/results.html", {"question": question}) - - -# def vote(request, question_id): -# return HttpResponse("You're voting on question %s." % question_id) + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['latest_question_list'] = Question.objects.filter(pub_date__lte=timezone.now()).order_by("-pub_date")[:5] + context['total_polls'] = Question.objects.count() + return context class IndexView(generic.ListView):