From e22ae60e925a7a63c7d65a5102d34821904685f4 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 11:56:04 +0200 Subject: [PATCH 1/5] 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 From 714f3241ceb291625d8003248c82cc8b448c3392 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 14:06:53 +0200 Subject: [PATCH 2/5] 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 From ed92b5d3e189cdc634048e1ba7b4cd6a31d11dcd Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 14:48:26 +0200 Subject: [PATCH 3/5] Added basic search function. --- backend/RateMyCourse/urls.py | 3 ++ .../postings/templates/postings/index.html | 30 +++++++++++++------ backend/postings/views.py | 8 ++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index cc3e5cb..581fd0f 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -24,6 +24,9 @@ urlpatterns = [ # / routes to index.html path('', views.index, name='homepage'), + # /?search_query=xxx routes to the homepage, with displaying some basic results. + path(' - Click one of the links below to view a list of all those entities. -

      -
        -
      • + {# First section for searching our database. #} +
        +
        + + +
        +
      • -
      • Courses -
      • -
      + + + + {# Second section for displaying results, or whatever should be shown first. #} + {% if results %} +
      +
        + {% for entity in results %} +
      • {{ entity.name }}
      • + {% endfor %} +
      +
      + {% endif %} + {% endblock %} \ No newline at end of file diff --git a/backend/postings/views.py b/backend/postings/views.py index 58288a1..61c25b9 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -5,8 +5,14 @@ from postings.models import * # Create your views here. # The view for the homepage, or index.html +# There is an optional 'search_query GET parameter, which, if provided, gives the template a 'results' variable. def index(request): - return render(request, 'postings/index.html') + search_query = request.GET.get('search_query', None) + results = None + if search_query: + results = RateableEntity.objects.filter(name__icontains=search_query) + + return render(request, 'postings/index.html', {'results': results}) # The view for a listing of universities. def universities(request): From 8a9c51e856b4fc87dd595bd3bf7066c6ba341ccc Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 2 Oct 2018 16:27:29 +0200 Subject: [PATCH 4/5] Added average rating. --- backend/db.sqlite3 | Bin 73728 -> 77824 bytes backend/postings/admin.py | 3 +- .../migrations/0002_auto_20181002_1338.py | 19 ++++++++++++ .../migrations/0003_auto_20181002_1355.py | 25 +++++++++++++++ backend/postings/models.py | 29 ++++++++++++++++-- .../postings/entity_pages/entity.html | 2 +- backend/postings/views.py | 1 + 7 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 backend/postings/migrations/0002_auto_20181002_1338.py create mode 100644 backend/postings/migrations/0003_auto_20181002_1355.py diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index facb5032d3814e7c0fb359ec500d5e60b716b68e..ae677ce941400f5703b6f0150e516df40ddb6bc3 100644 GIT binary patch delta 3924 zcmai1Yiu0V6~6bLncW>bZnB9J2ZzLilPC?2H}l+GJ59>q#LhZiJMkmVx&pKIj=kgE zopJUNKPXzvpX0NV#I)vX~g zfT}27>9ffX8n%D^TJ4Rb8lVv;#^UCvH5gB140AATjaF`03A?b3&(&=AQm$u_|Ei|@ ze@!(sELh6w#|(Xf*k{85V$jQ?T^biL^I0oV7|zo@;qw-M zFgcYohI3`Kg3VGe5EjEhRg^s}k~Q38Wci-FKAzM~et&!-MNfN~jvxgTDJTXd5@lIr zXk52`v|wcQjBe(OIewoxYM8p7rK&vT&G%R%`H6T|r?~NKzA#=+LUH#-2rG)ZgJIED z4Y$Wlz9*hO7Ef5&GV4mS6bgi;a9EK^2w1dR^Yxj=F+H0z@>9GuQsi6WX=B97nnrw? zsvrjxSq({wKv=X>^L0(qg$aHEpiIL#xPTB;R7GjVENanw-NsldSGa0WH}ZU2)-tK5 zx>?e#ovy-FL>3KANLc5(Y5mJN;FLp;n$p@ELpz@56uKO={z>@Mm}l zeh<%6D?f*N1~^>lhzdt=j_^6c>j;k{?8|NIYb(*)2%dm3s3U(Q-y!?(75qzVVHLe? z`I|U%9hBo=E74`ey#l zyY9M;gex4FwbzD`0!?aA5<^l?+(<0dEZzqDxa%uiu*$~RGxWl?Rh3fY`Ke?)5e26^{04ve~#P|>YvrBsw< zwMkMAW~~uDm$S0-P)a$JCjt&sXerbjlAD>quqew5$v6)smqQhO5pq4OxttA(;U?)C zSj&RY7s1zuax*v_Y!bvJQ0q$py)2x3r@w_)t;A2!OFD*747%uF8%>zVZ0!3Zn4x9; zUYdpX;MuMRpJ03hE+BXvF3_R#@TJv+L2GYvVtpZ_YN^iFn-)jk!klwU5O^QKC-6Q+ z_$O@gGMLr~LRf~TCF5Mjgj687nN;8}qwmr+pWxYw$3CIu0gOW zJp})S_bA>!pw2_7J6pz5PP7(QK|Ny72}Cs9icUa~;udC4y!H^;P`%Jml-_3A+PyUy z4bNokLx1D#J3jsqHT*7uEATFbejRQsL3=$O2O6`bxH)tdVB{eLlK}B>%?H@dPbG6fME}p38 zyE^Tar}!0f6ZP9?_Vm~tkM>}{{m`Q+?r68SM$_=|jD5$MYMVb*X}|eEEf(!t9;>ly zPyNcitGM0X{R(G4a`tBX^E&ns<_fcdfpyOPd_Nq9b(EtAihEYGXyY#JYST;mL3xn2 zo7SL{g`yxxgQBde3n}T;GF5F>#efo0l(4+VU#>4L)0e|b_2qE05Ddr^HH^dd{hym2 zOrAmH8OrEMQvBL3%tnv1T6laqDd#h}cqo_*heTZ*jVtN6EG4s3!nBY|M|-w0n2adFl#4@d8ap`bjpd}KFWV(w-WBsZ*G^LIWNvbfMNgExRRx!~wT9{wBKU(PR zZ%PgHPqxJRJF^4*YARw(7)K;$U2-IGq%%F7Zn9!WI<3f(mcV{Q zEe03$-c2Dzm7EyH@G62=>3;qJ8aG3f`+s{`(z%4d_J8o=EYJ90(?-zd`<~@SezF2r z&-(dyz~-6tRhXKL&_|$8fLgr_Cl%I9K1J|N@+tlP4k^xXv`*t~Gpwd@nAxij(>|Kd z4JR!t9pUpy!%R6cH#fx7xACl=r|oXSUAluGD&+Zed^qJySoF6LKVn&lz|z3F+L_6r z@{lVoOob#`NH~NW2PqYf^g33@DYDMz3KZV`ULxkO$XgblFzBT}8aIt;TH>8(7VWAtvzB&iN=Oa6Wdgm7$OfE3FWY|RIha}9Z=Zj1xBbAmI-5Tegqg;} zcF(z18=tAOt#cdfi{~0EzCP6Ft!Ze$-?)<|`(}K=P4WlNykcKCYueV?8e1u@x|-~G G`~Lts9O>8q delta 722 zcmY*WQAm?f6u##_S2x_6`yEbjq$3xU^Vdop3aR}T+A3&KghDV^PFuK5H9*)3>Shk*K{0_s!&&KACe zwX_r&Da0;{ARHyiTFp-8+PUHJFW|Ik!(iTpZDQ>#f%9Y*J-9B`KF4^; z5$$UYv}jWbRBDY1xQfR5+H_@3C)`GDZ!J`@54j38{(0XAYwsusR9tsoU5 z&%{|z()*~eYXT@Q__T$bp4!xz_K4#XL{g!HB+w;Z#du=wfdt=0`7M1xGMmGsfMf}} zq!G9-9U@uLSmfE|yC4z5hO%#q;+-dSWkD6Name: {{ entity.name }} +

      Name: {{ entity.name }}

      Average rating: {{ entity.average_rating }} {% block entity_info %} {% endblock %} diff --git a/backend/postings/views.py b/backend/postings/views.py index 61c25b9..d8ae6df 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -24,6 +24,7 @@ def universities(request): def university_entity(request, university_id): try: university = University.objects.get(pk=university_id) + university.average_rating = university.getAverageRating() except University.DoesNotExist: raise Http404("University does not exist") return render(request, 'postings/entity_pages/university.html', {'entity': university}) From fa67dc6c3478a2ffbbd16835498e392a564b088c Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Wed, 3 Oct 2018 22:00:08 +0200 Subject: [PATCH 5/5] Added a form object and the ability to write reviews. Only needs styling now. --- backend/RateMyCourse/urls.py | 3 ++ backend/db.sqlite3 | Bin 77824 -> 77824 bytes backend/postings/forms.py | 12 ++++++ backend/postings/models.py | 2 + .../postings/entity_pages/entity.html | 28 +++++++++++++- backend/postings/views.py | 35 +++++++++++++++++- 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 backend/postings/forms.py diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index cc3e5cb..00a147e 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -24,6 +24,9 @@ urlpatterns = [ # / routes to index.html path('', views.index, name='homepage'), + # /reviews routes to the endpoint for POSTing new reviews. + path('reviews', views.post_review, name='post_review'), + # /universities routes to a list of universities. path('universities', views.universities, name='universities_list'), diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index ae677ce941400f5703b6f0150e516df40ddb6bc3..823e9728193627bbd30a3deb9a2ae0eb65b50980 100644 GIT binary patch delta 735 zcmZvZzi-n(6vurz+fo_{rGljbsc$Pnt;sn*YG;c&Kr(^g55S49^(l_8@|_!HN-QC< zg8COA7FHBhu<;kb-_Uk|rAryg&<;G87D0-1`kwCnxc7PQ%?{1kq51kQ>AktPMS34z ztX7CUpH*JIuiEs;pcnKf{XviDH+nK(HowrSNz25xC?O@QP;3A6(d~EUClkYu4SGsX z=y!UIX=fPzmEJL_LF_`TLd-(w{Ot3ssA?Mr27OgJFOA3rd1@T&FPm?t`HH<{kk$NQ zr&Bhp$DGFy^K2-FuqTobLZKl`#2!zT&>SDpb;LT1f*=J99CNNA5h!D{$WdVn0}Ugd zh-3#d`i|qcHRf%w+D5Go%x^dA?Z&3#`n9R=HUIBoHP+1UTL`z6uXQ@au%1Uk0UjN3 z=yUZK*rb=?v(E=XrZ~h>E0Ei;9gJkAV3*6?n1j+;D0qlCDPPAw5D@>Gj-v^5Ar?ap z*j-R0FR(WJwu`JDbA9(;)IXlO>z1ThHptqug4BGHa;+zzB7xT>_8<Name: {{ entity.name }} Average rating: {{ entity.average_rating }} +

      Name: {{ entity.name }}

      Average rating: {{ entity.average_rating|floatformat:"-2" }} +{# Child templates can redefine this block for displaying data pertaining to that specific entity. #} {% block entity_info %} {% endblock %} +{# This section displays all reviews for a given entity. #}

      Reviews

        @@ -21,4 +23,28 @@
      +{# This section is where the user can write a review for a particular entity and submit it. #} +
      +

      Write a Review

      +
      + + +
      + + + +
      + + + +
      + + {# The following csrf_token and input fields are hidden values needed for form submission. #} + {% csrf_token %} + + + +
      +
      + {% endblock %} \ No newline at end of file diff --git a/backend/postings/views.py b/backend/postings/views.py index d8ae6df..4eb60cb 100644 --- a/backend/postings/views.py +++ b/backend/postings/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render -from django.http import HttpResponse, Http404 +from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseRedirect from postings.models import * +from postings.forms import * # Create your views here. @@ -41,4 +42,34 @@ def course_entity(request, course_id): 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 + return render(request, 'postings/entity_pages/course.html', {'entity': course}) + +# The view for receiving POST requests for new reviews. +def post_review(request): + if request.method == 'POST': + form = EntityReviewForm(request.POST) + if form.is_valid(): + # Only if the request is a POST and the form is valid do we do anything. + rating = form.cleaned_data['rating'] + title = form.cleaned_data['title'] + content = form.cleaned_data['content'] + entity_id = form.cleaned_data['entity_id'] + entity = RateableEntity.objects.get(pk=entity_id) + + # Creates the new Review object from the posted data. + review = Review.objects.create( + rating=rating, + title=title, + content=content, + rateable_entity=entity + ) + + # Send the user back to the entity they were viewing. + redirect_path = '/' + if entity.entity_type == RateableEntity.UNIVERSITY: + redirect_path = '/universities/' + str(entity_id) + elif entity.entity_type == RateableEntity.COURSE: + redirect_path = '/courses/' + str(entity_id) + return HttpResponseRedirect(redirect_path) + + return HttpResponseBadRequest("Bad Request") \ No newline at end of file