diff --git a/hackathon/templates/hackathon/hackathon_list.html b/hackathon/templates/hackathon/hackathon_list.html new file mode 100644 index 00000000..fbbdc72b --- /dev/null +++ b/hackathon/templates/hackathon/hackathon_list.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} +{% load static %} +{% block content %} +
+ {% if page_obj %} +

Hackathons

+ {% for hackathon in page_obj %} + {% include 'hackathon/includes/hackathon_card.html' %} +
+ {% endfor %} + {% else %} +

There aren't any Hackathons at the moment!

+ {% endif %} + + +
+{% endblock %} \ No newline at end of file diff --git a/hackathon/templates/hackathon/includes/hackathon_card.html b/hackathon/templates/hackathon/includes/hackathon_card.html new file mode 100644 index 00000000..65299654 --- /dev/null +++ b/hackathon/templates/hackathon/includes/hackathon_card.html @@ -0,0 +1,11 @@ +
+
+
{{ hackathon.display_name }}
+
{{ hackathon.start_date }} - {{ hackathon.end_date }}
+

{{ hackathon.description }}

+ {% if hackathon.organiser %} +

Organiser: {{ hackathon.organiser }}

+ {% endif %} + Read More +
+
\ No newline at end of file diff --git a/hackathon/templates/hackathon/includes/paginator.html b/hackathon/templates/hackathon/includes/paginator.html new file mode 100644 index 00000000..3f7c1b05 --- /dev/null +++ b/hackathon/templates/hackathon/includes/paginator.html @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/hackathon/tests/test_models.py b/hackathon/tests/test_models.py index 0c2c3b23..338b9d9c 100644 --- a/hackathon/tests/test_models.py +++ b/hackathon/tests/test_models.py @@ -16,28 +16,25 @@ class HackathonTests(TestCase): def setUp(self): """Sets up the models for testing""" user = User.objects.create(username="testuser") - user.save() + hackathon = Hackathon.objects.create( created_by=user, display_name="hacktest", description="lorem ipsum", start_date=f'{timezone.now()}', end_date=f'{timezone.now()}') - hackathon.save() team = HackTeam.objects.create( created_by=user, display_name="testteam", hackathon=hackathon) - team.save() team.participants.set([user]) - award_category = HackAwardCategory.objects.create( + HackAwardCategory.objects.create( created_by=user, display_name="testaward", description="lorem ipsum", hackathon=hackathon) - award_category.save() project = HackProject.objects.create( created_by=user, @@ -45,20 +42,17 @@ def setUp(self): description="lorem ipsum", github_link="https://www.test.com/", collab_link="https://www.test.com/") - project.save() score_category = HackProjectScoreCategory.objects.create( created_by=user, category="testcategory") - score_category.save() - score = HackProjectScore.objects.create( + HackProjectScore.objects.create( created_by=user, judge=user, project=project, score=1, hack_project_score_category=score_category) - score.save() def test_hackathon_str(self): """Tests the string method on the hackathon.""" diff --git a/hackathon/tests/test_views.py b/hackathon/tests/test_views.py new file mode 100644 index 00000000..96d68326 --- /dev/null +++ b/hackathon/tests/test_views.py @@ -0,0 +1,36 @@ +from django.test import TestCase +from django.contrib.auth.models import User +from django.utils import timezone + +from hackathon.models import Hackathon + + +class TestHackathonViews(TestCase): + """Tests views for the Hackathon app.""" + + def setUp(self): + """Sets up the models for testing""" + user = User.objects.create(username="testuser") + Hackathon.objects.create( + created_by=user, + display_name="hacktest", + description="lorem ipsum", + start_date=f'{timezone.now()}', + end_date=f'{timezone.now()}') + + def test_render_hackathon_list(self): + """Tests the correct rendering of the hackathon list page, + including contexts.""" + + response = self.client.get('/hackathon/') + + # Confirms the correct template, context items and queryset + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'hackathon/hackathon_list.html') + self.assertTemplateUsed(response, + 'hackathon/includes/hackathon_card.html') + self.assertTemplateUsed(response, 'hackathon/includes/paginator.html') + self.assertTrue(response.context['page_obj']) + self.assertQuerysetEqual(response.context['page_obj'], + Hackathon.objects.all().order_by('-created'), + transform=lambda x: x) diff --git a/hackathon/urls.py b/hackathon/urls.py index 96f8167f..e5d31057 100644 --- a/hackathon/urls.py +++ b/hackathon/urls.py @@ -1,5 +1,7 @@ from django.urls import path -urlpatterns = [ +from .views import HackathonListView +urlpatterns = [ + path('', HackathonListView.as_view(), name="hackathon-list") ] diff --git a/hackathon/views.py b/hackathon/views.py index 91ea44a2..4642fae0 100644 --- a/hackathon/views.py +++ b/hackathon/views.py @@ -1,3 +1,10 @@ -from django.shortcuts import render +from django.views.generic import ListView -# Create your views here. +from .models import Hackathon + + +class HackathonListView(ListView): + """Renders a page with a list of Hackathons.""" + model = Hackathon + ordering = ['-created'] + paginate_by = 8 diff --git a/static/css/style.css b/static/css/style.css index 055b6353..8ebb9e15 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -72,3 +72,31 @@ footer { color: var(--s-grey); background-color: var(--p-grey); } + +/* TEXT */ +.p-orange { + color: var(--p-orange); +} + +.p-blue { + color: var(--p-blue); +} + +/* CARDS */ +.card-link:hover { + color: rgba(0, 0, 0, .7); +} + +.card-title { + font-family: Rubik, sans-serif; +} + +/* PAGINATION */ +.page-item .page-link { + color: var(--p-orange); +} + +.page-item.active .page-link { + background-color: var(--p-orange); + border-color: var(--p-orange); +} \ No newline at end of file diff --git a/templates/includes/navbar.html b/templates/includes/navbar.html index 21f6c94c..0dd27152 100644 --- a/templates/includes/navbar.html +++ b/templates/includes/navbar.html @@ -11,6 +11,17 @@ +