Commit 585c0b73 authored by Jonathan Talbot's avatar Jonathan Talbot

assignments-lab3

parent 30ae1dca
......@@ -16,7 +16,7 @@ class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
def get_absolute_url(self):
return reverse('assignment', args=[(self.full_assignment)])
return reverse('assignment-detail', args=[(self.pk)])
@property
def full_assignment(self):
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assignment List</title>
</head>
<body>
<h1>Assignments Per Course</h1>
{% for course in courses %}
<ul>
<li>{{ course.course_code }} {{ course.course_title }} {{ course.section }}
<ul>
{% for assignment in assignments %}
{%if assignment.course == course%}
<li><a href="{{assignment.get_absolute_url}}">{{assignment.name}}</a></li>
{%endif%}
{% endfor %}
</ul>
</li>
</ul>
{% endfor %}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assignment Detail</title>
</head>
<body>
<p>{{assignment.name}}</p>
<p>{{assignment.description}}</p>
<p>Max Points: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p>
<p>{{assignment.course}}</p>
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import assignments
from .views import AssignmentListView, AssignmentDetailView
urlpatterns = [
path('', assignments, name='Assignments')
path('', AssignmentListView.as_view(), name='assignment-list'),
path('<int:pk>/details', AssignmentDetailView, name='assignment-detail'),
]
\ No newline at end of file
from django.http import HttpResponse
from ast import Assign
from django.shortcuts import render, get_object_or_404
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Assignment, Course
def assignments(request):
# def assignments(request):
# assignments = Assignment.objects.all()
# courses = Course.objects.all()
# output = "ASSIGNMENTS:\n" + "\n".join(
# ['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
# .format(str(assignment.name),
# str(assignment.description),
# str(assignment.max_points),
# str(assignment.passing_score),
# str(assignment.course))
# for assignment in assignments]
# )
# return HttpResponse(output, content_type = "text/plain")
class AssignmentListView(View):
def get(self, request):
assignments = Assignment.objects.all()
courses = Course.objects.all()
output = "ASSIGNMENTS:\n" + "\n".join(
['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
.format(str(assignment.name),
str(assignment.description),
str(assignment.max_points),
str(assignment.passing_score),
str(assignment.course))
for assignment in assignments]
)
return HttpResponse(output, content_type = "text/plain")
context = {
'assignments': assignments,
'courses' : courses
}
return render(request, 'assignments/assignment_list.html', context)
def AssignmentDetailView(request, pk):
assignment = get_object_or_404(Assignment, pk=pk)
return render(request, 'assignments/assignments_detail.html', {
'assignment': assignment
})
# class AssignmentListView(ListView):
# model = Assignment
No preview for this file type
from django import forms
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Widget User</title>
</head>
<body>
<h1>Add Widget User</h1>
</body>
</html>
\ No newline at end of file
......@@ -11,5 +11,7 @@
{% for user in object_list %}
<a href="{{ user.get_absolute_url }}"> {{ user.last_name }}, {{user.first_name}} {{user.middle_name}} </a> <br>
{% endfor %}
<a href="/users/add">test</a>
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import homepage, UserDetailView, UserListView
# urlpatterns = [
# path('', homepage, name='homepage')
# ]
urlpatterns = [
path('', UserListView.as_view(), name='widget_user-list'),
......
......@@ -4,25 +4,6 @@ from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import WidgetUser, Department
# def homepage(request):
# widget_users = WidgetUser.objects.all()
# # output = "WIDGET USERS:\n" + "\n".join(
# # ['{}, {} {}: {}, {}, {}'.format(str(user.last_name),
# # str(user.first_name),
# # str(user.middle_name),
# # str(user.id_num),
# # str(user.email),
# # str(user.department))
# # for user in widget_users]
# # )
# context = {
# 'widget_users': widget_users,
# }
# # return HttpResponse(output, content_type="text/plain")
# return render(request, 'homepage/homepage.html', context)
class homepage(View):
def get(self, request):
widget_users = WidgetUser.objects.all()
......@@ -31,11 +12,6 @@ class homepage(View):
}
return render(request, 'homepage/homepage.html', context)
# class UserDetailView(DetailView):
# model = WidgetUser
# With this configuration, the default template this renders
# is called user_detail.html
def UserDetailView(request, pk):
user = get_object_or_404(WidgetUser, pk=pk)
return render(request, 'homepage/widgetuser_detail.html', {
......@@ -44,5 +20,3 @@ def UserDetailView(request, pk):
class UserListView(ListView):
model = WidgetUser
\ No newline at end of file
# With this configuration, the default template this renders
# is called user_list.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