Commit 9ec65c4d authored by Brescia Amandy's avatar Brescia Amandy

Merge branch 'assignmentsv2' into 'master'

Assignmentsv2

See merge request !6
parents f7b2fc0a 9bbbed5b
from django.db import models from django.db import models
from django.urls import reverse
class Course(models.Model): class Course(models.Model):
...@@ -23,3 +24,6 @@ class Assignment(models.Model): ...@@ -23,3 +24,6 @@ class Assignment(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block header %}Add a new assignment:{% endblock %}
{% block body %}
<form method="POST" enctype="multipart/form-data" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object.name }}{% endblock %}
{% block header %}{{ object.name }}{% endblock %}
{% block body %}
{{ object.course }} {{ object.course.title }} - {{ object.course.section }} <br/> <br/>
Description: {{ object.description }} <br/>
Perfect Score: {{ object.perfect_score}} <br/>
Passing Score: {{ object.passing_score }} <br/> <br/>
<button>
<a href="edit">Edit Assignment</a>
</button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block header %}Edit Assignment:{% endblock %}
{% block body %}
<form method="POST" enctype="multipart/form-data" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Assignments{% endblock %}
{% block header %}Welcome to Widget's Assignments{% endblock %}
{% block body %}
<ul>
{% for assignment in assignment_list %}
<li>
<a href="{{ assignment.pk }}/details">
{{ assignment.name }}
</a>
</li>
{% endfor %}
</ul>
<button>
<a href="add">New Assignment</a>
</button>
<br/>
<a href="/dashboard">Dashboard</a> <br/>
<a href="/forum/">Forum</a>
{% endblock %}
\ 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>" context = {}
for assignment, course in zip(Assignment.objects.all(), Course.objects.all()): context["assignment_list"] = Assignment.objects.all()
return_string += 'Assignment: {}<br>'.format(assignment.name) return render(request, 'assignments/assignments.html', context)
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',
]
No preview for this file type
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<h1>{% block header %}{% endblock %}</h1>
{% block body %}{% endblock %}
</body>
</html>
\ No newline at end of file
...@@ -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