Commit 261cfc17 authored by RJC's avatar RJC

commit untracked files

parent 9b6930eb
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
# Register your models here.
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
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-05 14:21
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('Dashboard', '0002_widgetuser'),
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.TextField(blank=True, null=True)),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(null=True)),
('author', models.ForeignKey(null=True, 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')),
('name', models.CharField(blank=True, default='Like', max_length=5, null=True)),
('tally', models.IntegerField(blank=True, default=0, null=True)),
('announcement', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
from django.db import models
from Dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.TextField(null=True, blank=True)
body = models.TextField(null=True, blank=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(null=True)
class Reaction(models.Model):
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGRY, 'Angry'),
]
name = models.CharField(max_length=5, default=LIKE, null=True, blank=True)
tally = models.IntegerField(default=0 ,null=True, blank=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True)
# Create your models here.
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"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
import pytz
from django.utils import timezone
def convert_to_localtime(utctime):
format = '%d/%m/%Y %H:%M'
utc = utctime.replace(tzinfo=pytz.UTC)
localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(format)
def index(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"></head>\
<b><h1>Widget\'s Announcement Board</h1></b>\
<h2>Announcements:</h2><br/>'
html_string_2 = ""
for announced in Announcement.objects.all():
html_string_2 += "{} by {} {} published {}<br />:\
{}".format(announced.title, announced.author.first_name,
announced.author.last_name,
convert_to_localtime(announced.pub_datetime), announced.body)
for reacts in announced.reaction.all():
html_string_2 += "{}: {}".format(reacts.name, reacts.tally)
html_string_final = html_string_1 + html_string_2 + "</html>"
return HttpResponse(html_string_final)
# Create your views here.
...@@ -13,9 +13,11 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ ...@@ -13,9 +13,11 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
DIRNAME = os.path.abspath(os.path.dirname(__file__)) DIRNAME = os.path.abspath(os.path.dirname(__file__))
load_dotenv() load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -35,6 +37,7 @@ ALLOWED_HOSTS = [] ...@@ -35,6 +37,7 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'announcements',
'Assignments', 'Assignments',
'forum.apps.ForumConfig', 'forum.apps.ForumConfig',
'Dashboard.apps.DashboardConfig', 'Dashboard.apps.DashboardConfig',
......
...@@ -14,9 +14,11 @@ Including another URLconf ...@@ -14,9 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import include, path
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('announcements/', include('announcements.urls', namespace="announcements")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('Assignments/', include('Assignments.urls', namespace="Assignments")), path('Assignments/', include('Assignments.urls', namespace="Assignments")),
path('', include(('forum.urls', 'forum'), namespace='forum')), path('', include(('forum.urls', 'forum'), namespace='forum')),
......
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