Commit 385eee3d authored by Ciella's avatar Ciella

Created views and updated URLs

parent 98014e12
from django.urls import path
from .views import index
from .views import assignments_view, AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView
urlpatterns = [
path('', index, name='index'),
path('assignments/', assignments_view, name='assignments_view'),
path('assignments/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('assignments/add/', AssignmentCreateView.as_view(), name='assignment-add'),
path('assignments/<int:pk>/edit/', AssignmentUpdateView.as_view(), name='assignment-edit'),
]
app_name = 'assignments'
\ No newline at end of file
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
# Create your views here.
def index(request):
return_string = '<p>Widget\'s Assignments Page<br>'
for work in Assignment.objects.all():
work_string = '<br>Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {}-{}<br>'.format(
work.name, work.description, work.perfect_score, work.passing_score, work.course.code, work.course.title, work.course.section)
return_string += work_string
def assignments_view(request):
tasks = Assignment.objects.all()
context = {'tasks' : tasks}
return render(request, 'assignments/assignments.html')
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
class AssignmentUpdateView(UpdateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-edit.html'
\ No newline at end of file
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