Commit 092c1887 authored by Brescia Amandy's avatar Brescia Amandy

Pulled changes from main

parents 7da25599 0d27a7db
from django.contrib import admin
from .models import Reaction,Announcement
# Register your models here.
class ReactionInLine(admin.TabularInline):
model = Reaction
extra = 1
class AnnouncementAdmin(admin.ModelAdmin):
inlines = [ReactionInLine,]
list_display = ('title', 'author', 'pub_datetime', 'body')
search_fields = ('title', 'author', 'body')
list_filter = ('author', 'pub_datetime')
from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Announcement_Board'
from django.db import models
from django.urls import reverse
from dashboard.model import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey(
WidgetUser,
on_delete = models.CASCADE
)
pub_datetime = models.DateTimeField()
class Reaction(models.Model):
name = models.CharField(max_length = 50)
tally = models.IntegerField()
announcement = models.ForeignKey(
Announcement,
on_delete = models.CASCADE
)
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 = "Announcement_Board"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return_string = '<body> <ul>'
reaction_string = ''
for announcement in Announcement.objects.all():
announcement_string = '<li>{} by {} published <br>{}</li>'.format(
announcement.title, announcement.author, announcement.pub_datetime.strftime('%m/%d/%Y %H:%M %p'),
announcement.body
)
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
reaction_string += '<li>{}: {}</li>'.format(reaction.name, reaction.tally
)
return_string += announcement_string
return_string += reaction_string
return_string += '<br>'
return_string += '</ul></body>'
html_string = '<htmk>{}</html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score')
search_fields = ('name', 'description', 'course', 'perfect_score')
list_filter = ('name', 'course', 'perfect_score')
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section')
search_fields = ('code', 'title', 'section')
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
name = 'assignments'
# Generated by Django 3.0 on 2023-03-05 12:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=255)),
('section', models.CharField(blank=True, max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField(blank=True)),
('perfect_score', models.IntegerField(blank=True, default=0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.Course')),
],
),
]
# Generated by Django 3.2 on 2023-03-06 04:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='assignment',
name='perfect_score',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='course',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='course',
name='section',
field=models.CharField(max_length=3),
),
]
from django.db import models
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=255)
section = models.CharField(max_length=3)
def __str__(self):
return self.code
class Assignment(models.Model):
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField(default=0)
@property
def passing_score(self):
passing_score = self.perfect_score * 0.60
return passing_score
def __str__(self):
return self.name
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import assignments
urlpatterns = [
path('', assignments, name='assignments'),
]
# This might be needed depending on your Django version
app_name = "assignments"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment, Course
def assignments(request):
return_string = "Widget's Assignments Page<br><br>"
for assignment, course in zip(Assignment.objects.all(), Course.objects.all()):
return_string += 'Assignment: {}<br>'.format(assignment.name)
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)
from django.contrib import admin
from .models import Department, WidgetUser
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name', 'home_unit')
search_fields = ('dept_name', 'home_unit')
list_filter = ('dept_name',)
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('last_name', 'first_name', 'middle_name', 'department')
search_fields = ('last_name', 'first_name', 'middle_name')
list_filter = ('last_name', 'first_name')
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUserAdmin)
from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
# Generated by Django 4.1.7 on 2023-03-04 06:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=60)),
('home_unit', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=20)),
('middle_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
('department', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')),
],
),
]
from django.db import models
class Department(models.Model):
dept_name = models.CharField(max_length=60)
home_unit = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
department = models.ForeignKey(Department, null=True, on_delete=models.CASCADE)
def __str__(self):
return '{}, {} {} : {}'.format(self.last_name, self.first_name, self.middle_name, self.department)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('',index, name = 'index'),
]
dashboard = "Dashboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser, Department
def index(request):
text_in_http = "Welcome to Widget! <br> <br> WIDGET USERS: <br> <ul>"
for user in WidgetUser.objects.all():
text_in_http += "<li>{}, {} {} : {}</li>".format(user.last_name, user.first_name,
user.middle_name, user.department
)
text_in_http += "</ul>"
html_string = '<html><body>{}</body></html>'.format(text_in_http)
return HttpResponse(html_string)
...@@ -9,8 +9,15 @@ https://docs.djangoproject.com/en/4.1/topics/settings/ ...@@ -9,8 +9,15 @@ https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/ https://docs.djangoproject.com/en/4.1/ref/settings/
""" """
import os
from dotenv import load_dotenv
import os
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -20,7 +27,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent ...@@ -20,7 +27,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-gteg#r+a3^&nw_f+1)zcy#m72jv-i)wqfktiz$+#*6zem+6h^9' SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
...@@ -29,8 +36,8 @@ ALLOWED_HOSTS = [] ...@@ -29,8 +36,8 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'dashboard',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
...@@ -38,6 +45,8 @@ INSTALLED_APPS = [ ...@@ -38,6 +45,8 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'forum', 'forum',
'assignments',
'Announcement_Board',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -18,5 +18,8 @@ from django.urls import include, path ...@@ -18,5 +18,8 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('forum/', include('forum.urls', namespace="forum" )), path('forum/', include('forum.urls', namespace="forum" )),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('Announcement_Board/', include('Announcement_Board.urls', namespace="Announcement_Board" )),
path('dashboard', include('dashboard.urls', namespace="dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
...@@ -11,6 +11,7 @@ import os ...@@ -11,6 +11,7 @@ import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'widget_huli.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'widget_huli.settings')
application = get_wsgi_application() application = get_wsgi_application()
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