Commit 45a09d38 authored by Raul Jarod Conanan's avatar Raul Jarod Conanan

Merge branch 'dev' into 'master'

Dev

See merge request !22
parents a8941716 a939c3d1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (midterm_robo_mommy)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -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)
# Generated by Django 3.2 on 2023-05-11 11:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_widgetuser'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='department', to='Dashboard.department'),
),
]
......@@ -16,12 +16,8 @@ class WidgetUser(models.Model):
last_name = models.CharField(max_length=50)
department = models.ForeignKey(Department, related_name="department", on_delete=models.CASCADE)
def get_absolute_url(self):
return reverse('widgetuser-detail', kwargs={'pk': self.pk})
def __str__(self) -> str:
return str(self.last_name + ', ' + self.first_name)
def get_absolute_url(self):
return reverse('widgetuser-add', kwargs={'pk': self.pk})
\ No newline at end of file
return reverse('widgetuser-detail', kwargs={'pk': self.pk})
......@@ -10,7 +10,6 @@ urlpatterns = [
name='widgetuser-add'),
path('Widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(),
name='widgetuser-edit')
]
app_name = "Dashboard"
import string
from .models import WidgetUser, Department
from .models import WidgetUser
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views import generic
from django.urls import reverse
......@@ -16,30 +12,31 @@ def Dashboard_list_view(request):
for wu in WidgetUser.objects.all():
number = str(wu.pk)
href = '<a href="/Widgetusers/' + number + '/details">'
html_string_2 += '<li>' + href + '{}, {} {}: {}, {}' .format(wu.last_name,
html_string_2 += '<li>' + href + '{}, {} {}: {}, {}' .format(
wu.last_name,
wu.first_name,
wu.middle_name,
wu.department.dept_name,
wu.department.home_unit)
wu.department.home_unit
)
html_string_2 += '</ul></li>'
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="/Calendar/">Calendar</a><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="/widget_Calendar/">Calendar</a><br>'
html_string_final = html_string_1 + html_string_2 + html_string_3 + '</html>'
return HttpResponse(html_string_final)
class WidgetUserDetailView(generic.DetailView):
model = WidgetUser
template_name = 'widgetuser-details.html'
queryset = WidgetUser.objects.all()
context_object_name = 'widgetuser-detail'
class WidgetUserAddView(generic.CreateView):
model = WidgetUser
fields = '__all__'
......@@ -59,4 +56,3 @@ class WidgetUserUpdateView(generic.UpdateView):
def get_success_url(self):
return reverse('Dashboard:widgetuser-detail', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
\ No newline at end of file
# Generated by Django 3.2 on 2023-05-13 14:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='react', to='announcements.announcement'),
),
]
......@@ -19,6 +19,6 @@ class Reaction(models.Model):
name = models.CharField(max_length=5, default=LIKE, null=True, blank=True)
tally = models.IntegerField(default=0 ,null=True, blank=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True)
announcement = models.ForeignKey(Announcement, related_name="react", on_delete=models.CASCADE, null=True)
# Create your models here.
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Add Announcement</title>
<h1>Add a new announcement:</h1>
<form action="" method=POST>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Announcement">
</form>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>{{ announce.title }}</title>
<h1>{{ announce.title }}</h1>
<h2>by {{ announce.author.first_name }} {{ announce.author.last_name }}</h2>
<p>{{ announce.pub_datetime|date:'m/d/Y, h:i A' }}</p>
<p>{{ announce.body }}</p>
<p>
{% for react in announce.react.all %}
{{ react.name }}: {{ react.tally }}<br>
{% endfor %}
</p>
<a href = "/announcements/{{ announce.pk }}/edit/"><button value="">Edit Announcement</button></a>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Edit Announcement</title>
<h1>Edit announcement:</h1>
<form action="" method=POST>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Widget's Announcement Board</title>
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>Announcements:</h3>
{% for announce in announcement %}
<a href = "{{ announce.pk }}/details/">{{ announce.title }} by {{ announce.author.first_name }} {{ announce.author.last_name }}</a><br>
{% endfor %} <br>
<a href="add/"><button value="click here">Add Announcement</button></a><br><br>
<a href = "/Dashboard/">Dashboard</a><br>
<a href = "/forum/">Forum</a><br>
<a href = "/assignments/">Assignments</a><br>
<a href = "/widget_Calendar/">Calendar</a>
{% endblock content %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, AnnouncementDetailView, AnnouncementAddView, AnnouncementEditView
urlpatterns = [
path('', index, name='index'),
path('announcements/', index, name='index'),
path('announcements/<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcementdetailview'),
path('announcements/add/', AnnouncementAddView.as_view(), name='announcement-add'),
path('announcements/<int:pk>/edit/', AnnouncementEditView.as_view(), name='announcement-edit'),
]
app_name = "announcements"
\ 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 django.urls import reverse
from .models import Announcement, Reaction
import pytz
from django.utils import timezone
def convert_to_localtime(utctime):
format = '%d/%m/%Y %I:%M %p'
format = '%m/%d/%Y %I:%M %p'
utc = utctime.replace(tzinfo=pytz.UTC)
localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(format)
def index(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"></head>\
<b><h1>Widget\'s Announcement Board</h1></b>\
<h2>Announcements:</h2><br/>'
html_string_2 = ""
for announced in Announcement.objects.all():
html_string_2 += "{} by {} {} published {}:<br />\
{}<br/>".format(announced.title, announced.author.first_name,
announced.author.last_name,
convert_to_localtime(announced.pub_datetime), announced.body)
for reacts in announced.reaction_set.all():
html_string_2 += "{}: {}<br/>".format(reacts.name, reacts.tally)
html_string_2 += '<br/>'
html_string_final = html_string_1 + html_string_2 + "</html>"
return HttpResponse(html_string_final)
announcement = Announcement.objects.all().order_by('-pub_datetime')
context = {
'announcement': announcement
}
return render(request, 'announcements/announcements.html', context)
class AnnouncementDetailView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
queryset = Announcement.objects.all()
context_object_name = 'announce'
class AnnouncementAddView(CreateView):
model = Announcement
fields = ['title', 'body', 'author']
template_name = 'announcements/announcement-add.html'
def get_success_url(self):
return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class AnnouncementEditView(UpdateView):
model = Announcement
template_name = 'announcements/announcement-edit.html'
fields = ['title', 'body', 'author']
def get_success_url(self):
return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
# Create your views here.
{% 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 %}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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