Commit 0a0a1af3 authored by Joshua Son's avatar Joshua Son

Merge branch 'forum' into 'master'

Forum

See merge request !4
parents cfaf9aba c7a6ef05
# 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
...@@ -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/
import os import os
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,14 @@ USE_TZ = True ...@@ -125,6 +126,14 @@ 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/'
<<<<<<< HEAD
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIR = (
os.path.join(BASE_DIR, 'statics')
)
=======
MEDIA_URL = '/images/' MEDIA_URL = '/images/'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
...@@ -132,6 +141,7 @@ STATICFILES_DIRS = [ ...@@ -132,6 +141,7 @@ STATICFILES_DIRS = [
] ]
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images') MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')
>>>>>>> cfaf9ababe2607db22a5f225df2d8f007ea1dc50
# 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
......
...@@ -17,6 +17,10 @@ from django.contrib import admin ...@@ -17,6 +17,10 @@ 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 import settings
from django.conf.urls.static import static from django.conf.urls.static import static
<<<<<<< HEAD
=======
>>>>>>> cfaf9ababe2607db22a5f225df2d8f007ea1dc50
urlpatterns = [ urlpatterns = [
path('announcements/', include('announcements.urls')), path('announcements/', include('announcements.urls')),
...@@ -24,4 +28,8 @@ urlpatterns = [ ...@@ -24,4 +28,8 @@ 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),
<<<<<<< HEAD
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
=======
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>>>>>> cfaf9ababe2607db22a5f225df2d8f007ea1dc50
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