Commit dbeb241e authored by Elaiza Bolislis's avatar Elaiza Bolislis

Merged main into dashboard

parents 57662278 6e791c8f
File added
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'body', 'author', 'pub_datetime',)
search_fields = ('title', 'body', 'author', 'pub_datetime',)
list_filter = ('title', 'body', 'author', 'pub_datetime',)
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'announcement',)
search_fields = ('name', 'tally', 'announcement',)
list_filter = ('name', 'tally', 'announcement',)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
from django.apps import AppConfig
class AnnouncementsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcements'
# Generated by Django 4.1.7 on 2023-03-04 04:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('body', models.TextField()),
('author', models.CharField(max_length=100)),
('pub_datetime', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('tally', models.IntegerField()),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 05:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'LIKE'), ('Love', 'LOVE'), ('Angry', 'ANGRY')], default='Like', max_length=5),
),
]
# Generated by Django 4.1.7 on 2023-03-04 07:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcements', '0002_alter_announcement_pub_datetime_alter_reaction_name'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='first_name',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='first_names', to='dashboard.widgetuser'),
),
migrations.AddField(
model_name='announcement',
name='last_name',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='last_names', to='dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-03-04 08:27
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcements', '0003_announcement_first_name_announcement_last_name'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-03-04 10:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcements', '0004_alter_announcement_author'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='announcements_author', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('LIKE', 'Like'), ('LOVE', 'Love'), ('ANGRY', 'Angry')], default='LIKE', max_length=5),
),
]
# Generated by Django 4.1.7 on 2023-03-04 10:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_author_alter_reaction_name'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='first_name',
),
migrations.RemoveField(
model_name='announcement',
name='last_name',
),
]
from django.db import models
class Announcement(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.ForeignKey(
'dashboard.WidgetUser',
on_delete=models.CASCADE,
related_name='announcements_author'
)
pub_datetime = models.DateTimeField()
def __str__(self):
return '''{} by {} published {}\n{}'''.format(
self.title,
self.author,
self.pub_datetime,
self.body,
)
class Reaction(models.Model):
REACTION_LIKE = "LIKE"
REACTION_LOVE = "LOVE"
REACTION_ANGRY = "ANGRY"
REACTION_CHOICES = [
(REACTION_LIKE, "Like"),
(REACTION_LOVE, "Love"),
(REACTION_ANGRY, "Angry"),
]
name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default=REACTION_LIKE,
)
tally = models.IntegerField()
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return self.name
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 = "announcements"
from django.http import HttpResponse
from .models import Announcement, Reaction
def index(request):
return_string = "<p>Widget's Announcement Board</p>Announcements:<br>"
for a in Announcement.objects.all():
return_string += '''{} by {} {} published {}{}<br>'''.format(
a.title,
a.author.first_name,
a.author.last_name,
a.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
a.body,
)
likeTally = 0
loveTally = 0
angryTally = 0
for r in Reaction.objects.all():
if r.name == "LIKE" and r.announcement == a:
likeTally += r.tally
if r.name == "LOVE" and r.announcement == a:
loveTally += r.tally
if r.name == "ANGRY" and r.announcement == a:
angryTally += r.tally
return_string += '''Like: {}<br>Love: {}
<br>Angry: {}<br><br>'''.format(
likeTally,
loveTally,
angryTally,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('assignment_name', 'description', 'course', 'perfect_score',)
search_fields = ('assignment_name', 'description', 'course', 'perfect_score',)
list_filter = ('assignment_name', 'description', 'course', 'perfect_score',)
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section',)
search_fields = ('code', 'title', 'section',)
list_filter = ('code', 'title', 'section',)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
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-05 14:44
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.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('assignment_name', models.CharField(max_length=50)),
('description', models.TextField()),
('perfect_score', models.IntegerField()),
('course', models.ForeignKey(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)
title = models.CharField(max_length=100)
section = models.CharField(max_length=3)
def __str__(self):
return '''{}, {}, {}'''.format(
self.code,
self.title,
self.section,
)
class Assignment(models.Model):
assignment_name = models.CharField(max_length=50)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField()
def __str__(self):
return '''{}, {}, {}, {}'''.format(
self.assignment_name,
self.description,
self.course,
self.perfect_score,
)
\ 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'),
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment
def index(request):
return_string = "<p>Widget's Assignment Page</p>"
for a in Assignment.objects.all():
return_string += '''Assignment Name: {} <br>Description: {}
<br>Perfect Score: {} <br>Passing Score: {}
<br>Course/Section: {} {}-{}<br><br>'''.format(
a.assignment_name,
a.description,
a.perfect_score,
int(a.perfect_score * 0.60),
a.course.code,
a.course.title,
a.course.section,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
from django.contrib import admin
from .models import Department, WidgetUser
......
......@@ -16,4 +16,8 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete=models.CASCADE)
def __str__(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
return '{}, {} {}'.format(
self.last_name,
self.first_name,
self.middle_name
)
from django.shortcuts import HttpResponse
from .models import Department, WidgetUser
from .models import WidgetUser
def index(request):
return_string = '<p>Welcome to Widget!</p> WIDGET USERS:<br>'
return_string = '<p>Welcome to Widget!</p>WIDGET USERS:<br>'
for user in WidgetUser.objects.all():
return_string += '{}: {}<br>'.format(user, user.department)
html_string = '<html><body>{}</body></html>'.format(return_string)
......
from django.contrib import admin
from .models import ForumPost, Reply
class ReplyInline(admin.TabularInline):
model = Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ('title', 'body', 'author', 'pub_datetime',)
search_fields = ('title', 'author',)
list_filter = ('author', 'pub_datetime',)
inlines = [ReplyInline,]
fieldsets = [
('Forum Data', {
'fields': [
('title', 'body'), 'author', 'pub_datetime'
]
}),
]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ('body', 'author', 'pub_datetime',)
search_fields = ('author',)
list_filter = ('author', 'pub_datetime',)
fieldsets = [
('Reply Data', {
'fields': [
('body'), 'author', 'pub_datetime'
]
}),
]
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 4.1.7 on 2023-03-04 14:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='forumpost_author', to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reply_author', to='dashboard.widgetuser')),
('forumpost', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='forumpost_reply', to='forum.forumpost')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 15:09
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reply',
name='forumpost',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='forumpost_reply', to='forum.forumpost'),
),
]
from django.db import models
class ForumPost(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.ForeignKey(
'dashboard.WidgetUser',
on_delete=models.CASCADE,
related_name='forumpost_author'
)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {} posted {}: {}'.format(
self.title,
self.author,
self.pub_datetime,
self.body
)
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(
'dashboard.WidgetUser',
on_delete=models.CASCADE,
related_name='reply_author'
)
pub_datetime = models.DateTimeField()
forumpost = models.ForeignKey(
ForumPost,
on_delete=models.CASCADE,
related_name='forumpost_reply'
)
def __str__(self):
return 'Reply by {} posted {}: {}'.format(
self.author,
self.pub_datetime,
self.body,
)
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 = "forum"
from django.http import HttpResponse
from .models import ForumPost, Reply
def index(request):
return_string = "<p>Widget's Forum</p>Forum Posts:"
for post in ForumPost.objects.all():
counter = 0
for reply in Reply.objects.all():
if counter == 0 and post.title == reply.forumpost.title:
return_string += '<br>{} by {} {} posted {}<br>{}'.format(
reply.forumpost.title,
reply.forumpost.author.first_name,
reply.forumpost.author.last_name,
reply.forumpost.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.forumpost.body,
)
return_string += '<br>Reply by {} {} posted {}<br>{}'.format(
reply.author.first_name,
reply.author.last_name,
reply.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.body,
)
counter += 1
continue
elif counter == 1 and post.title == reply.forumpost.title:
return_string += '<br>Reply by {} {} posted {}<br>{}'.format(
reply.author.first_name,
reply.author.last_name,
reply.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
reply.body,
)
continue
elif counter == 1 and post.title != reply.forumpost.title:
return_string += '<br>'
break
else:
continue
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
......@@ -41,6 +41,10 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard',
'forum',
'widget_calendar',
'announcements',
'assignments',
]
MIDDLEWARE = [
......
......@@ -18,5 +18,9 @@ from django.urls import include, path
urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('forum/', include('forum.urls', namespace="forum")),
path('announcements/', include('announcements.urls', namespace="announcements")),
path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls),
]
from django.contrib import admin
from .models import Event, Location
class EventAdmin(admin.ModelAdmin):
model = Event
search_fields = ('activity', 'target_datetime', 'course', )
list_display = (
'target_datetime', 'activity', 'estimated_hours',
'location', 'course',
)
list_filter = ('target_datetime', 'course', )
fieldsets = [
('Activity', {
'fields': [
('activity', 'course', ),
'target_datetime', 'location', 'estimated_hours'
]
}),
]
class LocationAdmin(admin.ModelAdmin):
model = Location
search_fields = ('venue', 'mode', )
list_display = ('mode', 'venue', )
list_filter = ('mode', )
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
from django.apps import AppConfig
class WidgetCalendarConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'widget_calendar'
# Generated by Django 4.1.7 on 2023-03-04 14:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mode', models.CharField(choices=[('OS', 'Onsite'), ('OL', 'Online'), ('HB', 'Hybrid')], default='OS', max_length=2)),
('venue', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField()),
('activity', models.CharField(max_length=255)),
('estimated_hours', models.FloatField()),
('course', models.CharField(max_length=100)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='widget_calendar.location')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 15:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='location',
name='mode',
field=models.CharField(choices=[('Onsite', 'Onsite'), ('Online', 'Online'), ('Hybrid', 'Hybrid')], default='Onsite', max_length=6),
),
]
# Generated by Django 4.1.7 on 2023-03-04 16:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0002_alter_location_mode'),
]
operations = [
migrations.AlterField(
model_name='event',
name='location',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='event', to='widget_calendar.location'),
),
]
# Generated by Django 4.1.7 on 2023-03-04 18:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0003_alter_event_location'),
]
operations = [
migrations.AlterField(
model_name='event',
name='location',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='widget_calendar.location'),
),
]
from django.db import models
class Location(models.Model):
onsite = 'Onsite'
online = 'Online'
hybrid = 'Hybrid'
mode_choices = [
(onsite, 'Onsite'),
(online, 'Online'),
(hybrid, 'Hybrid'),
]
mode = models.CharField(
max_length=6, choices=mode_choices, default=onsite,
)
venue = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.mode, self.venue)
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=255)
estimated_hours = models.FloatField()
location = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.activity, self.target_datetime)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
# This might be needed, depending on your Django version
app_name = "widget_calendar"
\ No newline at end of file
from django.http import HttpResponse
from .models import Event
def index(request):
return_string = "<p>Widget's Calendar of Activities</p>"
for events in Event.objects.all():
round_hours = ("{:0.0f}".format(events.estimated_hours))
return_string += 'Date and Time: {}<br>'.format(
events.target_datetime.strftime('%m/%d/%Y, %H:%M %p')
)
return_string += 'Activity: {}<br>'.format(events.activity)
return_string += 'Estimated Hours: {}<br>'.format(round_hours)
return_string += 'Course/Section: {}<br>'.format(events.course)
return_string += 'Mode: {}<br>'.format(events.location.mode)
return_string += 'Venue: {}<br>'.format(events.location.venue)
return_string += '<br>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
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