From 714f3241ceb291625d8003248c82cc8b448c3392 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 14:06:53 +0200 Subject: [PATCH] Added templates for all basic things. --- backend/RateMyCourse/urls.py | 6 +++++ backend/db.sqlite3 | Bin 72704 -> 72704 bytes .../postings/collections/collection.html | 4 +++ .../postings/collections/courses.html | 11 ++++---- .../postings/collections/universities.html | 6 ++++- .../postings/entity_pages/course.html | 11 ++++++++ .../postings/entity_pages/entity.html | 24 ++++++++++++++++++ .../postings/entity_pages/university.html | 16 ++++++++++++ .../templates/postings/generic_page.html | 6 ++--- backend/postings/views.py | 22 ++++++++++++++-- 10 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 backend/postings/templates/postings/entity_pages/course.html create mode 100644 backend/postings/templates/postings/entity_pages/entity.html create mode 100644 backend/postings/templates/postings/entity_pages/university.html diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index dae6471..cc3e5cb 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -27,9 +27,15 @@ urlpatterns = [ # /universities routes to a list of universities. path('universities', views.universities, name='universities_list'), + # /universities/ routes to a specific university. + path('universities/', views.university_entity, name='university entity'), + # /courses routes to a list of courses. path('courses', views.courses, name='courses_list'), + # /courses/ routes to a specific course. + path('courses/', views.course_entity, name='course entity'), + # static files (*.css, *.js, *.jpg etc.) served on / # (assuming Django uses /static/ and /media/ for static/media urls) url(r'^(?!/?static/)(?!/?media/)(?P.*\..*)$', diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index e236f72ab9b8af8039458c850c6f5fdbc2b290f1..a1acc0e128e208b3cdb393328e9c388717793535 100644 GIT binary patch delta 490 zcmZqJ!P2mUWr8$g$V3@u#*mE(i`bS6P6ZWwq~4cds=+51Gk|X^DYJ<1{5H~%dE{=kY8MqnU`K1UzA#wnOeSi zI(Kf4gfR0A2IfD^-G{FwP3^G)U}%riDiRn#y~{&1ONFN+Vdh1X z*&9@um=^)RmXuT~ zr03_SC?w}378i$PWELv`QC4Yji9(`6abj*kPO1XLJql_0MG7SusSuS4L8*nMnMJ9& zsd**E3aNSNnR%(HML_54DR?TR98f0RxYb`8Nae@6Cb=@0r;d7+9DY zIoUStU`gO(WvXIe-pQQLtig1UsS4=n3??;KVNM1|etm65PEPEm8XH&|7*2jLUxAT% K`#~v2dqx1KD~8el delta 204 zcmZqJ!P2mUWr8$g@I)DB#^8+!i`b=F8Mv5EGB7(b^D##-FJ+$2T*!QyS%v8&)4R=r zENhu2pX7>S6OtBSwq~4cds=+51Gk}?5HGVfM?rpZNoHPpaePr~S!QZE^DYJ<1~_28 z$RMG{FwP3^G)U}n`J6$m?s8sO#X10W%HuyBo<~N z=H-*w8&rXIRx@v2-W;p5m_>nOG0Tnw9u}s949q*3^O-f64g#e&GHpL7#c0n60G*CK A00000 diff --git a/backend/postings/templates/postings/collections/collection.html b/backend/postings/templates/postings/collections/collection.html index 37d3f2d..90d7f3b 100644 --- a/backend/postings/templates/postings/collections/collection.html +++ b/backend/postings/templates/postings/collections/collection.html @@ -4,10 +4,14 @@ {% block content %} +{% block collection_name %} +{% endblock %} +
    {% for entity in entities %}
  • {% block entity %} + {{ entity.name }} {% endblock %}
  • {% endfor %} diff --git a/backend/postings/templates/postings/collections/courses.html b/backend/postings/templates/postings/collections/courses.html index 4805231..0fc63cb 100644 --- a/backend/postings/templates/postings/collections/courses.html +++ b/backend/postings/templates/postings/collections/courses.html @@ -2,11 +2,10 @@ {# Represents a list of university entities. #} +{% block collection_name %} +

    Courses

    +{% endblock %} + {% block entity %} - {{ entity.name }}, University: {{ entity.taught_at_university.name}}
    -
      - {% for professor in entity.professors.all %} -
    • {{ professor.name }}
    • - {% endfor %} -
    +

    {{ entity.name }}

    {% 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 index 6f392e1..bb5374d 100644 --- a/backend/postings/templates/postings/collections/universities.html +++ b/backend/postings/templates/postings/collections/universities.html @@ -2,6 +2,10 @@ {# Represents a list of university entities. #} +{% block collection_name %} +

    Universities

    +{% endblock %} + {% block entity %} - {{ entity.name }} +

    {{ entity.name }}

    {% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/entity_pages/course.html b/backend/postings/templates/postings/entity_pages/course.html new file mode 100644 index 0000000..8508196 --- /dev/null +++ b/backend/postings/templates/postings/entity_pages/course.html @@ -0,0 +1,11 @@ +{% extends "postings/entity_pages/entity.html" %} + +{% block entity_info %} + Taught at: {{ entity.taught_at_university.name }} +

    Professors

    +
      + {% for professor in entity.professors.all %} +
    • {{ professor.name }}
    • + {% endfor %} +
    +{% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/entity_pages/entity.html b/backend/postings/templates/postings/entity_pages/entity.html new file mode 100644 index 0000000..b066368 --- /dev/null +++ b/backend/postings/templates/postings/entity_pages/entity.html @@ -0,0 +1,24 @@ +{% extends "postings/generic_page.html" %} + +{# Represents a single entity's detail page. #} + +{% block content %} + +

    Name: {{ entity.name }}

    + +{% block entity_info %} +{% endblock %} + +
    +

    Reviews

    +
      + {% for review in entity.review_set.all %} +
    • +

      {{ review.title }}

      {{ review.rating }} +

      {{ review.content }} +

    • + {% endfor %} +
    +
    + +{% endblock %} \ No newline at end of file diff --git a/backend/postings/templates/postings/entity_pages/university.html b/backend/postings/templates/postings/entity_pages/university.html new file mode 100644 index 0000000..0ea0b8c --- /dev/null +++ b/backend/postings/templates/postings/entity_pages/university.html @@ -0,0 +1,16 @@ +{% extends "postings/entity_pages/entity.html" %} + +{% block entity_info %} +

    Courses

    + +

    Professors

    +
      + {% for professor in entity.professor_set.all %} +
    • {{ professor.name }}
    • + {% endfor %} +
    +{% 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 index 9f8d23a..f49084f 100644 --- a/backend/postings/templates/postings/generic_page.html +++ b/backend/postings/templates/postings/generic_page.html @@ -10,9 +10,9 @@ -
    -

    RateMyCourse

    -
    +
    +

    RateMyCourse

    +
    {# All of a page's content to display should be placed in here. #}
    diff --git a/backend/postings/views.py b/backend/postings/views.py index 19b0baa..58288a1 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from django.http import HttpResponse +from django.http import HttpResponse, Http404 from postings.models import * # Create your views here. @@ -8,12 +8,30 @@ from postings.models import * def index(request): return render(request, 'postings/index.html') +# The view for a listing of universities. def universities(request): universities_list = University.objects.all() context = {'entities': universities_list} return render(request, 'postings/collections/universities.html', context) +# The view for /universities/ Displays one university entity. +def university_entity(request, university_id): + try: + university = University.objects.get(pk=university_id) + except University.DoesNotExist: + raise Http404("University does not exist") + return render(request, 'postings/entity_pages/university.html', {'entity': university}) + +# The view for a listing of courses. 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 + return render(request, 'postings/collections/courses.html', context) + +# The view for a specific course entity. +def course_entity(request, course_id): + try: + course = Course.objects.get(pk=course_id) + except Course.DoesNotExist: + raise Http404("Course does not exist") + return render(request, 'postings/entity_pages/course.html', {'entity': course}) \ No newline at end of file