Commit b4aaf490 authored by Raul Jarod Conanan's avatar Raul Jarod Conanan

Merge branch '4-Assignmentsv2' into 'dev'

4 assignmentsv2

See merge request !19
parents 510374f1 512f483b
......@@ -3,4 +3,4 @@ from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Assignments'
name = 'assignments'
from django.forms import ModelForm
from .models import Assignment
from django import forms
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = "__all__"
labels = {
'name': '',
'description': '',
'course': 'Course: ',
'perfect_score': '',
}
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Assignment Name'}),
'description': forms.Textarea(attrs={'class': 'form-control', 'placeholder': 'Description'}),
'course': forms.Select(attrs={'class': 'form-control', 'placeholder': 'Course'}),
'perfect_score': forms.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Perfect Score'}),
'passing_score': forms.HiddenInput(),
}
\ No newline at end of file
......@@ -7,13 +7,13 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0001_initial'),
('assignments', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='Assignments.course'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
from django.db import models
from django.urls import reverse
class Course(models.Model):
......@@ -6,6 +7,9 @@ class Course(models.Model):
title = models.CharField(max_length=255, blank=True, null=True)
section = models.CharField(max_length=3, blank=True, null=True)
def __str__(self):
return self.code + '-' + self.section
class Assignment(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
......@@ -17,3 +21,12 @@ class Assignment(models.Model):
def save(self, *args, **kwargs):
self.passing_score = int(self.perfect_score * 0.60)
super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('assignments:assignments-item', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('assignments:assignments-edit', kwargs={'pk': self.pk})
from django.urls import path
from .views import index
from .views import (
index, AssignmentDetailsView,
AddAssignmentView, EditAssignmentView
)
urlpatterns = [
path('', index, name='index'),
path('add/', AddAssignmentView.as_view(), name='assignments-add'),
path('<int:pk>/edit/', EditAssignmentView.as_view(), name='assignments-edit'),
path('<int:pk>/details/', AssignmentDetailsView.as_view(), name='assignments-item'),
]
app_name = "Assignments"
app_name = "assignments"
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Assignment
from .forms import AssignmentForm
class AssignmentDetailsView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AddAssignmentView(CreateView):
model = Assignment
form_class = AssignmentForm
template_name = 'assignments/assignment-add.html'
class EditAssignmentView(UpdateView):
model = Assignment
form_class = AssignmentForm
template_name = 'assignments/assignment-edit.html'
def index(request):
output = f"Widget's Assignments Page<br><br>"
count = Assignment.objects.all().count()
for i in range(1, count + 1):
assignments = Assignment.objects.get(id=i)
output += f"""Assignment Name: {assignments.name}<br>
Description: {assignments.description}<br>
Perfect Score: {assignments.perfect_score}<br>
Passing Score: {assignments.passing_score}<br>
Course/Section: {assignments.course.code} {assignments.course.title}-{assignments.course.section}<br>
<br>"""
return HttpResponse(output)
assignments = Assignment.objects.all()
context = {
'assignments': assignments
}
return render(request, 'assignments/assignments.html', context)
......@@ -25,7 +25,7 @@ def Dashboard_list_view(request):
html_string_3 = '<a href="/Widgetusers/add"><button value="click here" > Add Widget User</button></a><br><br>'
html_string_3 += '<a href="/announcements/">Announcement Board</a><br>'
html_string_3 += '<a href="/forum/">Forum</a><br>'
html_string_3 += '<a href="/Assignments">Assignment</a><br>'
html_string_3 += '<a href="/assignments">Assignment</a><br>'
html_string_3 += '<a href="/widget_Calendar/">Calendar</a><br>'
html_string_final = html_string_1 + html_string_2 + html_string_3 + '</html>'
......
{% extends 'base.html' %}
{% block content %}
<title>Add Assignment</title>
<h1>Add a new assignment:</h1>
<form action="" method=POST>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Assignment">
</form>
{% endblock content %}
{% extends 'base.html' %}
{% block content %}
<title>{{ assignment.name }}</title>
<h1>{{ assignment.name }}</h1>
<p>
{{ assignment.course.code }} {{ assignment.course.title }}-{{ assignment.course.section }} <br><br>
Description: {{ assignment.description }} <br>
Perfect Score: {{ assignment.perfect_score }} <br>
Passing Score: {{ assignment.passing_score }} <br>
</p>
<li>
<a href="{{ assignment.get_update_url }}">Edit Assignment</a>
</li>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<title>Edit Assignment</title>
<h1>Edit Assignment.</h1>
<form action="" method=POST>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Assignment">
</form>
{% endblock content %}
{% extends 'base.html' %}
{% block content %}
<title>Widget's Assignments</title>
<h1>Welcome to Widget's Assignments!</h1>
{% for assignment in assignments %}
<a href="{{ assignment.pk }}/details/">{{ assignment.name }}</a><br>
{% endfor %}
<br>
<a href="add/"><button value="click here">New Assignment</button></a><br><br>
<a href="/Dashboard/">Dashboard</a><br>
<a href="/announcements/">Announcements</a><br>
<a href="/forum/">Forum</a><br>
<a href="/widget_Calendar/">Calendar</a><br>
{% endblock content %}
......@@ -16,6 +16,6 @@
<a href="/Dashboard/">Dashboard</a><br>
<a href="/announcements/">Announcements</a><br>
<a href="/Assignments/">Assignments</a><br>
<a href="/assignments/">Assignments</a><br>
<a href="/widget_Calendar/">Calendar</a><br>
{% endblock content %}
\ No newline at end of file
......@@ -7,7 +7,7 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0002_alter_assignment_course'),
('assignments', '0002_alter_assignment_course'),
('widget_Calendar', '0002_event_location_delete_indexcard_event_location'),
]
......@@ -15,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='event',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='event', to='Assignments.course'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='event', to='assignments.course'),
),
]
from django.db import models
from Assignments.models import Course
from assignments.models import Course
MODE_TYPES = (
......
......@@ -38,7 +38,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'announcements',
'Assignments',
'assignments',
'forum.apps.ForumConfig',
'Dashboard.apps.DashboardConfig',
'django.contrib.admin',
......
......@@ -22,7 +22,7 @@ urlpatterns = [
path('widget_Calendar/', include('widget_Calendar.urls', namespace="widget_Calendar")),
path('', include('Dashboard.urls', namespace="Dashboard")),
path('admin/', admin.site.urls),
path('Assignments/', include('Assignments.urls', namespace="Assignments")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('', include(('forum.urls', 'forum'), namespace='forum')),
# path('Dashboard/', include('Dashboard.urls', namespace="Dashboard")),
]
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