Commit d9515a5a authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

did a git pull because I was behind

parents 9e1a908e bc0c3d82
from django.contrib import admin
from .models import Announcement, Reaction
class ReactionInline(admin.TabularInline):
model = Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'author', )
search_fields = ('title', 'body', 'author', )
list_filter = ('title', 'author')
fieldsets = [
('Announcement', {
'fields':
('title', 'body','author')
})
]
inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
from django.apps import AppConfig
class AnnouncementboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcementBoard'
# Generated by Django 3.2 on 2023-03-04 07:17
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=250)),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
('tally', models.IntegerField(default=0)),
('annoucement', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='announcementBoard.announcement')),
],
),
]
# Generated by Django 3.2 on 2023-03-05 09:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcementBoard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='annoucement',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcementBoard.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.PositiveIntegerField(default=0),
),
]
from django.db import models
from dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.CharField(max_length=250, default="")
body = models.TextField(null=True, blank=True)
author = models.ForeignKey(
WidgetUser,
null=True,
default=True,
on_delete=models.CASCADE,
related_name='announcements',
)
pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reaction(models.Model):
name = models.CharField(max_length=5, choices=[('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')], default='Like')
tally = models.PositiveIntegerField(default=0)
annoucement = models.ForeignKey(
Announcement,
null=True,
default=True,
on_delete=models.CASCADE,
related_name='reactions'
)
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 = "announcementBoard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
from dashboard.models import WidgetUser
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:450%;'>\
Widget's Announcement Board\
</h1>"
body = "<h2>Announcements:</h2>"
for x in Announcement.objects.all():
reaction = x.reactions.all()
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
{} by {} published {}:\
<br>\
{}\
</p>".format(x.title, x.author,
x.format_pub_datetime(), x.body)
for y in reaction:
body += "<p>{}: {}\
</p>".format(y.name, y.tally)
body += '<p>&nbsp;</p>'
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
\ No newline at end of file
......@@ -42,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'dashboard',
'assignments',
'announcementBoard',
]
MIDDLEWARE = [
......
......@@ -20,4 +20,5 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('announcementBoard/', include('announcementBoard.urls', namespace="announcementBoard")),
]
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