Commit d6fc7537 authored by Jose Gabriel L. Salas's avatar Jose Gabriel L. Salas

added files for pushing to staging

parents 312176d1 f6700b35
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:<ul style='list-style: none; padding: 0; margin: 0;'>"
for a in Announcement.objects.all():
return_string += '''<li>{} by {} {} published {}</li>{}<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,
)
return_string += '</ul>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
...@@ -41,7 +41,11 @@ INSTALLED_APPS = [ ...@@ -41,7 +41,11 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard', 'dashboard',
<<<<<<< HEAD
'widget_calendar' 'widget_calendar'
=======
'announcements',
>>>>>>> f6700b35f7db8ac5d251ad6b596528ba9f7d4fac
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -18,6 +18,10 @@ from django.urls import include, path ...@@ -18,6 +18,10 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
<<<<<<< HEAD
path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")), path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")),
=======
path('announcements/', include('announcements.urls', namespace="announcements")),
>>>>>>> f6700b35f7db8ac5d251ad6b596528ba9f7d4fac
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
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