Commit 3fcde7bc authored by Ian Rafael T. Aragoza's avatar Ian Rafael T. Aragoza

Clean code to PEP8 standards, update announcementboard views.py and dashboard models.py

parent 090c9a66
...@@ -4,7 +4,7 @@ from django.urls import reverse ...@@ -4,7 +4,7 @@ from django.urls import reverse
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
# Create your models here.
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
body = models.TextField() body = models.TextField()
...@@ -13,19 +13,19 @@ class Announcement(models.Model): ...@@ -13,19 +13,19 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('announcement_detail', args=[str(self.title)]) return reverse('announcement_detail', args=[str(self.title)])
class Reaction(models.Model): class Reaction(models.Model):
reaction_names = [('Like','Like'),('Love','Love'),('Angry','Angry')] reaction_names = [('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')]
name = models.CharField(choices=reaction_names, max_length=255) name = models.CharField(choices=reaction_names, max_length=255)
tally = models.IntegerField(default=0, blank=True, null=True) tally = models.IntegerField(default=0, blank=True, null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name="reacts") announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name="reacts")
def __str__(self): def __str__(self):
return '{}'.format(self.name) return '{}'.format(self.name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('reaction_detail', args=[str(self.name)]) return reverse('reaction_detail', args=[str(self.name)])
...@@ -3,19 +3,35 @@ from django.http import HttpResponse ...@@ -3,19 +3,35 @@ from django.http import HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
# Create your views here.
# Create your views here.
def index(request): def index(request):
output = "<h1><b> Widget's Announcement Board </b></h1> <br> <h3>Announcements:</h3>" output = "<h1><b> Widget's Announcement Board </b></h1><h3>Announcements:</h3>"
for announcement in Announcement.objects.order_by('-pub_datetime'): for announcement in Announcement.objects.order_by('-pub_datetime'):
output += '{} by {} {} published {}:<br> {} <br>'.format( output += '<b>{}</b> by {} {} published {}:<br> {} <br>'.format(
announcement.title, announcement.author.first_name, announcement.author.last_name, announcement.pub_datetime.strftime("%m/%d/%Y %I:%M %p"), announcement.body) announcement.title, announcement.author.first_name, announcement.author.last_name, announcement.pub_datetime.strftime("%m/%d/%Y %I:%M %p"), announcement.body)
reactList = announcement.reacts.all() reactList = announcement.reacts.all()
for react in reactList: sortedReactList = sortReacts(reactList)
for react in sortedReactList:
output += '{}: {} <br>'.format(react.name, react.tally) output += '{}: {} <br>'.format(react.name, react.tally)
output += '<br>' output += '<br>'
return HttpResponse(output) return HttpResponse(output)
# Sorts reactions in the following order: Like, Love, Angry
def sortReacts(list):
sortedReactList = ['']*3
for react in list:
if react.name == "Like":
sortedReactList[0] = react
elif react.name == "Love":
sortedReactList[1] = react
elif react.name == "Angry":
sortedReactList[2] = react
return sortedReactList
from django.db import models
# Create your models here.
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
# Create your models here.
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=48, unique=True) dept_name = models.CharField(max_length=48, unique=True)
home_unit = models.CharField(max_length=48) home_unit = models.CharField(max_length=48)
def __str__(self): def __str__(self):
return '{}'.format(self.dept_name) return '{}'.format(self.dept_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('department_detail', args=[str(self.dept_name)]) return reverse('department_detail', args=[str(self.dept_name)])
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.TextField(max_length=48) first_name = models.TextField(max_length=48)
middle_name = models.TextField(max_length=48) middle_name = models.TextField(max_length=48)
last_name = models.TextField(max_length=48) last_name = models.TextField(max_length=48)
department = models.ForeignKey(Department, on_delete=models.CASCADE, related_name='department') department = models.ForeignKey(Department, on_delete=models.CASCADE, related_name='users')
def __str__(self): def __str__(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name) return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('user_detail', args=[str(self.last_name)]) return reverse('user_detail', args=[str(self.last_name)])
...@@ -3,8 +3,8 @@ from django.http import HttpResponse ...@@ -3,8 +3,8 @@ from django.http import HttpResponse
from .models import WidgetUser from .models import WidgetUser
# Create your views here.
# Create your views here.
def index(request): def index(request):
output = "Welcome to Widget!<br><br> WIDGET USERS:<br>" output = "Welcome to Widget!<br><br> WIDGET USERS:<br>"
userList = WidgetUser.objects.order_by('last_name') userList = WidgetUser.objects.order_by('last_name')
......
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