From e22ae60e925a7a63c7d65a5102d34821904685f4 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 11:56:04 +0200 Subject: [PATCH] Added template system. --- backend/RateMyCourse/urls.py | 9 ++++++- backend/db.sqlite3 | Bin 71680 -> 72704 bytes .../postings/collections/collection.html | 16 ++++++++++++ .../postings/collections/courses.html | 12 +++++++++ .../postings/collections/universities.html | 7 ++++++ .../templates/postings/generic_page.html | 23 ++++++++++++++++++ .../postings/templates/postings/index.html | 17 +++++++++++++ backend/postings/views.py | 16 ++++++++++++ 8 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 backend/postings/templates/postings/collections/collection.html create mode 100644 backend/postings/templates/postings/collections/courses.html create mode 100644 backend/postings/templates/postings/collections/universities.html create mode 100644 backend/postings/templates/postings/generic_page.html create mode 100644 backend/postings/templates/postings/index.html diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index 9cbc84d..dae6471 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -18,10 +18,17 @@ from django.urls import re_path,path,include from django.conf.urls import url from django.contrib.staticfiles.views import serve from django.views.generic import RedirectView +from postings import views urlpatterns = [ # / routes to index.html - url(r'^$', serve, kwargs={'path': 'index.html'}), + path('', views.index, name='homepage'), + + # /universities routes to a list of universities. + path('universities', views.universities, name='universities_list'), + + # /courses routes to a list of courses. + path('courses', views.courses, name='courses_list'), # static files (*.css, *.js, *.jpg etc.) served on / # (assuming Django uses /static/ and /media/ for static/media urls) diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index 359edf330bb4fdc20cdd32a017fd03ced1c164be..e236f72ab9b8af8039458c850c6f5fdbc2b290f1 100644 GIT binary patch delta 1810 zcmZ{kZD<@-6o&8IcV<76O|pbUn$Qesg;kU7%BlirB6|MeaogXC8Yq@f7$viV?+H#k1{q7o_B1pzKdy+(X>vEGui5&4fzR*>^P0j3m}E}lXcZ9@qFidY zRCB4~65&$GrGiVCOQ<|Q-V%}6-U?XZ9o31I8R6|E&{*W^YqghTaUw#VChRk8w9rNR z9xc#=!d>Bt&?kh*r=-M!-qjTelC~=S86gZgQCbmqTFNo1X|s;S7rU^ivAK*_W$2139B!QXg@ z1(x(3>U|IiH}g^NNhN_jgVOY@CfSOI7Umw mlS($7Q1&W!%Yb)OaZ=mPlK5GnYVm9~t7Y}nwu(|aD*7LXp0l3- delta 264 zcmZqJ!P2mSWr8%X7Xt%>8xU&%G2=uHb4IU?2}{^T*qI#}m>rp4F-I^jWuDGl$b6bv ze6t{nCi7%R?n)*GhRJ)l^~6M&nROXcvJ&&s^Wzg!ax?SdbMn(UH}SC8Y-UOL%e|Q~ zgjq$5llck*^B?B#%%7OwGQVJc%zTgeCi4}bS-Y4wU#T`=!KYv{P=OdH;{pce4a|AW zI!v#aRxqV8sW3ibTmUqnjdAmWxd}{*Iz%=LD!gZ&tiU3;NrjPPGvf+omc=YK9E(|0 gfOrp(4Wdu5Y-aKK$G(~A3KNhO^Ot`! + {% for entity in entities %} +
  • + {% block entity %} + {% endblock %} +
  • + {% endfor %} + + +{% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/collections/courses.html b/backend/postings/templates/postings/collections/courses.html new file mode 100644 index 0000000..4805231 --- /dev/null +++ b/backend/postings/templates/postings/collections/courses.html @@ -0,0 +1,12 @@ +{% extends "postings/collections/collection.html" %} + +{# Represents a list of university entities. #} + +{% block entity %} + {{ entity.name }}, University: {{ entity.taught_at_university.name}}
    +
      + {% for professor in entity.professors.all %} +
    • {{ professor.name }}
    • + {% endfor %} +
    +{% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/collections/universities.html b/backend/postings/templates/postings/collections/universities.html new file mode 100644 index 0000000..6f392e1 --- /dev/null +++ b/backend/postings/templates/postings/collections/universities.html @@ -0,0 +1,7 @@ +{% extends "postings/collections/collection.html" %} + +{# Represents a list of university entities. #} + +{% block entity %} + {{ entity.name }} +{% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/generic_page.html b/backend/postings/templates/postings/generic_page.html new file mode 100644 index 0000000..9f8d23a --- /dev/null +++ b/backend/postings/templates/postings/generic_page.html @@ -0,0 +1,23 @@ +{# This page represents the base template that all others will extend from. #} +{# It will contain a universal navigation bar, script tags, footers, and other things needed on every page. #} + + + + + + {% block title %}RateMyCourse{% endblock %} + + + + +
    +

    RateMyCourse

    +
    + + {# All of a page's content to display should be placed in here. #} +
    + {% block content %} + {% endblock %} +
    + + \ No newline at end of file diff --git a/backend/postings/templates/postings/index.html b/backend/postings/templates/postings/index.html new file mode 100644 index 0000000..d26bf17 --- /dev/null +++ b/backend/postings/templates/postings/index.html @@ -0,0 +1,17 @@ +{% extends "postings/generic_page.html" %} + +{# The homepage for the website. #} + +{% block content %} +

    + Click one of the links below to view a list of all those entities. +

    + +{% endblock %} \ No newline at end of file diff --git a/backend/postings/views.py b/backend/postings/views.py index 91ea44a..19b0baa 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -1,3 +1,19 @@ from django.shortcuts import render +from django.http import HttpResponse +from postings.models import * # Create your views here. + +# The view for the homepage, or index.html +def index(request): + return render(request, 'postings/index.html') + +def universities(request): + universities_list = University.objects.all() + context = {'entities': universities_list} + return render(request, 'postings/collections/universities.html', context) + +def courses(request): + courses_list = Course.objects.all() + context = {'entities': courses_list} + return render(request, 'postings/collections/courses.html', context) \ No newline at end of file