Commit 9fb15637 authored by Lex Philip Gabriel D. Chan's avatar Lex Philip Gabriel D. Chan

Fixed merge conflicts with master

parents c25d26c6 91c4a4cc
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcement_board'
# Generated by Django 4.1.7 on 2023-03-05 19:01
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='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=255)),
('body', models.TextField(default='')),
('pub_datetime', models.DateField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('like_tally', models.IntegerField(default=0)),
('love_tally', models.IntegerField(default=0)),
('angry_tally', models.IntegerField(default=0)),
('name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5)),
('announcment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement_board.announcement')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-05 19:16
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='angry_tally',
),
migrations.RemoveField(
model_name='reaction',
name='like_tally',
),
migrations.RemoveField(
model_name='reaction',
name='love_tally',
),
]
# Generated by Django 4.1.7 on 2023-03-05 20:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0002_remove_reaction_angry_tally_and_more'),
]
operations = [
migrations.AddField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
# Generated by Django 4.1.7 on 2023-03-06 05:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0003_reaction_tally'),
]
operations = [
migrations.RenameField(
model_name='reaction',
old_name='announcment',
new_name='announcement',
),
]
# Generated by Django 4.1.7 on 2023-03-06 06:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0004_rename_announcment_reaction_announcement'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(),
),
]
# Generated by Django 4.1.7 on 2023-03-06 08:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0005_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcement_board.announcement'),
),
]
from django.db import models
from django.utils.translation import gettext_lazy as _
from dashboard import models as dashboard_models
class Announcement(models.Model):
title = models.CharField(max_length=255, default="")
body = models.TextField(default="")
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {} {} published on {}: {}'.format(
self.title,
self.author.first_name,
self.author.last_name,
self.pub_datetime.strftime("%m/%d/%Y %I:%M %p"),
self.body
)
class Reaction(models.Model):
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='reactions')
class Reacts(models.TextChoices):
like = 'Like', _('Like')
love = 'Love', _('Love')
angry = 'Angry', _('Angry')
name = models.CharField(
max_length=5,
choices=Reacts.choices,
default=Reacts.like
)
tally = models.IntegerField(default=0)
def __str__(self):
return '{} reaction on {}'.format(self.name, self.announcement)
\ 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 = "announcement_board"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
from .models import Reaction
def index(request):
return_string = "<p>Widget's Announcement Board</p> <p>Announcements:<br>"
for announcements in Announcement.objects.all():
announcement_string = '{} by {} {} published {}:<br>{}<br>'.format(
announcements.title,
announcements.author.first_name,
announcements.author.last_name,
announcements.pub_datetime.strftime("%m/%d/%Y %I:%M %p"),
announcements.body
)
return_string += announcement_string
reactionList = announcements.reactions.all()
sortedReactionList = sortReactions(reactionList)
for reaction in sortedReactionList:
reactions_string = '{}: {}<br>'.format(
reaction.name,
reaction.tally
)
return_string += reactions_string
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(return_string)
# Sorting the reactions to Like, Love, and Angry order.
def sortReactions(list):
sortedReactionList = ['']*3
for reaction in list:
if reaction.name=="Like":
sortedReactionList[0] = reaction
elif reaction.name=="Love":
sortedReactionList[1] = reaction
elif reaction.name=="Angry":
sortedReactionList[2] = reaction
return sortedReactionList
\ No newline at end of file
...@@ -42,7 +42,7 @@ INSTALLED_APPS = [ ...@@ -42,7 +42,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard', 'dashboard',
#for announcement board 'announcement_board',
'forum', 'forum',
'assignments', 'assignments',
'widget_calendar', 'widget_calendar',
......
...@@ -19,7 +19,7 @@ from django.urls import path, include ...@@ -19,7 +19,7 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('dashboard/', include('dashboard.urls', namespace='dashboard')), path('dashboard/', include('dashboard.urls', namespace='dashboard')),
#for announcement board path('announcement_board/', include('announcement_board.urls', namespace='announcement_board')),
path('forum', include('forum.urls', namespace='forum')), path('forum', include('forum.urls', namespace='forum')),
path('widget_calendar/', include('widget_calendar.urls', namespace="widget_calendar")), path('widget_calendar/', include('widget_calendar.urls', namespace="widget_calendar")),
path('assignments/', include('assignments.urls', namespace='assignments')), path('assignments/', include('assignments.urls', namespace='assignments')),
......
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