bypassing file name length errors

parent 5dbd99c4
# Generated by Django 4.0.3 on 2022-05-22 09:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_remove_reaction_announcement_reaction_announcement'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(verbose_name='Date Published'),
),
]
# Generated by Django 4.0.3 on 2022-05-22 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_alter_announcement_pub_date'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='images',
field=models.ImageField(default='default.jpg', upload_to='announcement'),
),
]
...@@ -7,15 +7,16 @@ class Announcement(models.Model): ...@@ -7,15 +7,16 @@ class Announcement(models.Model):
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)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,default = 1) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,default = 1)
images = models.ImageField (upload_to="announcement", default = "default.jpg")
pub_date = models.DateField("Date Published") pub_date = models.DateField("Date Published")
def __str__(self): def __str__(self):
return self.announcement_title return f"{self.announcement_title} {self.announcement_body} {self.pub_date}"
class Reaction(models.Model): class Reaction(models.Model):
reaction_name = models.CharField(max_length=10) reaction_name = models.CharField(max_length=10)
tally = models.IntegerField(default=0) tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement,on_delete=models.CASCADE, default = 1) announcement = models.ForeignKey(Announcement,on_delete=models.CASCADE, default = 1)
def __str__(self): def __str__(self):
return self.reaction_name return f"{self.reaction_name} {self.tally}"
\ No newline at end of file \ No newline at end of file
h1 {
text-align: center;
color:rgb(90, 90, 90);
text-shadow:2px 2px 5px rgb(200, 15, 100);
font-family: "Lucida Grande";
font-size: 75px;
}
h2 {
color:rgb(216, 94, 216);
font-size: 20px;
font-family: "Helvetica";
}
body {
background-color: rgb(255, 255, 255);
}
p {
color:rgb(0, 180, 216);
font-size: 25px;
font-family: "Arial Narrow";
}
a {
color:rgb(5, 119, 100);
font-size: 22px;
font-family: "Arial Narrow";
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
\ 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.0">
<link rel="stylesheet" type="text/css" href="{% static 'announcements/style.css' %}">
<title>{% block title %}It is a Page LOL{% endblock %}</title>
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block title %}announcement details{% endblock %}
{%block content%}
<h1>{{ announcement.announcement_title }}</h1>
<h2>by {{ announcement.author }}, {{announcement.pub_date}}</h2>
<p>{{announcement.announcement_body}}</p>
<ul>
{% for reaction in reactionList %}
<li>{{ reaction.reaction_name }}: {{reaction.tally}}</a></li>
{% endfor %}
</ul>
<br /><br /><br /><img src="{{ announcement.images.url }}" alt="{{announcement.announcement_title}}" style="width:50%">
{% endblock %}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block title %}Announcements{% endblock %}
{% block content %}
<h1>Announcement Board</h1>
<p>Important Announcements</p>
{% if announcementList %}
<ul>
{% for announcement in announcementList %}
<li><a href="{{ announcement.id }}/details/">{{announcement.announcement_title}} by {{ announcement.author }} dated {{ announcement.pub_date }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No users are available</p>
{% endif %}
{% endblock %}
\ No newline at end of file
...@@ -3,5 +3,9 @@ from django.urls import path ...@@ -3,5 +3,9 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='announcementboardIndex') path('', views.index, name='announcementboardIndex'),
] # announcement/1/details
\ No newline at end of file path("<int:announcement_id>/details/", views.details, name="details")
]
app_name = "announcement"
\ No newline at end of file
from django.http import HttpResponse, Http404
from django.http import HttpResponse from django.shortcuts import render
from .models import Announcement, Reaction from .models import Announcement, Reaction
text = "" announcementList = Announcement.objects.order_by("pub_date")
announcementCounter = 1
reactionCounter = 0
announcementList = Announcement.objects.all()
reactionList = Reaction.objects.all() reactionList = Reaction.objects.all()
outputText = "ANNOUNCEMENTS:"
for i in announcementList:
text += "<br />" + f"{i.announcement_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.announcement_body}<br />"
if announcementCounter == 1:
while reactionCounter < 3:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 2:
while reactionCounter < 6:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 3:
while reactionCounter < 9:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
announcementCounter += 1
outputText += text
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse(outputText)
\ No newline at end of file context = {
"announcementList": announcementList,
}
return render(request, "announcements/index.html", context)
def details(request, announcement_id):
try:
announcement = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
for reaction in announcementList:
if reaction.id == announcement_id:
announcement = reaction
break
context = {
"announcement": announcement,
"announcement_id": announcement_id
}
return render(request, "announcements/details.html", context)
\ 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.0">
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<title>{% block title %}Oh look, a page{% endblock %}</title>
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %} {% extends 'assignments/base.html' %}
{% load static %}
{% block title %}Assignment no. {{ assignment_id }}{% endblock %} {% block title %}Assignment no. {{ assignment_id }}{% endblock %}
......
{% extends 'base.html' %} {% extends 'assignments/base.html' %}
{% load static %}
{% block title %}Assignments{% endblock %} {% block title %}Assignments{% endblock %}
......
# Generated by Django 4.0.3 on 2022-05-22 09:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_post_author_reply'),
]
operations = [
migrations.AddField(
model_name='reply',
name='images',
field=models.ImageField(default='default.jpg', upload_to='forum'),
),
]
# Generated by Django 4.0.3 on 2022-05-22 10:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_reply_images'),
]
operations = [
migrations.RemoveField(
model_name='reply',
name='images',
),
migrations.AddField(
model_name='post',
name='images',
field=models.ImageField(default='default.jpg', upload_to='forum'),
),
]
...@@ -7,6 +7,7 @@ class Post (models.Model): ...@@ -7,6 +7,7 @@ class Post (models.Model):
post_body = models.CharField(max_length=99999) post_body = models.CharField(max_length=99999)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
images = models.ImageField (upload_to="forum", default = "default.jpg")
def __str__(self): def __str__(self):
return f"{self.post_title} {self.post_body} {self.pub_date}" return f"{self.post_title} {self.post_body} {self.pub_date}"
......
h1 {
text-align: center;
color:rgb(122, 124, 240);
text-shadow:2px 2px 5px rgb(101, 15, 158);
font-family: "Brush Script MT", "Brush Script Std";
font-size: 50px;
}
h2 {
color:rgb(8, 28, 54);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
body {
background-color: rgb(163, 163, 163);
}
p {
color:rgb(0, 0, 0);
font-size: 25px;
font-family: "New Century Schoolbook", "TeX Gyre Schola", serif;
}
a {
color:rgb(133, 0, 77);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
\ No newline at end of file
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<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.0"> <meta name="viewport" content="width=device-width, initial-scale-1.0">
<link rel="stylesheet" href="{% static 'assignments/style.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}">
<title>{% block title %}Woah a page{% endblock %}</title> <title>{% block title %}What a page{% endblock %}</title>
</head> </head>
<body> <body>
<div id="content"> <div id="content">
......
{% extends 'forum/base.html' %}
{% block title %}post details{% endblock %}
{%block content%}
<h1>{{ post.post_title }}</h1>
<h2>by {{ post.author }}, {{post.pub_date}}</h2>
<p>{{post.post_body}}</p>
{% if replies %}
<ul>
{% for reply in replies %}
<li>{{ reply.author }}, {{reply.pub_date}}: {{reply.reply_body}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No replies are available.</p>
{% endif %}
<br /><br /><br /><img src="{{ post.images.url }}" alt="{{post.post_title}}" style="width:50%">
{% endblock %}
{% extends 'forum/base.html' %}
{%block title%}Forum{%endblock%}
{%block content%}
<h1>Welcome to Widget's Forum!</h1>
<p>Forum posts:</p>
{% if posts %}
<ul>
{% for post in posts %}
<li><a href = "posts/{{ post.id }}/details/">{{post.post_title}} by {{ post.author }} dated {{ post.pub_date }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No posts are available.</p>
{% endif %}
{% endblock %}
\ No newline at end of file
...@@ -3,6 +3,7 @@ from . import views ...@@ -3,6 +3,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path("posts/<int:post_id>/details/", views.details, name = "details"),
] ]
app_name = "forum" app_name = "forum"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from .models import Post, Reply from .models import Post, Reply
posts = Post.objects.all() posts = Post.objects.order_by("pub_date")
replies = Reply.objects.all() replies = Reply.objects.order_by("pub_date")
finalstring = "FORUM POSTS:<br />" def index (request):
for i in posts:
poststring = f"{i.post_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.post_body}<br />"
finalstring += poststring
for i in replies:
replystring = "Reply by " + f"{i.author} dated " + f"{i.pub_date}:<br \>" + f"{i.reply_body}<br />" context = {
"posts": posts
}
finalstring += replystring return render(request, "forum/index.html", context)
def index (request): def details (request, post_id):
try:
post = Post.objects.get (pk=post_id)
except Post.DoesNotExist:
raise Http404 ("Post does not exist!")
for reply in posts:
if reply.id == post_id:
post = reply
break
context = {
"post": post,
"replies": replies
}
return HttpResponse (finalstring) return render(request, "forum/details.html", context)
......
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