Commit fc8bdba5 authored by Rau Layug's avatar Rau Layug

Merged layug/calendar with master branch

parents 38732a97 cab13277
from django.contrib import admin from django.contrib import admin
from .models import Announcement from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
list_display = ('announcement_title', 'announcement_body', 'pub_date') list_display = ('announcement_title', 'announcement_body', 'pub_date', 'author')
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('announcement', 'reaction_name', 'tally')
admin.site.register(Announcement, AnnouncementAdmin) admin.site.register(Announcement, AnnouncementAdmin)
\ No newline at end of file admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
...@@ -4,6 +4,38 @@ class Announcement(models.Model): ...@@ -4,6 +4,38 @@ class Announcement(models.Model):
announcement_title = models.CharField(max_length=150) announcement_title = models.CharField(max_length=150)
announcement_body = models.TextField() announcement_body = models.TextField()
pub_date = models.DateField(auto_now=True) pub_date = models.DateField(auto_now=True)
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
related_name='announcements'
)
def __str__(self): def __str__(self):
return '"{}" published {}'.format(self.announcement_title, self.pub_date) return '"{}" published {}'.format(self.announcement_title, self.pub_date)
\ No newline at end of file
class Reaction(models.Model):
announcement = models.ForeignKey(
Announcement,
on_delete=models.CASCADE,
related_name='reactions'
)
REACTION_CHOICES = [
('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')
]
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default='Like'
)
tally = models.IntegerField(default=1, editable=False)
def save(self):
if self.reaction_name=='Like':
self.tally = self.announcement.reactions.filter(reaction_name='Like').count()+1
elif self.reaction_name=='Love':
self.tally = self.announcement.reactions.filter(reaction_name='Love').count()+1
elif self.reaction_name=='Angry':
self.tally = self.announcement.reactions.filter(reaction_name='Angry').count()+1
return super().save()
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement
def index(request): def index(request):
return HttpResponse("This is the Announcement Board!") heading = 'ANNOUNCEMENTS:<br>'
all_announcements = Announcement.objects.all()
body = ''
for announcement in all_announcements:
count_like = announcement.reactions.filter(reaction_name='Like').count()
count_love = announcement.reactions.filter(reaction_name='Love').count()
count_angry = announcement.reactions.filter(reaction_name='Angry').count()
body += '{} by {} {} dated {}:<br>{}<br>Like: {}<br>Love: {}<br>Angry: {}<br><br>'.format(
announcement.announcement_title, announcement.author.first_name,
announcement.author.last_name, announcement.pub_date,
announcement.announcement_body, count_like,
count_love, count_angry
)
return HttpResponse(heading + body)
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Assignment from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
list_display = ('name', 'description', 'max_points') list_display = ('name', 'description', 'max_points', 'passing_score')
class CourseAdmin(admin.ModelAdmin):
mode = Course
list_display = ('course_code', 'course_title', 'section')
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
# Generated by Django 4.0.3 on 2022-03-22 14:13
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.CharField(max_length=500)),
('max_points', models.IntegerField()),
],
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Course(models.Model):
course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=50)
section = models.CharField(max_length=3)
def __str__(self):
return self.course_code
class Assignment(models.Model): class Assignment(models.Model):
course_code = models.ForeignKey(Course, on_delete=models.CASCADE)
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
max_points = models.IntegerField() max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0, editable=False)
def __str__(self): def __str__(self):
return self.name return self.name
def save(self):
self.passing_score = int(self.max_points*0.6)
return super(Assignment, self).save()
from django.shortcuts import HttpResponse from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!") heading = 'ASSIGNMENTS:<br><br>'
assignments = Assignment.objects.all()
body = ''
for assignment in assignments:
courses = Course.objects.filter(course_code__exact=assignment.course_code)
body += 'Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>'.format(
assignment.name, assignment.description, assignment.max_points, assignment.passing_score
)
for course in courses:
body += 'Course/Section: {} {} {}<br><br>'.format(
course.course_code, course.course_title, course.section
)
return HttpResponse(heading + body)
# Generated by Django 4.0.3 on 2022-03-17 15:19
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_date', models.DateField()),
('activity', models.CharField(max_length=150)),
('estimated_hours', models.FloatField()),
],
),
]
from django.contrib import admin from django.contrib import admin
from .models import Post from .models import Post, Reply
class PostAdmin(admin.ModelAdmin): class PostAdmin(admin.ModelAdmin):
model = Post model = Post
list_display = ('post_title', 'post_body', 'pub_date') list_display = ('post_title', 'post_body', 'pub_date', 'author')
admin.site.register(Post, PostAdmin) class ReplyAdmin(admin.ModelAdmin):
\ No newline at end of file model = Reply
list_display = ('reply_body', 'original_post', 'pub_date', 'author')
admin.site.register(Post, PostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-19 17:29
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=150)),
('post_body', models.TextField()),
('pub_date', models.DateField(auto_now=True)),
],
),
]
...@@ -4,7 +4,14 @@ from django.db import models ...@@ -4,7 +4,14 @@ from django.db import models
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=150) post_title = models.CharField(max_length=150)
post_body = models.TextField() post_body = models.TextField()
pub_date = models.DateField(auto_now=True) pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE, related_name='posts')
def __str__(self): def __str__(self):
return '"{}" published {}'.format(self.post_title, self.pub_date) return '{}'.format(self.post_title)
\ No newline at end of file
class Reply(models.Model):
original_post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name='replies')
reply_body = models.TextField()
pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE, related_name='replies')
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
def index(request): def index(request):
return HttpResponse("Welcome to Widget's Forum!") heading = 'FORUM POSTS:<br>'
posts = Post.objects.all()
body = ''
for post in posts:
post_replies = Reply.objects.filter(original_post=post)
body += '{} by {} {} dated {}:<br>{}<br>'.format(
post.post_title, post.author.first_name, post.author.last_name,
post.pub_date, post.post_body
)
for post_reply in post_replies:
body += 'Reply by {} {} dated {}:<br>{}<br>'.format(
post_reply.author.first_name, post_reply.author.last_name,
post_reply.pub_date, post_reply.reply_body
)
body += '<br>'
return HttpResponse(heading + body)
from django.contrib import admin from django.contrib import admin
from .models import WidgetUser from .models import WidgetUser,Department
# Register your models here. # Register your models here.
class WidgetUserAdmin(admin.ModelAdmin): class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser model = WidgetUser
search_fields = ('first_name','last_name') search_fields = ('first_name','last_name')
list_display = ('first_name','middle_name','last_name') list_display = ('first_name','middle_name','last_name','id_num','email','department')
list_filter = ('last_name', 'first_name') list_filter = ('last_name', 'first_name')
admin.site.register(WidgetUser, WidgetUserAdmin) class DepartmentAdmin(admin.ModelAdmin):
\ No newline at end of file model = Department
list_display = ('dept_name','home_unit')
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department,DepartmentAdmin)
\ No newline at end of file
from xml.dom import ValidationErr
from django.db import models from django.db import models
from django.core.exceptions import ValidationError
# Create your models here. # Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=124)
home_unit = models.CharField(max_length=124)
def __str__(self):
return '{}'.format(self.dept_name)
def get_dept_info(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=35) def ID_validator(value):
middle_name = models.CharField(max_length=20) if value.isdigit() != True:
last_name= models.CharField(max_length=20) raise ValidationError('Student ID must be Integers')
first_name = models.CharField(max_length=35,default='')
middle_name = models.CharField(max_length=20,default='')
last_name = models.CharField(max_length=20,default='')
id_num = models.CharField(max_length=7,default='',validators=[ID_validator])
email = models.EmailField(default='')
department = models.ForeignKey(Department,on_delete=models.CASCADE,default='')
def __str__(self): def __str__(self):
return 'Name: {}, {} {}'.format(self.last_name, self.first_name, self.last_name) return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
\ No newline at end of file
def get_user_info(self):
return '{}, {} {}: {}, {}, {} </br>'.format(
self.last_name,self.first_name,
self.middle_name,self.id_num,self.email,
self.department.get_dept_info()
)
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse('Welcome to the Widget!') model = WidgetUser
\ No newline at end of file widget_users = model.objects.all()
homepage_response = "WIDGET USERS: </br>"
for user in widget_users:
homepage_response += user.get_user_info()
return HttpResponse(homepage_response)
\ No newline at end of file
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