Commit a359ad04 authored by RJC's avatar RJC

pull from dev

parents bfae439d 39cda890
<?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
......@@ -11,11 +11,11 @@ CSCI 40 Midterms
widget_robo_mommy
APP_ASSIGNMENTS:
Dashboard - TBA
Announcement Board - TBA
Forum - TBA
Assignments - TBA
Calendar - TBA
Dashboard - CHESKA
Announcement Board - JIUVI
Forum - RJ
Assignments - LANCE
Calendar - AL
DATE_OF_SUBMISSION: **/**/**
......
SECRET_KEY='django-insecure-t*s#_++5=ze%3#*ns6vcmt8a5bw6249en-!ek7*#3=p-dkhl_f'
STATIC_ROOT='midterm_robo_mommy\widget_robo_mommy\widget_robo_mommy\settings.py'
\ No newline at end of file
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Assignments'
# Generated by Django 4.1.7 on 2023-03-04 17:11
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255, null=True)),
('description', models.TextField(blank=True, null=True)),
('course', models.CharField(blank=True, max_length=255, null=True)),
('perfect_score', models.IntegerField(blank=True, null=True)),
('passing_score', models.IntegerField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(blank=True, max_length=10, null=True)),
('title', models.CharField(blank=True, max_length=255, null=True)),
('section', models.CharField(blank=True, max_length=3, null=True)),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 17:27
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('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'),
),
]
from django.db import models
class Course(models.Model):
code = models.CharField(max_length=10, blank=True, null=True)
title = models.CharField(max_length=255, blank=True, null=True)
section = models.CharField(max_length=3, blank=True, null=True)
class Assignment(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
description = models.TextField(blank=True, null=True)
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)
perfect_score = models.IntegerField(blank=True, null=True)
passing_score = models.IntegerField(blank=True, null=True)
def save(self, *args, **kwargs):
self.passing_score = int(self.perfect_score * 0.60)
super(Assignment, self).save(*args, **kwargs)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "Assignments"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment, Course
import os
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)
from django.contrib import admin
from .models import ForumPost, Reply, WidgetUser
# Register your models here.
admin.site.register(ForumPost)
admin.site.register(Reply)
admin.site.register(WidgetUser)
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 3.2 on 2023-03-04 13:35
import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=255, null=True)),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.user')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
bases=('auth.user',),
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.widgetuser')),
('forumpost', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reply', to='forum.forumpost')),
],
),
migrations.AddField(
model_name='forumpost',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='forumpost', to='forum.widgetuser'),
),
]
# Generated by Django 3.2 on 2023-03-04 15:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_widgetuser'),
('admin', '0003_logentry_add_action_flag_choices'),
('forum', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='forumpost', to='Dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='Dashboard.widgetuser'),
),
migrations.DeleteModel(
name='WidgetUser',
),
]
from django.db import models
from Dashboard.models import WidgetUser
# Create your models here.
class ForumPost(models.Model):
title = models.CharField(max_length=255, blank=True, null=True)
body = models.TextField(blank=True, null=True)
author = models.ForeignKey(WidgetUser, related_name='forumpost', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
class Reply(models.Model):
forumpost = models.ForeignKey(ForumPost, related_name='reply', on_delete=models.CASCADE, null=True)
body = models.TextField(blank=True, null=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import *
urlpatterns = [
path('forum/', forum_post_list_view, name='forum_post_list_view')
]
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost
import pytz
from django.utils import timezone
# helper function to convert utc datetime object to local time
def convert_utc_to_local(utctime):
datetime_format = '%d/%m/%Y %H:%M'
utc = utctime.replace(tzinfo=pytz.UTC)
localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(datetime_format)
def forum_post_list_view(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"><title>Forum Post List</title>' \
'<h1>Forum Post List</h1></head><ul>'
html_string_2 = ''
for fp in ForumPost.objects.all():
html_string_2 += '<li><b style="font-size: 30px">{}</b>' \
' by <b style="font-size: large">{} {}</b>' \
' posted <b>{}</b><p>{}</p><ul>'.format(fp.title,
fp.author.first_name,
fp.author.last_name,
convert_utc_to_local(fp.pub_datetime), fp.body)
for replies in fp.reply.all():
html_string_2 += '<li> Reply by <b>{} {}</b> ' \
'posted <b>{}</b><p>{}</p></li>'.format(replies.author.first_name,
replies.author.last_name,
convert_utc_to_local(replies.pub_datetime),
replies.body)
html_string_2 += '</ul></li>'
html_string_final = html_string_1 + html_string_2 + '</ul></html>'
return HttpResponse(html_string_final)
......@@ -25,6 +25,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-t*s#_++5=ze%3#*ns6vcmt8a5bw6249en-!ek7*#3=p-dkhl_f'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
......@@ -34,13 +35,16 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'Assignments',
'forum.apps.ForumConfig',
'Dashboard.apps.DashboardConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Dashboard.apps.DashboardConfig'
'tz_detect',
]
MIDDLEWARE = [
......@@ -109,7 +113,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Hong_Kong'
USE_I18N = True
......@@ -127,6 +131,3 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
#blank =true and null=true
\ No newline at end of file
......@@ -17,7 +17,8 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('Dashboard/', include('Dashboard.urls', namespace="Dashboard")),
path('admin/', admin.site.urls),
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