Commit 4990f64f authored by Miguel Luis D. Bandelaria's avatar Miguel Luis D. Bandelaria

update: transferred some files into the static folder and resolved cache issues

parents dbe52d97 1bb55877
...@@ -18,4 +18,7 @@ LAB 1 ...@@ -18,4 +18,7 @@ LAB 1
https://drive.google.com/file/d/1h7ZKUgOm05asADkjp_4TqzfbnsMjiszC/view?usp=sharing https://drive.google.com/file/d/1h7ZKUgOm05asADkjp_4TqzfbnsMjiszC/view?usp=sharing
LAB 2 LAB 2
https://drive.google.com/file/d/1vxanijE64BhKiguSCyYZRtvO4vT7x44i/view?usp=sharing https://drive.google.com/file/d/1vxanijE64BhKiguSCyYZRtvO4vT7x44i/view?usp=sharing
\ No newline at end of file
LAB 3
https://drive.google.com/file/d/1ZEtiJNDHxrIiPe88rekPPwjKmwHVC7aQ/view?usp=sharing
\ No newline at end of file
from django.forms import ModelForm
from .models import WidgetUser, Announcement, Reaction
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = [
"announcement_title",
"announcement_body",
"author",
"image",
]
# Generated by Django 4.0.3 on 2022-05-17 15:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0002_announcement_author_reaction'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='image',
field=models.FileField(null=True, upload_to='static/'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 05:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_announcement_image'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='image',
field=models.FileField(null=True, upload_to='static/announcements'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 06:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_alter_announcement_image'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(null=True, verbose_name='date published'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 06:55
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(default=django.utils.timezone.now, null=True, verbose_name='date published'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 07:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0009_alter_widgetuser_profile_url'),
('announcements', '0006_alter_announcement_pub_date'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 07:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0009_alter_widgetuser_profile_url'),
('announcements', '0007_alter_announcement_author'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
# Generated by Django 4.0.3 on 2022-05-21 07:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0008_alter_announcement_author'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='image',
field=models.FileField(blank=True, null=True, upload_to='static/announcements'),
),
]
from django.db import models from django.db import models
from django.utils import timezone
from homepage.models import WidgetUser from homepage.models import WidgetUser
import os
Like = 'Like' Like = 'Like'
Love = 'Love' Love = 'Love'
...@@ -7,12 +9,23 @@ Angry = 'Angry' ...@@ -7,12 +9,23 @@ Angry = 'Angry'
REACTION_CHOICES = ((Like, 'Like'), (Love, 'Love'), (Angry, 'Angry')) REACTION_CHOICES = ((Like, 'Like'), (Love, 'Love'), (Angry, 'Angry'))
# Create your models here. # Create your models here.
class Announcement(models.Model): class Announcement(models.Model):
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True, blank=True, default=None)
announcement_title = models.CharField(max_length=50) announcement_title = models.CharField(max_length=50)
announcement_body = models.CharField(max_length=500) announcement_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published", default=timezone.now, null=True)
image = models.FileField(upload_to='static/announcements', null=True, blank=True)
def __str__(self):
return self.announcement_title
def file(self):
value = os.path.basename(self.image.name)
return value
class Reaction(models.Model): class Reaction(models.Model):
reaction_name = models.CharField(max_length=10, choices=REACTION_CHOICES, default=Like) reaction_name = models.CharField(max_length=10, choices=REACTION_CHOICES, default=Like)
tally = models.IntegerField(default = 0) tally = models.IntegerField(default = 0)
announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE) announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE)
def __str__(self):
return self.reaction_name
p{
color: black;
font-weight: bold;
font-family: Helvetica;
font-size:25px;
}
h1 {
position: sticky;
text-align: left;
color: black;
font-size: 55px;
font-family: Helvetica;
}
body {
background-image: url("/static/announcements/bg.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
font-family: Helvetica;
}
a{
color: black;
font-family: Helvetica;
font-weight: bold;
}
ol {
font-size:35px;
font-family: Helvetica;
color:black;
font-weight: bold;
}
a:link {
text-decoration: none;
}
img{
position: relative;
top: 150px;
}
{% extends "announcements/base.html" %}
{% block page-title %}Add New Announcement{% endblock %}
{% block content %}
<form method="POST" action="{% url 'announcements:add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ announcement_form.as_p }}
<button class="button" type="submit">Save Announcement</button>
<button onclick="location.href = '/announcements'">Return to Announcements Page</button>
</form>
{% endblock %}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css"
href="{% static 'announcements/style.css' %}">
<title>{% block page-title %}{% endblock %}</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block page-title %}Announcements Page{% endblock %}
{% block content %}
<head>
<h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author.first_name }} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"d-m-Y" }}</h2>
</head>
<body>
<p>{{ announcement.announcement_body }}</p>
<p>Like: {{ like_tally }}</p>
<p>Love: {{ love_tally }}</p>
<p>Angry: {{ angry_tally }}</p>
<img src = "../../static/announcements/{{ announcement.file }}" width="400" height="200">
</body>
{% endblock %}
{% extends "announcements/base.html" %}
{% block page-title %}Announcements Page{% endblock %}
{% block content %}
<h1>Announcement Board</h1>
<body>
<p>Important announcements:</p>
<ul>
{% for announcement in announcements_list %}
<li><a href="{% url 'announcements:detail' announcement.id %}">
{{ announcement.announcement_title }}
by {{ announcement.author.first_name }} {{ announcement.author.last_name }}
dated {{ announcement.pub_date|date:"d-m-Y" }}
</a>
</li>
{% endfor %}
</ul>
<form method="get" action="add/">
<button type="submit">New Announcement</button>
</form>
</body>
{% endblock %}
from django.urls import path from django.urls import path
from . import views from . import views
app_name = "announcements"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.IndexView.as_view(), name='index'),
path('welcome', views.welcome, name='welcome') path('add/', views.add, name='add'),
path('<int:announcement_id>/details', views.detail, name="detail")
#path('welcome', views.welcome, name='welcome')
] ]
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render import datetime
from django.shortcuts import render, redirect
from .models import WidgetUser, Announcement, Reaction from .models import WidgetUser, Announcement, Reaction
from .forms import AnnouncementForm
from django.template import loader
from django.views import View
# Create your views here. # Create your views here.
def welcome(request): class IndexView(View):
return HttpResponse("This is the Announcement Board!") def get(self,request):
announcements_list = Announcement.objects.all().order_by("pub_date")
return render(request, "announcements/index.html", {"announcements_list":announcements_list})
'''
def index(request): def index(request):
announcement_view = 'ANNOUNCEMENTS: ' announcements_list = Announcement.objects.all().order_by("pub_date")
announcements = Announcement.objects.all() #template = loader.get_template("announcements/index.html")
reactions = Reaction.objects.all() context = {
"announcements_list":announcements_list
}
return render(request, "announcements/index.html", context)
'''
#HttpResponse(template.render(context, request))
for a in announcements: def detail(request, announcement_id):
like_tally=0 try:
love_tally=0 announcement = Announcement.objects.get(pk=announcement_id)
angry_tally=0 reaction_list = Reaction.objects.all()
for r in reactions: except Announcement.DoesNotExist:
if r.reaction_name=="Like" and r.announcement==a: raise Http404("Announcement does not exist!")
like_tally+=r.tally like_tally = 0
elif r.reaction_name=="Love" and r.announcement==a: love_tally = 0
love_tally+=r.tally angry_tally = 0
elif r.reaction_name=="Angry" and r.announcement==a: for r in reaction_list:
angry_tally+=r.tally if r.reaction_name == "Like" and r.announcement == announcement:
announcement_view += "<br/> {} by {} {} dated {}: <br/> {} <br/> Like: {} <br/> Love: {} <br/> Angry: {} <br/>".\ like_tally += r.tally
format(a.announcement_title, elif r.reaction_name == "Love" and r.announcement == announcement:
a.author.first_name, love_tally += r.tally
a.author.last_name, elif r.reaction_name == "Angry" and r.announcement == announcement:
a.pub_date, angry_tally += r.tally
a.announcement_body,
like_tally,
love_tally,
angry_tally)
return HttpResponse(announcement_view) context = {
"announcement": announcement,
"like_tally": like_tally,
"love_tally": love_tally,
"angry_tally": angry_tally
}
return render(request, "announcements/details.html", context)
def add(request):
if request.method == "POST":
announcement_form = AnnouncementForm(request.POST, request.FILES)
if announcement_form.is_valid():
new_announcement = announcement_form.save()
return redirect("announcements:add")
else:
announcement_form = AnnouncementForm()
return render(request, "announcements/add.html", {"announcement_form":announcement_form})
# Code from previous lab activities:
# def welcome(request):
# return HttpResponse("This is the Announcement Board!")
# announcement_view = 'ANNOUNCEMENTS: '
# announcements = Announcement.objects.all()
# reactions = Reaction.objects.all()
#
# like_tally=0
# love_tally=0
# angry_tally=0
# for r in reactions:
# if r.reaction_name=="Like" and r.announcement==a:
# like_tally+=r.tally
# elif r.reaction_name=="Love" and r.announcement==a:
# love_tally+=r.tally
# elif r.reaction_name=="Angry" and r.announcement==a:
# angry_tally+=r.tally
# announcement_view += "<br/> {} by {} {} dated {}: <br/> {} <br/> Like: {} <br/> Love: {} <br/> Angry: {} <br/>".\
# format(a.announcement_title,
# a.author.first_name,
# a.author.last_name,
# a.pub_date,
# a.announcement_body,
# like_tally,
# love_tally,
# angry_tally)
#
# return HttpResponse(announcement_view)
# Generated by Django 3.2.12 on 2022-05-18 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0004_auto_20220406_0329'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/'),
),
]
# Generated by Django 3.2.12 on 2022-05-19 01:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0005_assignment_image'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/assignments/'),
),
]
from django.db import models from django.db import models
import os
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -12,8 +13,11 @@ class Assignment(models.Model): ...@@ -12,8 +13,11 @@ class Assignment(models.Model):
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0) passing_score = models.IntegerField(default=0)
image = models.FileField(upload_to='static/assignments/', null=True)
def _str_(self): def _str_(self):
return self.name return self.name
def file(self):
\ No newline at end of file value = os.path.basename(self.image.name)
return value
\ No newline at end of file
h1 {
position: sticky;
text-align: center;
color: purple;
font-size: 55px;
font-family: Georgia;
}
h2 {
color: purple;
font-size: 30px;
font-family: Georgia;
}
h3 {
color: black;
font-weight: bold;
font-family: Courier New;
font-size:25px;
}
p{
color: black;
font-family: Helvetica;
font-size:20px;
}
body {
background-color: white;
}
a{
color: blue;
font-family: Courier New;
font-size: 20px;
font-weight: bold;
}
a:link {
text-decoration: underline;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css"
href="{% static 'assignments/style.css' %}">
<title>{% block page-title %}{% endblock %}</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "assignments/base.html" %}
{% block page-title %}Assignment {{ assignment_id }} Details{% endblock %}
{% block content %}
<h1>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h1>
<h3>{{ assignment.name }}</h3>
<p>Description: {{ assignment.description }}</p>
<p>Perfect Score: {{ assignment.max_points }}</p>
<p>Passing Score: {{ assignment.passing_score }}</p>
<img src="/static/assignments/{{ assignment.file }}" width="250" height="250">
{% endblock %}
\ No newline at end of file
{% extends "assignments/base.html" %}
{% block page-title %}Assignments Per Course{% endblock %}
{% block content %}
<h1>Assignments Per Course</h1>
<h2>List of courses:</h2>
{% if course_list %}
<ul>
{% for course in course_list %}
<li><h3>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h3></li>
<ul>
{% for assignment in assignment_list %}
{% if assignment.course == course %}
<li><a href="{% url 'assignments:details' assignment.id %}">{{ assignment.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</ul>
{% else %}
<p>No course available.</p>
{% endif %}
{% endblock %}
\ No newline at end of file
...@@ -2,6 +2,10 @@ from django.urls import path ...@@ -2,6 +2,10 @@ from django.urls import path
from . import views from . import views
app_name = "assignments"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') # assignments/
path('', views.index, name='index'),
# assignments/<assignment_id>/details/
path('<int:assignment_id>/details/', views.details, name='details'),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from assignments.models import Assignment, Course from assignments.models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
assignments_view = "ASSIGNMENTS: <br>" course_list = Course.objects.order_by("course_code")
schoolwork = Assignment.objects.all() assignment_list = Assignment.objects.all()
for assignment in schoolwork: context = {
score = assignment.max_points "course_list" : course_list,
assignment.passing_score = (score*60) // 100 "assignment_list" : assignment_list,
assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\ }
format(assignment.name, return render(request, "assignments/index.html", context)
assignment.description,
assignment.max_points, def details(request, assignment_id):
assignment.passing_score, try:
assignment.course.course_code, assignment = Assignment.objects.get(pk=assignment_id)
assignment.course.course_title, except Assignment.DoesNotExist:
assignment.course.section) raise Http404("Assignment does not exist.")
return HttpResponse(assignments_view) score = assignment.max_points
\ No newline at end of file assignment.passing_score = (score*60) // 100
context = {
"assignment" : assignment,
"course" : assignment.course,
}
return render(request, "assignments/details.html", context)
# Code from previous labs:
#
# def index(request):
# assignments_view = "ASSIGNMENTS: <br>"
# schoolwork = Assignment.objects.all()
# for assignment in schoolwork:
# score = assignment.max_points
# assignment.passing_score = (score*60) // 100
# assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\
# format(assignment.name,
# assignment.description,
# assignment.max_points,
# assignment.passing_score,
# assignment.course.course_code,
# assignment.course.course_title,
# assignment.course.section)
#
# return HttpResponse(assignments_view)
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" <link rel="stylesheet" type="text/css"
href="{% static 'style.css' %}"> href="{% static 'forum/style.css' %}">
<title>{% block page-title %}{% endblock %}</title> <title>{% block page-title %}{% endblock %}</title>
</head> </head>
<body> <body>
......
{% extends "base.html" %} {% extends "forum/base.html" %}
{% block page-title %}Details{% endblock %} {% block page-title %}Details{% endblock %}
......
{% extends "base.html" %} {% extends "forum/base.html" %}
{% block page-title %}Forum Posts{% endblock %} {% block page-title %}Forum Posts{% endblock %}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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