Commit af90e4c6 authored by Brescia Amandy's avatar Brescia Amandy

Created the new views and linked them to a URL

parent 7ee2e782
assignment-add.html
\ No newline at end of file
assignment-details.html
\ No newline at end of file
assignment-edit.html
\ No newline at end of file
Assignments.html
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import assignments from .views import assignments
from .views import AssignmentDetails, AssignmentAdd, AssignmentEdit
urlpatterns = [ urlpatterns = [
path('', assignments, name='assignments'), path('', assignments, name='assignments'),
path('<pk>/details', AssignmentDetails.as_view(), name='assignment-details'),
path('add', AssignmentAdd.as_view(), name='assignment-add'),
path('<pk>/edit', AssignmentEdit.as_view(), name='assignment-edit'),
] ]
# This might be needed depending on your Django version # This might be needed depending on your Django version
......
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Assignment, Course from .models import Assignment, Course
def assignments(request): def assignments(request):
return_string = "Widget's Assignments Page<br><br>" return render(request, 'assignments/assignments.html')
for assignment, course in zip(Assignment.objects.all(), Course.objects.all()):
return_string += 'Assignment: {}<br>'.format(assignment.name)
return_string += 'Description: {}<br>'.format(assignment.description)
return_string += 'Perfect Score: {}<br>'.format(assignment.perfect_score)
return_string += 'Passing Score: {}<br>'.format(assignment.passing_score)
return_string += 'Course/Section: {} {}-{}<br><br>'.format(
course.code, course.title, course.section)
return HttpResponse(return_string) class AssignmentDetails(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentAdd(CreateView):
model = Assignment
template_name = 'assignments/assignment-add.html'
fields = [
'name',
'description',
'course',
'perfect_score',
]
class AssignmentEdit(UpdateView):
model = Assignment
template_name = 'assignments/assignment-edit.html'
fields = [
'name',
'description',
'course',
'perfect_score',
]
...@@ -61,7 +61,7 @@ ROOT_URLCONF = 'widget_huli.urls' ...@@ -61,7 +61,7 @@ ROOT_URLCONF = 'widget_huli.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
...@@ -20,7 +20,6 @@ from django.urls import include, path ...@@ -20,7 +20,6 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('forum/', include(('forum.urls', 'forum'), namespace="forum" )), path('forum/', include(('forum.urls', 'forum'), namespace="forum" )),
path('assignments/', include(('assignments.urls', 'assignments'), namespace="assignments")), path('assignments/', include(('assignments.urls', 'assignments'), namespace="assignments")),
path('Announcement_Board/', include(('Announcement_Board.urls', 'Announcement_Board'), namespace="Announcement_Board")),
path('dashboard', include(('dashboard.urls', 'dashboard'), namespace="dashboard")), path('dashboard', include(('dashboard.urls', 'dashboard'), namespace="dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment