Commit 0405a2b7 authored by Nicolas Reichert's avatar Nicolas Reichert

finalized announcements

parents 24cf7409 8742ae46
# Generated by Django 4.0.3 on 2022-05-19 17:30
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_reaction_reaction_name'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reacts', to='announcements.announcement'),
),
]
# Generated by Django 3.2.12 on 2022-05-23 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_alter_reaction_announcement'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='image',
field=models.ImageField(default=1, upload_to='announcements/'),
preserve_default=False,
),
]
...@@ -11,6 +11,7 @@ class Announcement(models.Model): ...@@ -11,6 +11,7 @@ class Announcement(models.Model):
on_delete=models.CASCADE on_delete=models.CASCADE
) )
image = models.ImageField(upload_to='announcements/')
def __str__(self): def __str__(self):
return '{}'.format(self.announcement_title) return '{}'.format(self.announcement_title)
...@@ -44,7 +45,7 @@ class Reaction(models.Model): ...@@ -44,7 +45,7 @@ class Reaction(models.Model):
@property @property
def reaction_detail(self): def reaction_detail(self):
reaction = '<br>{}: {}'.format(self.reaction_name, self.tally) reaction = '{}: {}'.format(self.reaction_name, self.tally)
return reaction return reaction
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/announcements_stylesheet.css' %}">
{% endblock %}
{% block app_header %}Announcement Board{% endblock %}
{% block content %}
<p class="head">Important announcements:</p>
<ul class="announcements">
{% for a in announcement_list %}
<li>
<a href="{% url 'announcements:announcement-detail' pk=a.pk %}">
<p><span class="title">{{ a.announcement_title }}</span> <br/> by <span class="author">{{ a.author.first_name }} {{ a.author.last_name }}</span> dated {{ a.pub_date|date:"d/m/Y" }}</p>
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/announcements_stylesheet.css' %}">
{% endblock %}
{% block content %}
<h3>{{ object.announcement_title }}</h3>
<h2 class="subtitle">by {{ object.author.first_name }} {{ object.author.last_name }}, {{ object.pub_date|date:"d/m/Y" }}</h2>
<p>{{ object.announcement_body }}</p>
<div class="reactions">
{% for r in object.reacts.all %}
<p class="reaction">{{ r.reaction_detail }} </p>
{% endfor %}
</div>
<img src= "{{ object.image.url }}">
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import AnnouncementPageView, AnnouncementDetailView
urlpatterns = [ urlpatterns = [
path('', index, name="index"), path('', AnnouncementPageView.as_view(), name='index'),
path('announcement/<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-detail'),
] ]
app_name = "announcements" app_name = "announcements"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views import View
from django.views.generic.detail import DetailView
from .models import Announcement, Reaction from .models import Announcement, Reaction
# Create your views here. # Create your views here.
def index(request): class AnnouncementPageView(View):
def announcement_list(): def get(self, request):
final_list = '' return render(request, 'announcements/announcement.html', {
for p in range(len(Announcement.objects.all())): 'announcement_list': Announcement.objects.all().order_by('-id'),
final_list += '{}'.format(Announcement.objects.get(pk=p+1).announcement_detail) 'reaction_list': Reaction.objects.all().order_by('-id')
reaction_list = list(Reaction.objects.filter(announcement=Announcement.objects.get(pk=p+1))) })
lk_tally = 0
lv_tally = 0
ag_tally = 0
for r in range(len(reaction_list)):
if str(reaction_list[r]) == 'LK':
lk_tally += reaction_list[r].reaction_tally
elif str(reaction_list[r]) == 'LV':
lv_tally += reaction_list[r].reaction_tally
elif str(reaction_list[r]) == 'AG':
ag_tally += reaction_list[r].reaction_tally
final_list += f'<br>Like: {lk_tally}'
final_list += f'<br>Love: {lv_tally}'
final_list += f'<br>Angry: {ag_tally}<br>'
return final_list
html = f''' class AnnouncementDetailView(DetailView):
<html> model = Announcement
<body>
<h1>ANNOUNCEMENTS:</h1>
<main>
<p>{announcement_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-19 15:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_assignment_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.ImageField(default=1, upload_to='images'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-05-19 17:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0004_assignment_image'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='image',
field=models.ImageField(upload_to='assignments/'),
),
]
...@@ -24,19 +24,11 @@ class Assignment(models.Model): ...@@ -24,19 +24,11 @@ class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE) course = models.ForeignKey(Course, on_delete = models.CASCADE)
image = models.ImageField(upload_to='assignments/')
@property @property
def passing_score(self): def passing_score(self):
return self.max_points * 0.60 return self.max_points * 0.60
@property
def assignment_info(self):
assignment = '<br>Assignment Name: {}'.format(self.name)
assignment += '<br>Description: {}'.format(self.description)
assignment += '<br>Perfect Score: {}'.format(self.max_points)
assignment += '<br>Passing Score: {}'.format(self.passing_score)
assignment += '<br>Course/Section: {}<br>'.format(self.course.course_info)
return assignment
def __str__(self): def __str__(self):
return '{} - {}'.format(self.name, self.course.course_shorthand) return '{} - {}'.format(self.name, self.course.course_shorthand)
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/assignments_stylesheet.css' %}">
{% endblock %}
{% block app_header %}Assignments Per Course{% endblock %}
{% block content %}
<ul>
{% for c in course_list|dictsort:"course_code" %}
<li><p class="course_section">{{ c.course_code }} {{ c.course_title }} {{ c.section }}</p>
<ul class="course_assignments">
{% for a in assignment_list %}
{% if a.course.course_code == c.course_code %}
{% if a.course.section == c.section %}
<li><a href="{% url 'assignments:assignment-detail' pk=a.pk %}">{{ a.name }}</a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/assignments_stylesheet.css' %}">
{% endblock %}
{% block content %}
<p class="course">{{ object.course.course_code }} {{ object.course.course_title }} {{ object.course.section }}</p>
<p class="title">{{ object.name }}</p>
<img src= "{{ object.image.url }}">
<div class="assign_details">
<p class="desc">{{ object.description }}</p>
<p class="score">Perfect Score: {{ object.max_points }}</p>
<p class="score">Passing Score: {{ object.passing_score }}</p>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import AssignmentsPageView, AssignmentDetailView
urlpatterns = [ urlpatterns = [
path('', index, name="index"), path('', AssignmentsPageView.as_view(), name='index'),
path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-detail'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views import View
from django.views.generic.detail import DetailView
from .models import Assignment, Course
from .models import Assignment from .models import Assignment
# Create your views here. # Create your views here.
def index(request): class AssignmentsPageView(View):
def assignment_list(): def get(self, request):
final_list = '' return render(request, 'assignments/assignment.html', {
for a in range(len(Assignment.objects.all())): 'course_list': Course.objects.all(),
final_list += '{}'.format(Assignment.objects.get(pk=a+1).assignment_info) 'assignment_list': Assignment.objects.all()
})
return final_list
html = f'''
<html>
<body>
<header><h1>ASSIGNMENTS:</h1><header>
<main>
<p>{assignment_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html) class AssignmentDetailView(DetailView):
\ No newline at end of file model = Assignment
# Generated by Django 4.0.3 on 2022-05-18 05:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0010_alter_post_pub_date_alter_reply_pub_date'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='reply',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
]
# Generated by Django 4.0.3 on 2022-05-19 16:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0011_alter_post_pub_date_alter_reply_pub_date'),
]
operations = [
migrations.AddField(
model_name='post',
name='image',
field=models.ImageField(default=1, upload_to='images/'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-05-19 17:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0012_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='image',
field=models.ImageField(upload_to='forum/'),
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500) post_body = models.CharField(max_length=500)
pub_date = models.DateField(auto_now=True) pub_date = models.DateTimeField(auto_now=True)
author = models.ForeignKey( author = models.ForeignKey(
'homepage.WidgetUser', 'homepage.WidgetUser',
on_delete=models.CASCADE on_delete=models.CASCADE
) )
image = models.ImageField(upload_to="forum/")
def __str__(self): def __str__(self):
return '{}'.format(self.post_title) return '{}'.format(self.post_title)
...@@ -26,7 +25,7 @@ class Post(models.Model): ...@@ -26,7 +25,7 @@ class Post(models.Model):
class Reply(models.Model): class Reply(models.Model):
reply_body = models.CharField(max_length=500) reply_body = models.CharField(max_length=500)
pub_date = models.DateField(auto_now=True) pub_date = models.DateTimeField(auto_now=True)
author = models.ForeignKey( author = models.ForeignKey(
'homepage.WidgetUser', 'homepage.WidgetUser',
on_delete=models.CASCADE on_delete=models.CASCADE
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/forum_stylesheet.css' %}">
{% endblock %}
{% block app_header %}Welcome to Widget's Forum!{% endblock %}
{% block content %}
<ul class="posts">
{% for p in post_list %}
<li>
<a href="{% url 'forum:post-detail' pk=p.pk %}">
<p><span class="title">{{ p.post_title }}</span> <br/> by <span class="author">{{ p.author.first_name }} {{ p.author.last_name }}</span> dated {{ p.pub_date|date:"d/m/Y" }}</p>
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/forum_stylesheet.css' %}">
{% endblock %}
{% block content %}
<div class="wrapper">
<div class="post">
<h1>{{ object.post_title }}</h1>
<h2>by {{ object.author.first_name }} {{ object.author.last_name }}, {{ object.pub_date|date:"d/m/Y" }}</h2>
<p>{{ object.post_body }}</p>
<img src="{{ object.image.url }}">
</div>
<ul class="replies">
{% for r in object.comments.all %}
<li>
<p><span class="author">{{ r.author.first_name }} {{ r.author.last_name }}</span>, {{ r.pub_date|date:"d/m/Y" }}: {{ r.reply_body }}</p>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import ForumPageView, PostDetailView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', ForumPageView.as_view(), name='index'),
path('post/<int:pk>/details', PostDetailView.as_view(), name='post-detail'),
] ]
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.views import View
from django.views.generic.detail import DetailView
from .models import Post, Reply from .models import Post, Reply
# Create your views here. # Create your views here.
def index(request): class ForumPageView(View):
def post_list(): def get(self, request):
final_list = '' return render(request, 'forum/forum.html', {
for p in range(len(Post.objects.all())): 'post_list': Post.objects.all().order_by('-id'),
final_list += '{}'.format(Post.objects.get(pk=p+1).post_detail) 'reply_list': Reply.objects.all().order_by('-id')
reply_list = list(Reply.objects.filter(post__exact=Post.objects.get(pk=p+1))) })
for r in range(len(reply_list)):
final_list += '{}'.format(reply_list[r].reply_detail)
final_list += '<br>'
return final_list
html = f'''
<html>
<body>
<h1>FORUM POSTS:</h1>
<main>
<p>{post_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html) class PostDetailView(DetailView):
model = Post
...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_group_23.urls' ...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_group_23.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], 'DIRS': [os.path.join(BASE_DIR, 'widget_group_23/templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
...@@ -124,6 +124,12 @@ USE_TZ = True ...@@ -124,6 +124,12 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.0/howto/static-files/ # https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'widget_group_23/static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'widget_group_23/staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'widget_group_23/media')
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
......
body {
background-color: #f8e2e2;
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
header {
font-size: 32px;
font-weight: bold;
margin: 32px 0px 32px 0px;
text-align: center;
}
img {
height: 50%;
width: 50%;
}
h3 {
font-size: 36px;
}
.head {
font-size: 24px;
margin: 32px 0px 32px 0px;
text-align: center;
}
.author {
font-weight: bold;
}
.announcement {
background-color: #FFF;
border-radius: 8px;
padding: 32px;
}
.announcements {
margin: 0 auto;
padding-left: 0px;
width: 80%;
}
.announcements li {
list-style: none;
margin-bottom: 24px;
}
.announcements li a {
color: #222;
line-height: 175%;
text-decoration:none;
}
.announcements li a:hover {
color: cornflowerblue !important;
}
.announcements li a p {
background-color: #FFF;
border-radius: 8px;
padding: 32px 24px 32px 24px;
}
.title {
font-size: 20px;
font-weight: bold;
}
\ No newline at end of file
body {
font-family: Tahoma, sans-serif;
}
header {
font-size: 25px;
font-weight: bold;
}
.course_section {
font-weight: bold;
}
.course, .title {
font-weight: bold;
}
\ No newline at end of file
body {
background-color: #EDEDED;
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
header {
font-size: 32px;
font-weight: bold;
margin: 32px 0px 32px 0px;
text-align: center;
}
img {
height: 50%;
width: 50%;
}
.author {
font-weight: bold;
}
.post {
background-color: #FFF;
border-radius: 8px;
padding: 32px;
}
.posts {
margin: 0 auto;
padding-left: 0px;
width: 80%;
}
.posts li {
list-style: none;
margin-bottom: 24px;
}
.posts li a {
color: #222;
line-height: 175%;
text-decoration:none;
}
.posts li a:hover {
color: cornflowerblue !important;
}
.posts li a p {
background-color: #FFF;
border-radius: 8px;
padding: 32px 24px 32px 24px;
}
.posts li a .title {
font-size: 20px;
font-weight: bold;
}
.replies {
background-color: #FFF;
border-radius: 8px;
padding: 32px 24px 32px 24px;
}
.replies li {
list-style: none;
}
.wrapper {
margin: 0 auto;
padding: 32px 0px 32px 0px;
width: 80%;
}
\ No newline at end of file
<html lang="en">
<head>
<meta charset = "UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Widget_23</title>
{% block styles %}{% endblock %}
</head>
<body>
<header>
{% block app_header %}{% endblock %}
</header>
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
...@@ -15,6 +15,11 @@ Including another URLconf ...@@ -15,6 +15,11 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('homepage/', include('homepage.urls', namespace="homepage")), path('homepage/', include('homepage.urls', namespace="homepage")),
...@@ -23,3 +28,6 @@ urlpatterns = [ ...@@ -23,3 +28,6 @@ urlpatterns = [
path('announcements/', include('announcements.urls', namespace="announcements")), path('announcements/', include('announcements.urls', namespace="announcements")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ 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