Commit 13d6fb18 authored by Rau Layug's avatar Rau Layug

Merging with master

parents 9c1fd25f e5e74568
...@@ -13,21 +13,25 @@ class Announcement(models.Model): ...@@ -13,21 +13,25 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return '"{}" published {}'.format(self.announcement_title, self.pub_date) return '"{}" published {}'.format(self.announcement_title, self.pub_date)
class Reaction(models.Model): class Reaction(models.Model):
announcement = models.ForeignKey( announcement = models.ForeignKey(
Announcement, Announcement,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='reactions' related_name='reactions'
) )
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [ REACTION_CHOICES = [
('Like', 'Like'), (LIKE, 'Like'),
('Love', 'Love'), (LOVE, 'Love'),
('Angry', 'Angry') (ANGRY, 'Angry')
] ]
reaction_name = models.CharField( reaction_name = models.CharField(
max_length=5, max_length=5,
choices=REACTION_CHOICES, choices=REACTION_CHOICES,
default='Like' default=LIKE
) )
tally = models.IntegerField(default=1, editable=False) tally = models.IntegerField(default=1, editable=False)
......
from django.urls import path from django.urls import path
from .views import index from .views import announcement_list_view, announcement_detail_view
urlpatterns = [ urlpatterns = [
path('', index, name='index') # path('', index, name='index')
path('', announcement_list_view, name='announcement-list'),
path('<int:pk>/details', announcement_detail_view, name='announcement-detail'),
] ]
app_name = "announcementboard" app_name = "announcementboard"
\ 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 from .models import Announcement
def index(request):
heading = 'ANNOUNCEMENTS:<br>' def announcement_list_view(request):
all_announcements = Announcement.objects.all() context = {}
body = '' context['object_list'] = Announcement.objects.order_by('-pub_date').all()
for announcement in all_announcements: return render(request, 'announcementboard/announcement_list.html', context)
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() def announcement_detail_view(request, pk):
body += '{} by {} {} dated {}:<br>{}<br>Like: {}<br>Love: {}<br>Angry: {}<br><br>'.format( announcement = Announcement.objects.get(pk=pk)
announcement.announcement_title, announcement.author.first_name, context = {'announcement': announcement,
announcement.author.last_name, announcement.pub_date, 'count_like': announcement.reactions.filter(reaction_name='Like').count(),
announcement.announcement_body, count_like, 'count_love': announcement.reactions.filter(reaction_name='Love').count(),
count_love, count_angry 'count_angry': announcement.reactions.filter(reaction_name='Angry').count()
) }
return HttpResponse(heading + body) return render(request, 'announcementboard/announcement_detail.html', context)
\ No newline at end of file \ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-15 09:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=50)),
('section', models.CharField(max_length=3)),
],
),
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(default=0)),
('passing_score', models.IntegerField(default=0, editable=False)),
('course_code', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
...@@ -3,7 +3,8 @@ from django.urls import path ...@@ -3,7 +3,8 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name="index") path('', views.index, name="assignment-list"),
path('<int:pk>/details', views.detail, name="assignment-detail"),
] ]
app_name = "assignments" app_name = "assignments"
...@@ -5,18 +5,35 @@ from .models import Assignment, Course ...@@ -5,18 +5,35 @@ from .models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
heading = 'ASSIGNMENTS:<br><br>' course_list = Course.objects.order_by("course_code")
assignments = Assignment.objects.all() assignments_list = Assignment.objects.order_by("name")
body = '' context = {
"course_list": course_list,
"assignments_list": assignments_list,
}
return render(request, "assignments/assignments_list.html", context)
for assignment in assignments: # heading = 'ASSIGNMENTS:<br><br>'
courses = Course.objects.filter(course_code__exact=assignment.course_code) # assignments = Assignment.objects.all()
body += 'Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>'.format( # body = ''
assignment.name, assignment.description, assignment.max_points, assignment.passing_score #
) # for assignment in assignments:
for course in courses: # courses = Course.objects.filter(course_code__exact=assignment.course_code)
body += 'Course/Section: {} {} {}<br><br>'.format( # body += 'Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>'.format(
course.course_code, course.course_title, course.section # 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)
return HttpResponse(heading + body) def detail(request, pk):
assignment = Assignment.objects.get(pk=pk)
course = Course.objects.get(course_code__exact=assignment.course_code)
context = {
"assignment": assignment,
"course": course,
}
return render(request, "assignments/assignments_detail.html", context)
# Generated by Django 4.0.3 on 2022-05-15 18:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendarapp', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='location',
name='image',
field=models.ImageField(default='temp', upload_to='uploads/'),
preserve_default=False,
),
]
from django.urls import path from django.urls import path
from .views import index from .views import post_list_view, post_detail_view
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', post_list_view, name='post-list'),
path('<int:post_id>/details', post_detail_view, name='post-details'),
] ]
app_name = 'forum' app_name = 'forum'
\ 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 django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Post, Reply from .models import Post, Reply
def index(request):
heading = 'FORUM POSTS:<br>' def post_list_view(request):
posts = Post.objects.all() context = {}
body = '' context['post_list'] = Post.objects.order_by('-pub_date').all()
for post in posts: return render(request, 'forum/forum_list.html', context)
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, def post_detail_view(request, post_id):
post.pub_date, post.post_body post = Post.objects.get(id=post_id)
) reply_list = Reply.objects.filter(original_post=post).order_by('-pub_date').all()
for post_reply in post_replies: context = {'post': post,
body += 'Reply by {} {} dated {}:<br>{}<br>'.format( 'reply_list': reply_list
post_reply.author.first_name, post_reply.author.last_name, }
post_reply.pub_date, post_reply.reply_body return render(request, 'forum/forum_details.html', context)
)
body += '<br>'
return HttpResponse(heading + body)
from django.urls import path from django.urls import path
from homepage import views
from .views import index
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', views.index, name='index'),
path('users/<str:user_id>/details', views.details, name='details'),
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from re import A, template
from django.shortcuts import render from django.shortcuts import render
from django.template import loader
from django.http import HttpResponse 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):
model = WidgetUser user_list = WidgetUser.objects.order_by("last_name")
widget_users = model.objects.all() template = loader.get_template("homepage/homepage.html")
homepage_response = "WIDGET USERS: </br>" context = {
"user_list" : user_list,
}
return HttpResponse(template.render(context,request))
for user in widget_users:
homepage_response += user.get_user_info()
return HttpResponse(homepage_response) def details(request,user_id):
\ No newline at end of file user = WidgetUser.objects.get(id_num=user_id)
template = loader.get_template("homepage/details.html")
context = {
"user" : user,
}
return HttpResponse(template.render(context,request))
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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