Commit 9fdc1c3f authored by Ray Rafael Abenido's avatar Ray Rafael Abenido

1) Improvement and Clean: Models in forum app Post and Reply are easier to...

1) Improvement and Clean: Models in forum app Post and Reply are easier to read. reply_chain fields in both Post and Reply are also removed as improvements in other parts of the Forum app made them unnecessary.
2) New Feature: Post model in forum app now has an ImageField to allow users to upload pictures.
3) Style: base.html added to templates folder of forum app to provide an overall design for the app. All HTML files extend from this file.
4) New Feature: post_details.html added to templates folder of forum app. Allowed to show individual post, associated picture, and reply section.
5) New Feature: index.html added to list down all posts in the database from newest to oldest.
6) Improvement: post_listing.html and replychain_listing.html are both removed. post_listing.html was removed and replaced by index.html. function better. replychain_listing.html removed because its recursive design was simply bad.
7) New Feature: post_form.html added to provide users the capability to submit new posts and replies. This feature is still under work and user access to it is disabled.
8) New Feature: settings.py and urls.py in widget_django_unchained directory were modified to allow for images to be uploaded in the media directory. These uploaded images can now be displayed on the website.
parent 0762e8b8
# Generated by Django 3.2.12 on 2022-05-16 14:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_auto_20220331_2149'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(null=True),
),
]
# Generated by Django 3.2.12 on 2022-05-17 11:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_alter_post_pub_date'),
]
operations = [
migrations.RemoveField(
model_name='post',
name='reply_chain',
),
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now_add=True, null=True),
),
]
# Generated by Django 3.2.12 on 2022-05-17 11:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0006_auto_20220517_1909'),
]
operations = [
migrations.RemoveField(
model_name='reply',
name='reply_chain',
),
migrations.AddField(
model_name='reply',
name='post',
field=models.ForeignKey(blank=True, default=0, on_delete=django.db.models.deletion.CASCADE, to='forum.post'),
),
]
# Generated by Django 3.2.12 on 2022-05-17 11:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0007_auto_20220517_1912'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-17 12:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0008_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='media/uploaded_image'),
),
]
# Generated by Django 3.2.12 on 2022-05-17 12:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0009_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='forum/static/forum/images'),
),
]
# Generated by Django 3.2.12 on 2022-05-17 13:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0010_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to=''),
),
]
from asyncio.windows_events import NULL
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE) author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE)
post_image = models.ImageField(null=True)
post_title = models.CharField(max_length=100) post_title = models.CharField(max_length=100)
post_body = models.TextField() post_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True) pub_date = models.DateTimeField(auto_now_add=True, null=True)
reply_chain = models.ForeignKey('Reply', on_delete=models.CASCADE,
blank=True,null= True)
def __str__(self): def __str__(self):
return self.post_title return self.post_title
...@@ -16,5 +16,4 @@ class Reply(models.Model): ...@@ -16,5 +16,4 @@ class Reply(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE) author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE)
reply_body = models.TextField() reply_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True) pub_date = models.DateTimeField(auto_now_add=True)
reply_chain = models.ForeignKey('Reply', on_delete=models.CASCADE, post = models.ForeignKey(Post, on_delete=models.CASCADE, blank=True, default=NULL)
blank=True,null= True)
body {
background-color: grey;
font-family: Helvetica, sans-serif;
}
{% 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 'forum/style.css' %}">
<title> Forum </title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'forum/base.html' %}
{% block content %}
<h3>Welcome to Widget's Forum!</h3>
<p> Forum Posts: </p>
{% for post in posts %}
<ul>
<li>
<p>
<a href="{% url 'Show Post Details' post.id %}">
{{ post.post_title }} by {{ post.author.first_name }} {{ post.author.last_name }} dated {{ post.pub_date|date:"d/m/Y h:i:s A" }}
</a>
</p>
</li>
</ul>
{% endfor %}
{% endblock %}
\ No newline at end of file
{% extends "forum/base.html" %}
{% block content %}
<img src="{{post.post_image.url}}">
<p><h2>{{post.post_title}}</h2></p>
<p>by {{post.author.first_name}} {{post.author.last_name}}, {{ post.pub_date|date:"d/m/Y h:i:s A"}}:</p>
<p> {{ post.post_body }} </p>
<p><b> Reply Section: </b></p>
<ul>
{% for reply in replies %}
<li>{{reply.author.first_name}} {{reply.author.last_name}}, {{ reply.pub_date|date:"d/m/Y h:i:s A"}}: {{reply.reply_body}}</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'forum/base.html' %}
{% block content %}
<form action="confirmation" method="POST">
{% csrf_token %}
<h3> Post Name: </h3> <input type="text" name="post_title"> <br>
<h3> Post Body: </h3> <input type="text" name="post_body"> <br>
<h3> Author ID </h3> <input type="text" name="author_id"> <br>
<input type="submit">
</form>
{% endblock %}
<h2>FORUM POSTS:</h2>
<p>
{% for post in posts %}
<p><b>{{post.post_title}}</b> by {{post.author.first_name}} {{post.author.last_name}} dated {{post.pub_date}}:</p>
<p> {{ post.post_body }} </p>
{% if post.reply_chain != NULL %}
<p> {% include "replychain_listing.html" with reply=post.reply_chain %} </p>
{% endif %}
<br>
{% endfor %}
</p>
\ No newline at end of file
<p>
<i> Reply by {{post.author.first_name}} {{post.author.last_name}} dated {{reply.pub_date}}: </i>
</p>
<p>{{reply.reply_body}}</p>
{% if reply.reply_chain != NULL %}
<p>{% include "replychain_listing.html" with reply=reply.reply_chain %}</p>
{% endif %}
\ No newline at end of file
...@@ -2,5 +2,11 @@ from django.urls import path ...@@ -2,5 +2,11 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.show_forum_page, name="Show Forum Page") path('', views.show_index, name="Show Forum Page"),
path('post/<int:post_id>/details', views.show_post, name="Show Post Details"),
# Disabled for the time being. May be used again in the near future.
#path('post/add', views.show_form, name="Add Post Form"),
#path('post/confirmation', views.show_confirmation, name="Show confirmation"),
] ]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import Http404, HttpResponse
from .models import Post, Reply from .models import Post, Reply
# Create your views here. # Create your views here.
def show_forum_page(request): def show_index(request):
posts = Post.objects.all() posts = Post.objects.all().order_by("-pub_date")
return render(request, 'post_listing.html', {'posts': posts}) return render(request, 'forum/index.html', {'posts':posts})
\ No newline at end of file
def show_post(request, post_id):
try:
post = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404("No such article exists.")
replies = Reply.objects.filter(post=post_id).order_by("-pub_date")
return render(request, 'forum/post_details.html', {'post':post, 'replies': replies})
# The following functions are not used for the time being. May be used again
# in the near future.
def show_form(request):
return render(request, 'forum/post_form.html', {})
def show_confirmation(request):
if (request.method == "POST"):
title = request.POST.get("post_title")
body = request.POST.get("post_body")
author = request.POST.get("author_id")
post = Post.objects.create(post_title=title,post_body=body,author_id=author)
return HttpResponse("Article saved!")
\ No newline at end of file
...@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ ...@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
from pathlib import Path from pathlib import Path
import environ import environ
import os
env = environ.Env() env = environ.Env()
environ.Env.read_env() environ.Env.read_env()
...@@ -125,6 +126,12 @@ USE_TZ = True ...@@ -125,6 +126,12 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIR = (
os.path.join(BASE_DIR, 'statics')
)
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
...@@ -15,6 +15,8 @@ Including another URLconf ...@@ -15,6 +15,8 @@ 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
urlpatterns = [ urlpatterns = [
...@@ -23,4 +25,4 @@ urlpatterns = [ ...@@ -23,4 +25,4 @@ urlpatterns = [
path('forum/', include('forum.urls')), path('forum/', include('forum.urls')),
path('assignments/', include('assignments.urls')), path('assignments/', include('assignments.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
\ No newline at end of file \ 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