Added templates for all basic things.

This commit is contained in:
Andrew Lalis 2018-10-02 14:06:53 +02:00
parent e22ae60e92
commit 714f3241ce
10 changed files with 94 additions and 12 deletions

View File

@ -27,9 +27,15 @@ urlpatterns = [
# /universities routes to a list of universities. # /universities routes to a list of universities.
path('universities', views.universities, name='universities_list'), path('universities', views.universities, name='universities_list'),
# /universities/<pk> routes to a specific university.
path('universities/<int:university_id>', views.university_entity, name='university entity'),
# /courses routes to a list of courses. # /courses routes to a list of courses.
path('courses', views.courses, name='courses_list'), path('courses', views.courses, name='courses_list'),
# /courses/<pk> routes to a specific course.
path('courses/<int:course_id>', views.course_entity, name='course entity'),
# static files (*.css, *.js, *.jpg etc.) served on / # static files (*.css, *.js, *.jpg etc.) served on /
# (assuming Django uses /static/ and /media/ for static/media urls) # (assuming Django uses /static/ and /media/ for static/media urls)
url(r'^(?!/?static/)(?!/?media/)(?P<path>.*\..*)$', url(r'^(?!/?static/)(?!/?media/)(?P<path>.*\..*)$',

Binary file not shown.

View File

@ -4,10 +4,14 @@
{% block content %} {% block content %}
{% block collection_name %}
{% endblock %}
<ul> <ul>
{% for entity in entities %} {% for entity in entities %}
<li> <li>
{% block entity %} {% block entity %}
{{ entity.name }}
{% endblock %} {% endblock %}
</li> </li>
{% endfor %} {% endfor %}

View File

@ -2,11 +2,10 @@
{# Represents a list of university entities. #} {# Represents a list of university entities. #}
{% block collection_name %}
<h2>Courses</h2>
{% endblock %}
{% block entity %} {% block entity %}
<b>{{ entity.name }}</b>, University:<i> {{ entity.taught_at_university.name}}</i><br> <h3><a href="/courses/{{ entity.pk }}">{{ entity.name }}</a></h3>
<ul>
{% for professor in entity.professors.all %}
<li>{{ professor.name }}</li>
{% endfor %}
</ul>
{% endblock %} {% endblock %}

View File

@ -2,6 +2,10 @@
{# Represents a list of university entities. #} {# Represents a list of university entities. #}
{% block collection_name %}
<h2>Universities</h2>
{% endblock %}
{% block entity %} {% block entity %}
<b>{{ entity.name }}</b> <h3><a href="/universities/{{ entity.pk }}">{{ entity.name }}</a></h3>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,11 @@
{% extends "postings/entity_pages/entity.html" %}
{% block entity_info %}
Taught at: <a href="/universities/{{ entity.taught_at_university.pk }}">{{ entity.taught_at_university.name }}</a>
<h4>Professors</h4>
<ul>
{% for professor in entity.professors.all %}
<li>{{ professor.name }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -0,0 +1,24 @@
{% extends "postings/generic_page.html" %}
{# Represents a single entity's detail page. #}
{% block content %}
<h2>Name: {{ entity.name }}</h2>
{% block entity_info %}
{% endblock %}
<section>
<h3>Reviews</h3>
<ul>
{% for review in entity.review_set.all %}
<li>
<h4>{{ review.title }}</h4> {{ review.rating }}
<p>{{ review.content }}
</li>
{% endfor %}
</ul>
</section>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "postings/entity_pages/entity.html" %}
{% block entity_info %}
<h4>Courses</h4>
<ul>
{% for course in entity.course_set.all %}
<li><a href="/courses/{{ course.pk }}">{{ course.name }}</a></li>
{% endfor %}
</ul>
<h4>Professors</h4>
<ul>
{% for professor in entity.professor_set.all %}
<li>{{ professor.name }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -10,9 +10,9 @@
</head> </head>
<body> <body>
<div style="width: 100%; text-align: center; background-color: gray;"> <header>
<h1>RateMyCourse</h1> <h1><a href="/">RateMyCourse</a></h1>
</div> </header>
{# All of a page's content to display should be placed in here. #} {# All of a page's content to display should be placed in here. #}
<div id="content"> <div id="content">

View File

@ -1,5 +1,5 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse, Http404
from postings.models import * from postings.models import *
# Create your views here. # Create your views here.
@ -8,12 +8,30 @@ from postings.models import *
def index(request): def index(request):
return render(request, 'postings/index.html') return render(request, 'postings/index.html')
# The view for a listing of universities.
def universities(request): def universities(request):
universities_list = University.objects.all() universities_list = University.objects.all()
context = {'entities': universities_list} context = {'entities': universities_list}
return render(request, 'postings/collections/universities.html', context) return render(request, 'postings/collections/universities.html', context)
# The view for /universities/<pk> 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): def courses(request):
courses_list = Course.objects.all() courses_list = Course.objects.all()
context = {'entities': courses_list} context = {'entities': courses_list}
return render(request, 'postings/collections/courses.html', context) 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})