Commit d74f3357 authored by Pierre Ashley Salcedo's avatar Pierre Ashley Salcedo

Merge branch 'master' into salcedo/homepage

parents e7be278c 4ee1db9b
No preview for this file type
from django.contrib import admin from django.contrib import admin
from .models import Announcement from .models import Announcement, Reaction
# Register your models here. # Register your models here.
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
admin.site.register(Announcement) admin.site.register(Announcement)
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Reaction)
# Generated by Django 3.2.12 on 2022-04-07 16:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(choices=[('LV', 'Love'), ('LK', 'Like'), ('AG', 'Angry')], default=None, max_length=2)),
('tally', models.IntegerField()),
],
),
migrations.AddField(
model_name='announcement',
name='reaction',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.reaction'),
),
]
# Generated by Django 3.2.12 on 2022-04-07 17:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_auto_20220407_0505'),
('announcements', '0002_auto_20220407_1634'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='reaction_name',
field=models.CharField(choices=[('Love', 'Love'), ('Like', 'Like'), ('Angry', 'Angry')], default=None, max_length=5),
),
]
# Generated by Django 3.2.12 on 2022-04-07 19:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_auto_20220407_1707'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
# Generated by Django 3.2.12 on 2022-04-08 02:38
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_auto_20220407_1942'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='tally',
),
]
# Generated by Django 3.2.12 on 2022-04-08 03:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_remove_reaction_tally'),
]
operations = [
migrations.AddField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Announcement(models.Model): class Announcement(models.Model):
announcement_title = models.CharField(max_length=100) announcement_title = models.CharField(max_length=100)
announcement_body = models.CharField(max_length=1000) announcement_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField('date published') pub_date = models.DateTimeField('date published')
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
default=None,
null=True
)
def __str__(self): def __str__(self):
return self.announcement_title return self.announcement_title
class Reaction(models.Model):
LOVE = 'Love'
LIKE = 'Like'
ANGRY = 'Angry'
REACTION_CHOICES = [
(LOVE, 'Love'),
(LIKE, 'Like'),
(ANGRY, 'Angry'),
]
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default=None,
)
announcement = models.ForeignKey(
'Announcement',
on_delete=models.CASCADE,
null=True,
)
tally = models.IntegerField(default=0)
def __str__(self):
return self.reaction_name
def count(self):
return self.tally
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request): def index(request):
return HttpResponse('This is the Announcement Board!') announcement = Announcement.objects.all()
html = '<html><body><h3>ANNOUNCEMENT POSTS:</h3>'
for a in announcement:
html += "{} by {} {} dated {}:<br>{}<br>".format(
a.announcement_title,
a.author.first_name,
a.author.last_name,
a.pub_date,
a.announcement_body,
)
reaction = Reaction.objects.filter(announcement=a.id)
html += "Like: {}<br>Love: {}<br>Angry: {}".format(
reaction.filter(reaction_name__exact="Like").count,
reaction.filter(reaction_name__exact="Love").count,
reaction.filter(reaction_name__exact="Angry").count,
)
html += '<br>'
html += '</body></html>'
return HttpResponse(html)
...@@ -2,6 +2,8 @@ from pyexpat import model ...@@ -2,6 +2,8 @@ from pyexpat import model
from django.db import models from django.db import models
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
course_code = models.CharField(max_length=10) course_code = models.CharField(max_length=10)
......
h1{
color: purple;
font-weight: bold;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
p, ul{
color: darkolivegreen;
font-size: 24px;
margin-bottom: 15px;
display: block;
text-align: justify;
font-family: Georgia, 'Times New Roman', Times, serif;
}
body{
background-color: rgb(255, 225, 182);
}
a{
color: blueviolet;
}
a:visited{
color: brown;
}
a:hover{
color: orangered;
}
img{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
{% load static %}
<!DOCTYPE html>
<html lang ="en">
<head>
<link rel ="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name ="viewport" content="width-device width, initial scale=1.0">
<title>Assignments</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "assignments/base.html" %}
{% load static %}
{% block content %}
<h1> {{assignment.course.course_code}} {{assignment.course.course_title}} {{assignment.course.section}} </h1>
<p>
{{assignment.name}} <br>
{{assignment.description}} <br>
{{assignment.max_points}} <br>
{{assignment.passing_score}} <br>
{% if assignment.id == 1 %}
<img src = "{% static 'assignments/images/history.jpg' %}" alt = "history">
{% elif assignment.id == 2 %}
<img src = "{% static 'assignments/images/koreanlang.png' %}" alt = "korean speaking">
{% else %}
<img src = "{% static 'assignments/images/yoga.jpg' %}" alt = "yoga">
{% endif %}
</p>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html> {% extends "assignments/base.html" %}
<html>
<head></head> {% block content %}
<body> <h1> Assignments Per Course </h1>
<h1> ASSIGNMENTS: </h1>
{% for assignment in assignment_entries %}
<p> <p>
Assignment Name: {{assignment.name}}<br> List of All Courses: <br>
Description: {{assignment.description}}<br> {% for course in course_list %}
Perfect Score: {{assignment.max_points}}<br> <ul>
Passing Score: {{assignment.passing_score}}<br> <li>{{course.course_code}} {{course.course_title}} {{course.section}} </li>
Course/Section: {{assignment.course.course_code}} {{assignment.course.course_title}} | {{assignment.course.section}}
</p> {% for assignment in course.assignment_set.all %}
<ul>
<li> <a href = "{% url 'assignments:detail' assignment.id %}"> {{assignment.name}} </a> </li>
</ul>
{% endfor %}
</ul>
{% endfor %} {% endfor %}
</p>
{% endblock %}
</body>
</html>
from django.urls import path from django.urls import path, include
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name = 'index'), path('', views.index, name = 'index'),
#assignments/1/details
path("<int:assignment_id>/details/", views.detail, name='detail'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse from unicodedata import name
from django.template import loader from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect
from .models import Course, Assignment from .models import Course, Assignment
# Create your views here. # Create your views here.
def index(request): def index(request):
assignments = Assignment.objects.all() course_list = Course.objects.order_by("course_code")
template = loader.get_template('assignments/index.html')
context = { context = {
'assignment_entries': assignments 'course_list': course_list
} }
return HttpResponse(template.render(context, request)) return render(request, "assignments/index.html", context)
def detail(request, assignment_id):
try:
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
return render(request, "assignments/detail.html", {"assignment": assignment})
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from .models import Post from .models import Post, Reply
# Register your models here. # Register your models here.
admin.site.register(Post) admin.site.register(Post)
admin.site.register(Reply)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-07 17:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_auto_20220407_0505'),
('forum', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=10000)),
('pub_date', models.DateTimeField(verbose_name='date published')),
('author', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
('reply_post', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.post')),
],
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
...@@ -6,6 +7,16 @@ class Post(models.Model): ...@@ -6,6 +7,16 @@ class Post(models.Model):
post_title = models.CharField(max_length=100) post_title = models.CharField(max_length=100)
post_body = models.CharField(max_length=10000) post_body = models.CharField(max_length=10000)
pub_date = models.DateTimeField('date published') pub_date = models.DateTimeField('date published')
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE, default=None, null=True)
def __str__(self): def __str__(self):
return self.post_title return self.post_title
class Reply(models.Model):
reply_body = models.CharField(max_length=10000)
pub_date = models.DateTimeField('date published')
reply_post = models.ForeignKey(Post, on_delete=models.CASCADE, default=None, null=True)
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE, default=None, null=True)
def __str__(self):
return 'Reply to: {}' .format(self.reply_post)
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget's Forum!") post_data = Post.objects.all()
\ No newline at end of file
html = '<html><body><h3>FORUM POSTS:</h3>'
for a in post_data:
html += "{} by {} {} dated {}:<br>{}<br>".format(
a.post_title,
a.author.first_name,
a.author.last_name,
a.pub_date,
a.post_body
)
reply_data = Reply.objects.filter(reply_post=a.id)
for b in reply_data:
html += "Reply by {} {} dated {}:<br>{}<br>".format(
b.author.first_name,
b.author.last_name,
b.pub_date,
b.reply_body
)
html += '<br>'
html += '</body></html>'
return HttpResponse(html)
\ 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