Commit 2e566658 authored by Sumawang, Tee Jay Jr. C.'s avatar Sumawang, Tee Jay Jr. C.

Announcements now has Reactions and Authors. View is also updated to reflect this information.

parents 50a3a78b c3b1b58b
widget_tee_jays_angelos/homepage/__pycache__/
widget_tee_jays_angelos/homepage/migrations/__pycache__/
widget_tee_jays_angelos/announcements/__pycache__/
widget_tee_jays_angelos/announcements/migrations/__pycache__/
widget_tee_jays_angelos/forum/__pycache__/
widget_tee_jays_angelos/forum/migrations/__pycache__/
widget_tee_jays_angelos/assignments/__pycache__/
widget_tee_jays_angelos/assignments/migrations/__pycache__/
......@@ -9,3 +9,5 @@ LIM, Ryan Angelo G. - Forum
SY, Paul Angelo G. - Assignments
LAB 1 DEMO LINK: https://youtu.be/jNdRMSFblpw
LAB 2 DEMO LINK: https://youtu.be/c7grjkmlyRI
\ No newline at end of file
from django.contrib import admin
from .models import Announcement
from django.db import models
from .models import Announcement, Reaction
# Register your models here.
admin.site.register(Announcement)
\ No newline at end of file
class ReactionAdminInline(admin.TabularInline):
model = Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
inlines = [ReactionAdminInline]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-03-31 07:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_widgetuser_email_widgetuser_id_num_department'),
('announcements', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='author', to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(max_length=50)),
('tally', models.IntegerField()),
('Announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='announcements.announcement')),
],
),
]
# Generated by Django 3.2.12 on 2022-03-31 08:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0002_auto_20220331_1544'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='Announcement',
),
migrations.AddField(
model_name='announcement',
name='reaction',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='announcements.reaction'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 08:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_auto_20220331_1602'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='Announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='announcements.announcement'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 08:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_auto_20220331_1604'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='Announcement',
),
migrations.AddField(
model_name='announcement',
name='Announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='announcements.reaction'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 08:18
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_auto_20220331_1610'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='Announcement',
),
migrations.AddField(
model_name='announcement',
name='reaction',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcements.reaction'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 08:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_auto_20220331_1618'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='Announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='announcements.announcement'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 14:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_auto_20220331_1622'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 14:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0008_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 14:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0009_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(default=['%m/%d/%y'], verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0010_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0011_alter_announcement_pub_date'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='date_only',
field=models.DateField(null=True, verbose_name='Date only'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0012_announcement_date_only'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='date_only',
),
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(null=True, verbose_name='Date only'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0013_auto_20220331_2315'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(auto_now_add=True, null=True, verbose_name='Date only'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0014_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(null=True, verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0015_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(null=True, verbose_name='date published'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 15:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0016_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(null=True, verbose_name='date published'),
),
]
from django.db import models
from homepage.models import WidgetUser
# Create your models here.
class Announcement(models.Model):
announcement_title = models.CharField(max_length=50)
announcement_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published")
pub_date = models.DateTimeField("date published", null=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True, related_name='author')
def __str__(self):
return self.announcement_title
class Reaction(models.Model):
Announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True, related_name='announcements')
reaction_name = models.CharField(max_length=50)
tally = models.IntegerField()
def __str__(self):
return self.reaction_name
from django.http import HttpResponse
from announcements.models import Announcement, Reaction, WidgetUser
# Create your views here.
def index(request):
return HttpResponse("This is the Announcements Board!")
announcementEntries = Announcement.objects.all().count()
n = 1
announcement = "ANNOUNCEMENTS:<br/>"
while(n<=announcementEntries):
announcement += getAnnouncementHeader(n)
announcement += getReactions(n)
n += 1
return HttpResponse(announcement)
# helper function that iterates through every reaction of an announcement and returns it
def getReactions(pk):
announcementReactions = ""
for reaction in Announcement.objects.get(pk=pk).announcements.all():
announcementReactions += "{}: {}<br/>" .format(reaction.reaction_name, reaction.tally)
announcementReactions += "<br/>"
return announcementReactions
# helper function that takes the data in an announcement and creates the header of the announcement
# (First and Second lines)
def getAnnouncementHeader(pk):
announcementFirstLine = ""
announcementSecondLine = ""
announcementHeader = ""
announcementTitle = Announcement.objects.get(pk=pk).announcement_title
authorFirstName = Announcement.objects.get(pk=pk).author.first_name
authorLastName = Announcement.objects.get(pk=pk).author.last_name
publicationDate = Announcement.objects.get(pk=pk).pub_date
announcementBody = Announcement.objects.get(pk=pk).announcement_body
announcementFirstLine = "{} by {} {} dated {}<br/>" .format(announcementTitle, authorFirstName, authorLastName, publicationDate)
announcementSecondLine = "{}<br/>" .format(announcementBody)
announcementHeader += announcementFirstLine + announcementSecondLine
return announcementHeader
from django.contrib import admin
# Register your models here.
from .models import Post
admin.site.register(Post)
# Generated by Django 4.0.3 on 2022-03-22 07:48
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post_title', models.CharField(max_length=50)),
('post_body', models.CharField(max_length=500)),
('pub_date', models.DateTimeField(verbose_name='date published')),
],
),
]
from django.db import models
# Create your models here.
class Post(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published")
def __str__(self):
return self.post_title
from django.contrib import admin
from .models import WidgetUser
from .models import WidgetUser, Department
# Register your models here.
admin.site.register(WidgetUser)
class DepartmentAdminInline(admin.TabularInline):
model = Department
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
inlines = [DepartmentAdminInline]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
# Generated by Django 4.0.3 on 2022-03-25 18:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.CharField(max_length=50, null=True),
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.CharField(max_length=7, null=True),
),
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=50)),
('home_unit', models.CharField(max_length=50)),
('widget_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
......@@ -6,6 +6,18 @@ class WidgetUser(models.Model):
first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
id_num = models.CharField(max_length=7, null=True)
email = models.CharField(max_length=50, null=True)
def __str__(self):
return self.first_name + " " + self.last_name
return self.last_name + ", " + self.first_name
class Department(models.Model):
widget_user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,
blank=True, null=True)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
def __str__(self):
return self.dept_name + ", " + self.home_unit
from django.http import HttpResponse
from homepage.models import WidgetUser, Department
# Create your views here.
def index(request):
return HttpResponse("Welcome to Widget!")
entries = WidgetUser.objects.all().count()
n = 1
users = "WIDGET USERS:<br/>"
while (n <= entries):
userLastName = WidgetUser.objects.get(pk=n).last_name
userFirstName = WidgetUser.objects.get(pk=n).first_name
userMiddleName = WidgetUser.objects.get(pk=n).middle_name
userIdNum = WidgetUser.objects.get(pk=n).id_num
userEmail = WidgetUser.objects.get(pk=n).email
userDept = Department.objects.get(widget_user=n).dept_name
userHome = Department.objects.get(widget_user=n).home_unit
users = users + userLastName + ", " + userFirstName + " " + userMiddleName + ": " + userIdNum + ", " + userEmail + ", " + userDept + ", " + userHome + "<br/>"
n += 1
return HttpResponse(users)
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