Commit 4b598ba0 authored by Neal Luigi D. Rodriguez's avatar Neal Luigi D. Rodriguez

Merge branch 'Assignmentsv2'

parents f92324d6 0182df76
from django import forms
from .models import Course, Assignment
class CourseForm(forms.ModelForm):
class meta:
model = Course
fields = ['code', 'title',
'section']
class AssignmentForm(forms.ModelForm):
class meta:
model = Assignment
fields = ['name', 'description',
'course', 'perfect_score']
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -17,6 +18,12 @@ class Assignment(models.Model): ...@@ -17,6 +18,12 @@ class Assignment(models.Model):
on_delete=models.PROTECT, on_delete=models.PROTECT,
) )
perfect_score = models.IntegerField() perfect_score = models.IntegerField()
def get_absolute_url(self):
return reverse('Assignments:assignment-details', kwargs={'pk': self.pk})
def get_course_details(self):
return '{} {}-{}'.format(self.course.code, self.course.title, self.course.section)
@property @property
def passing_score(self): def passing_score(self):
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Assignment {% endblock %}
{% block content %}
<h1>Add a New Assignment</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.name }}{% endblock %}
{% block content %}
<h1>{{ object.name }}</h1>
<h2>{{ object.get_course_details }}</h2>
<ul>
<li>Description: {{ object.description }}</li>
<li>Perfect Score: {{ object.perfect_score }}</li>
<li>Passing Score: {{ object.passing_score }}</li>
</ul>
<button onclick="window.location.href='../../../Assignments/{{object.id}}/edit/';">
Edit Assignment
</button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Assignment {% endblock %}
{% block content %}
<h1>Edit Assignment</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Assignments {% endblock %}
{% block content %}
<h1>Welcome to Widget's Assignments </h1>
<ul>
{% for object in assignments %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
</li>
{% endfor %}
</ul>
<button onclick="window.location.href='../../Assignments/add/';">
New Assignment
</button>
<p>
<a href="http://127.0.0.1:8000/Dashboard/">Dashboard</a><br>
<a href="http://127.0.0.1:8000/Announcement/">Announcements</a><br>
<a href="http://127.0.0.1:8000/Forum/">Forum</a><br>
<a href="http://127.0.0.1:8000/Calendar/">Calendar</a>
</p>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import (AssignmentView,
AssignmentsDetailView, AssignmentsCreateView,
AssignmentsUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name="index") path('assignments/', AssignmentView, name="index"),
path('<pk>/details/', AssignmentsDetailView.as_view(), name='assignment-details'),
path('add/', AssignmentsCreateView.as_view(), name='assignment-add'),
path('<pk>/edit/', AssignmentsUpdateView.as_view(), name='assignment-edit')
] ]
app_name = "Assignments" app_name = "Assignments"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse 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
# Create your views here. # Create your views here.
def index(request): def AssignmentView(request):
head_string = "<h1>Widget's Assignment Page</h1>" assignments = Assignment.objects.all()
body_string = "" context = {'assignments': assignments}
for assignment in Assignment.objects.all(): return render(request, 'Assignments/assignments.html', context)
body_string += '<p>Assignment Name: {}</br>'.format(assignment.name)
body_string += 'Description: {}</br>'.format(assignment.description) class AssignmentsDetailView(DetailView):
body_string += 'Perfect Score: {}</br>'.format(assignment.perfect_score) model = Assignment
body_string += 'Passing Score: {}</br>'.format(assignment.passing_score) template_name = 'Assignments/assignment-details.html'
body_string += 'Course/Section: {} {}-{}</br>'.format(assignment.course.code, assignment.course.title, assignment.course.section)
body_string += "</p>" class AssignmentsCreateView(CreateView):
html_string = '<html><head>{}</head><body>{}</body></html>'.format(head_string, body_string) model = Assignment
fields = '__all__'
template_name = 'Assignments/assignment-add.html'
return HttpResponse(html_string) class AssignmentsUpdateView(UpdateView):
\ No newline at end of file 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