Commit 0d27a7db authored by Brescia Amandy's avatar Brescia Amandy

Pulled changes from main

parents 802e8714 18b6b350
from django.contrib import admin
from .models import Reaction,Announcement
# Register your models here.
class ReactionInLine(admin.TabularInline):
model = Reaction
extra = 1
class AnnouncementAdmin(admin.ModelAdmin):
inlines = [ReactionInLine,]
list_display = ('title', 'author', 'pub_datetime', 'body')
search_fields = ('title', 'author', 'body')
list_filter = ('author', 'pub_datetime')
from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Announcement_Board'
from django.db import models
from django.urls import reverse
from dashboard.model import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey(
WidgetUser,
on_delete = models.CASCADE
)
pub_datetime = models.DateTimeField()
class Reaction(models.Model):
name = models.CharField(max_length = 50)
tally = models.IntegerField()
announcement = models.ForeignKey(
Announcement,
on_delete = models.CASCADE
)
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"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return_string = '<body> <ul>'
reaction_string = ''
for announcement in Announcement.objects.all():
announcement_string = '<li>{} by {} published <br>{}</li>'.format(
announcement.title, announcement.author, announcement.pub_datetime.strftime('%m/%d/%Y %H:%M %p'),
announcement.body
)
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
reaction_string += '<li>{}: {}</li>'.format(reaction.name, reaction.tally
)
return_string += announcement_string
return_string += reaction_string
return_string += '<br>'
return_string += '</ul></body>'
html_string = '<htmk>{}</html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
from django.contrib import admin
from .models import Department, WidgetUser
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name', 'home_unit')
search_fields = ('dept_name', 'home_unit')
list_filter = ('dept_name',)
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('last_name', 'first_name', 'middle_name', 'department')
search_fields = ('last_name', 'first_name', 'middle_name')
list_filter = ('last_name', 'first_name')
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUserAdmin)
from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
# Generated by Django 4.1.7 on 2023-03-04 06:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
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=60)),
('home_unit', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=20)),
('middle_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
('department', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')),
],
),
]
from django.db import models
class Department(models.Model):
dept_name = models.CharField(max_length=60)
home_unit = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
department = models.ForeignKey(Department, null=True, on_delete=models.CASCADE)
def __str__(self):
return '{}, {} {} : {}'.format(self.last_name, self.first_name, self.middle_name, self.department)
\ 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'),
]
dashboard = "Dashboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser, Department
def index(request):
text_in_http = "Welcome to Widget! <br> <br> WIDGET USERS: <br> <ul>"
for user in WidgetUser.objects.all():
text_in_http += "<li>{}, {} {} : {}</li>".format(user.last_name, user.first_name,
user.middle_name, user.department
)
text_in_http += "</ul>"
html_string = '<html><body>{}</body></html>'.format(text_in_http)
return HttpResponse(html_string)
......@@ -9,6 +9,8 @@ https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
from dotenv import load_dotenv
import os
from pathlib import Path
......@@ -35,6 +37,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -42,6 +45,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'assignments',
'Announcement_Board',
]
MIDDLEWARE = [
......
......@@ -16,8 +16,12 @@ Including another URLconf
from django.contrib import admin
from django.urls import include, path
from django.urls import include, path
urlpatterns = [
path('assignments/', include('assignments.urls', namespace="assignments")),
path('Announcement_Board/', include('Announcement_Board.urls', namespace="Announcement_Board" )),
path('dashboard', include('dashboard.urls', namespace="dashboard")),
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