Commit e90d7b7d authored by Neal Luigi D. Rodriguez's avatar Neal Luigi D. Rodriguez

Merge branch 'forumv2'

parents 50b9299c 49de88d0
......@@ -6,7 +6,7 @@ Group Members:
204374 RODRIGUEZ, Neal Luigi D.
204655 SEE, Eurydice Gabrielle Madison O.
Project: Widget Version 1
Project: Widget Version 2
Apps Assigned:
DASHBOARD-Castillo
......@@ -15,7 +15,7 @@ FORUM-See
ASSIGNMENTS-Rodriguez
CALENDAR-Olivares
Date of Submission: March 6, 2023
Date of Submission: May 15, 2023
We as a group have worked on the project by ourselves
with no help from anyone except from our own groupmates.
......@@ -24,11 +24,10 @@ presented in class. We have also cited the references
below that also helped us in our project.
References Used:
Model Field Reference. Django. (n.d.). Retrieved March 5, 2023, from https://docs.djangoproject.com/en/4.0/ref/models/fields/
Signatures:
(sgd) Gareth Xerxes Yap Castillo March 5, 2023
(sgd) Neal Luigi RODRIGUEZ March 5, 2023
(sgd) Christian Louis Olivares March 5, 2023
(sgd) Ann Colleen Garcia March 5, 2023
(sgd) Eurydice Gabrielle Madison See March 5, 2023
\ No newline at end of file
(sgd) Eurydice Gabrielle Madison See May 15, 2023
\ No newline at end of file
No preview for this file type
# Generated by Django 4.1.7 on 2023-05-11 10:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0003_alter_forumpost_author_alter_reply_author'),
]
operations = [
migrations.AddField(
model_name='forumpost',
name='replies',
field=models.ManyToManyField(blank=True, to='Forum.forumpost'),
),
]
# Generated by Django 4.1.7 on 2023-05-12 17:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_alter_widgetuser_department'),
('Forum', '0004_forumpost_replies'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='pub_datetime',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='replies', to='Dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-05-12 18:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_alter_widgetuser_department'),
('Forum', '0005_alter_forumpost_pub_datetime_alter_reply_author'),
]
operations = [
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='Dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='forum_post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='post_replies', to='Forum.forumpost'),
),
]
{% block title %}Widget's Forum{% endblock %}
{% block styles %}
<style>
body {
background-color: rgb(253, 222, 207);
font-family: Georgia, serif;
font-size: 16px;
color: rgb(206, 132, 100);
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: center;">
<h1>Welcome to Widget's Forum</h1>
</div>
<p1>Forum posts:</p1>
{% for post in posts %}
<li>{{post.title}} by {{post.author}}</li>
{% endfor %}
<form method="post">
{% csrf_token %}
{{form.as_p}}
<button type="submit">New Post</button>
</form>
<p><a href="http://127.0.0.1:8000/bookshelf/dashboard">Dashboard</a></p>
<p><a href="http://127.0.0.1:8000/bookshelf/announcements">Announcements</a></p>
<p><a href="http://127.0.0.1:8000/bookshelf/assignments">Assignments</a></p>
<p><a href="http://127.0.0.1:8000/bookshelf/calendar">Calendar</a></p>
{% endblock %}
\ No newline at end of file
from django.db import models
from Dashboard.models import WidgetUser
from django.urls import reverse
class ForumPost(models.Model):
title = models.CharField(max_length = 100)
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT)
pub_datetime = models.DateTimeField()
pub_datetime = models.DateTimeField(auto_now_add=True, null=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('Forum:forumpost-details', kwargs={'pk':self.pk})
replies = models.ManyToManyField('self', blank=True)
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE, related_name='post_replies')
def __str__(self):
return self.body
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block styles %}
<style>
body {
background-color: rgb(253, 222, 207);
font-family: Georgia, serif;
font-size: 16px;
color: rgb(206, 132, 100);
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: center;">
<h1>Welcome to Widget's Forum</h1>
</div>
<p1>Forum posts:</p1>
{% for post in posts %}
<li><a href="{% url 'Forum:forumpost-details' pk=post.pk %}">{{ post.title }} by {{ post.author }}</a></li>
{% endfor %}
<br>
<button type="submit">
<a href="{% url 'Forum:forumpost-add' %}">New Post</a>
</button>
<br>
<br>
<a href="http://127.0.0.1:8000/Dashboard/dashboard">Dashboard</a>
<br>
<a href="http://127.0.0.1:8000/Announcements/announcements">Announcements</a>
<br>
<a href="http://127.0.0.1:8000/Assignments/assignments">Assignments</a>
<br>
<a href="http://127.0.0.1:8000/widgetcalendar/calendar">Calendar</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
<title>{% block title %}Widget's Forum{% endblock %}</title>
{% block styles %}
<style>
body {
background-color: rgb(253, 222, 207);
font-family: Georgia, serif;
font-size: 16px;
color: rgb(206, 132, 100);
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: center;">
<h1>Welcome to Widget's Forum</h1>
</div>
<p1>Forum posts:</p1>
{% for post in posts %}
<li><a href="{% url 'Forum:forumpost-details' pk=post.pk %}">{{ post.title }} by {{ post.author }}</a></li>
{% endfor %}
<br>
<button type="submit">
<a href="{% url 'Forum:forumpost-add' %}">New Post</a>
</button>
<br>
<br>
<a href="http://127.0.0.1:8000/Dashboard/dashboard">Dashboard</a>
<br>
<a href="http://127.0.0.1:8000/Announcements/announcements">Announcements</a>
<br>
<a href="http://127.0.0.1:8000/Assignments/assignments">Assignments</a>
<br>
<a href="http://127.0.0.1:8000/widgetcalendar/calendar">Calendar</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Post {% endblock %}
{% block styles %}
<style>
body {
background-color: #FEA8A5;
font-family: Georgia, serif;
font-size: 16px;
font-weight: bold;
color:#c35c5a;
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: left;">
<h1>Add a new post:</h1>
</div>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Post</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{object.title}} {% endblock %}
{% block styles %}
<style>
body {
background-color: rgb(202, 255, 206);
font-family: Georgia, serif;
font-size: 16px;
color: rgb(90, 154, 78);
}
</style>
{% endblock %}
{% block content %}
<div class="center">
<h1>{{ object.title }}</h1>
by {{ object.author }}
<br>
{{ object.pub_datetime }}
<br>
{{ object.body }}
<h2>Post Replies:</h2>
{% for reply in object.post_replies.all %}
by {{ reply.author }}
<br>
{{ reply.pub_datetime }}
<br>
{{ reply.body }}
{% empty %}
No replies yet.
{% endfor %}
<br>
<br>
<button type="submit">
<a href="{% url 'Forum:forumpost-edit' pk=object.pk %}">Edit Post</a>
</button>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Post {% endblock %}
{% block styles %}
<style>
body {
background-color: #E8D1C5;
font-family: Georgia, serif;
font-size: 16px;
font-weight: bold;
color: #a77f6a;
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: left;">
<h1>Edit Post</h1>
</div>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes to Post</button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import (
index, forum, ForumDetailView, AddForumPostView,
EditForumPostView, ForumListView)
from . import views
urlpatterns = [
path('', index, name='index'),
path("", views.index, name="index"),
path('forum/', ForumListView.as_view(), name='forum'),
path('forum/forumposts/<int:pk>/details/', ForumDetailView.as_view(), name='forumpost-details'),
path('forum/forumposts/add/', AddForumPostView.as_view(), name='forumpost-add'),
path('forum/forumposts/<pk>/edit/', EditForumPostView.as_view(), name = 'forumpost-edit'),
]
# This might be needed, depending on your Django version
app_name = "Forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from django.views.generic.list import ListView
from .models import ForumPost
from .models import Reply
from .models import ForumPost, Reply
def index(request):
return_string = "<br>"
......@@ -15,3 +19,34 @@ def index(request):
html_string = "<html><head> Widget's Forum <br><br> Forum Posts: </head><body> {} </body><html>".format(return_string)
return HttpResponse(html_string)
def forum(request):
posts = ForumPost.objects.all()
context = {'posts': posts}
return render(request, 'forum.html', context)
class ForumListView(ListView):
model = ForumPost
template_name = 'forum.html'
context_object_name = 'posts'
ordering = ['-pub_datetime'] # sort by newest to oldest
class ForumDetailView(DetailView):
model = ForumPost
template_name = 'forumpost-details.html'
context_object_name = 'post'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['replies'] = self.object.replies.all()
return context
class AddForumPostView(CreateView):
model = ForumPost
fields = ['title', 'body', 'author']
template_name = 'forumpost-add.html'
class EditForumPostView(UpdateView):
model = ForumPost
fields = ['title', 'body', 'author']
template_name = 'forumpost-edit.html'
\ No newline at end of file
......@@ -18,7 +18,6 @@ load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
......
# Generated by Django 3.2 on 2023-05-15 06:20
# Generated by Django 4.1.7 on 2023-05-11 10:32
from django.db import migrations, models
......
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