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

Merging with master

parents 9c1fd25f e5e74568
......@@ -13,21 +13,25 @@ class Announcement(models.Model):
def __str__(self):
return '"{}" published {}'.format(self.announcement_title, self.pub_date)
class Reaction(models.Model):
announcement = models.ForeignKey(
Announcement,
on_delete=models.CASCADE,
related_name='reactions'
)
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [
('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGRY, 'Angry')
]
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default='Like'
default=LIKE
)
tally = models.IntegerField(default=1, editable=False)
......
from django.urls import path
from .views import index
from .views import announcement_list_view, announcement_detail_view
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"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
def index(request):
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
def announcement_list_view(request):
context = {}
context['object_list'] = Announcement.objects.order_by('-pub_date').all()
return render(request, 'announcementboard/announcement_list.html', context)
def announcement_detail_view(request, pk):
announcement = Announcement.objects.get(pk=pk)
context = {'announcement': announcement,
'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()
}
return render(request, 'announcementboard/announcement_detail.html', context)
\ 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
from . import views
urlpatterns = [
path('', views.index, name="index")
path('', views.index, name="assignment-list"),
path('<int:pk>/details', views.detail, name="assignment-detail"),
]
app_name = "assignments"
......@@ -5,18 +5,35 @@ from .models import Assignment, Course
# Create your views here.
def index(request):
heading = 'ASSIGNMENTS:<br><br>'
assignments = Assignment.objects.all()
body = ''
course_list = Course.objects.order_by("course_code")
assignments_list = Assignment.objects.order_by("name")
context = {
"course_list": course_list,
"assignments_list": assignments_list,
}
return render(request, "assignments/assignments_list.html", context)
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
)
# 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)
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 .views import index
from .views import post_list_view, post_detail_view
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'
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Post, Reply
def index(request):
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)
def post_list_view(request):
context = {}
context['post_list'] = Post.objects.order_by('-pub_date').all()
return render(request, 'forum/forum_list.html', context)
def post_detail_view(request, post_id):
post = Post.objects.get(id=post_id)
reply_list = Reply.objects.filter(original_post=post).order_by('-pub_date').all()
context = {'post': post,
'reply_list': reply_list
}
return render(request, 'forum/forum_details.html', context)
from django.urls import path
from .views import index
from homepage import views
urlpatterns = [
path('', index, name='index'),
path('', views.index, name='index'),
path('users/<str:user_id>/details', views.details, name='details'),
]
app_name = "homepage"
\ No newline at end of file
from re import A, template
from django.shortcuts import render
from django.template import loader
from django.http import HttpResponse
from .models import WidgetUser
# Create your views here.
def index(request):
model = WidgetUser
widget_users = model.objects.all()
homepage_response = "WIDGET USERS: </br>"
user_list = WidgetUser.objects.order_by("last_name")
template = loader.get_template("homepage/homepage.html")
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)
\ No newline at end of file
def details(request,user_id):
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