Commit 79e2ddbc authored by Migs Atienza's avatar Migs Atienza

Merge branch 'forumv2' into 'master'

Forumv2

See merge request !12
parents e9323618 500e5f75
manage.py
\ No newline at end of file
CSCI 40-F
Atienza, Miguel Luis Antonio, A, 210523; Benito, Matthew Josh Benedict, R., 210857; Garsin, Mariam Yasmin, B, 206034; Gomez, Enrnique Jose Stefan, P, 212804; Que, Nate Brevin, A, 214754;
Midterm Project: Widget v1
Final Project: Widget v2
App Assignments:
Dashboard - Stefan
Announcement Board - Josh
Forum - Migs
Assignments - Brevin
Calendar - Yam
DATE OF SUBMISSION: March 6, 2023
DATE OF SUBMISSION: May 15, 2023
The project was done completely by k3git without help from people outside of the group.
REFERENCES USED:
https://www.geeksforgeeks.org/how-to-use-django-field-choices/
Members Signatures:
[sgd] Atienza, Miguel Luis Antonio A.,
......
No preview for this file type
models.py
\ No newline at end of file
from django.db import models
from django.urls import reverse
class ForumPost(models.Model):
......@@ -10,6 +11,9 @@ class ForumPost(models.Model):
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('forum:forumpost-details', kwargs={'pk': self.pk})
class Reply(models.Model):
body = models.TextField(max_length=1000)
......@@ -19,4 +23,6 @@ class Reply(models.Model):
def __str__(self):
return '{}\'s reply to {}'.format(self.author, self.forum_post)
# Create your models here.
{% extends 'base.html' %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum!</h1>
<h3>
{% for post in forumposts %}
<a href="{{ post.get_absolute_url }}">{{ post.title }} by {{ post.author }}</a><br>
{% endfor %}
</h3>
{% endblock %}
{% block scripts %}
<a href="/forum/forumposts/add"><input type="submit" value="New Post"></a><br><br>
<a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcements</a><br>
<a href="/assignments">Assignments</a><br>
<a href="/calendar">Calendar</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block content %}
<h1>Add a new Post:</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Post">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ reply.forum_post.title }}{% endblock %}
{% block content %}
<h1>{{ reply.forum_post.title }}</h1>
<h3>by {{ reply.forum_post.author }}<br>
{{ reply.forum_post.pub_datetime }}<br>
{{ reply.forum_post.body }}<br>
</h3>
<br>
<h1>POST REPLIES</h1>
<h3>
by {{ reply.author }}
{{ reply.pub_datetime }}
{{ reply.body }}
</h3>
{% endblock %}
{% block scripts %}
<a href="/forum/forumposts/{{ reply.forum_post.pk }}/edit"><input type="submit" value="Edit Post"></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Post{% endblock %}
{% block content %}
<h1>Edit Post:</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Post">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
from django.contrib import admin
from django.urls import path
from .views import index
from .views import index, ForumPostDetailView, ForumPostCreateView, ForumPostUpdateView
urlpatterns = [
path('', index, name='index'),
path('forumposts/<int:pk>/details', ForumPostDetailView.as_view(), name='forumpost-details'),
path('forumposts/add', ForumPostCreateView.as_view(), name='forumpost-add'),
path('forumposts/<int:pk>/edit', ForumPostUpdateView.as_view(), name='forumpost-edit'),
]
app_name = "forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import ForumPost, Reply
def index(request):
page_content = """<H1>Widget’s Forum</H1>"""
for forum in ForumPost.objects.all():
newForumDateTime = forum.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<br>
{} by {} posted {}:<br>
{}<br>
""".format(forum.title, forum.author, newForumDateTime, forum.body)
for reply in Reply.objects.all():
if reply.forum_post == forum:
newReplyDateTime = reply.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """Reply by {} posted {}:<br>
{}<br>
""".format(reply.author, newReplyDateTime, reply.body)
return HttpResponse(page_content)
return render(request, 'forum/forum.html', {'forumposts': ForumPost.objects.all()})
class ForumPostDetailView(DetailView):
model = Reply
def get(self, request, pk):
return render(request, 'forum/forumpost-details.html', {'reply': self.model.objects.get(pk=pk)})
class ForumPostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class ForumPostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
# Create your views here.
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