RateMyCourse/backend/postings/views.py

37 lines
1.3 KiB
Python
Raw Normal View History

2018-09-16 16:52:23 +00:00
from django.shortcuts import render
2018-10-02 12:06:53 +00:00
from django.http import HttpResponse, Http404
2018-10-02 09:56:04 +00:00
from postings.models import *
2018-09-16 16:52:23 +00:00
# Create your views here.
2018-10-02 09:56:04 +00:00
# The view for the homepage, or index.html
def index(request):
return render(request, 'postings/index.html')
2018-10-02 12:06:53 +00:00
# The view for a listing of universities.
2018-10-02 09:56:04 +00:00
def universities(request):
universities_list = University.objects.all()
context = {'entities': universities_list}
return render(request, 'postings/collections/universities.html', context)
2018-10-02 12:06:53 +00:00
# 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.
2018-10-02 09:56:04 +00:00
def courses(request):
courses_list = Course.objects.all()
context = {'entities': courses_list}
2018-10-02 12:06:53 +00:00
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})