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,
)
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.
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