Commit b3474c86 authored by Matthew Karl David P. Arpas's avatar Matthew Karl David P. Arpas

Pulled faulty code from forumv2 and resolved conflicts

parents 4075b398 b88d3ac6
from django import forms
from .models import ForumPost
class ForumpostForm(forms.ModelForm):
class Meta:
model = ForumPost
fields = ['title', 'body', 'author']
\ 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)
......@@ -10,6 +11,9 @@ class ForumPost(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("forum:forumpost-details", kwargs={"pk": self.pk})
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h2>Welcome to Widget's Forum!</h2>
<h3>Forum posts:</h3>
{% for forumpost in forumposts %}
<a href="{{ forumpost.get_absolute_url }}">{{ forumpost.title }} by {{ forumpost.author.last_name }}, {{ forumpost.author.first_name }}</a><br>
{% endfor %}
<br>
<form action={% url 'forum:forumpost-add' %}>
<input type="submit" value="New Post"/>
</form>
<a href="{% url 'dashboard:pageview' %}">Dashboard</a><br>
<a href="{% url 'announcements:pageview' %}">Announcements</a><br>
<a href="{% url 'assignments:pageview' %}">Assignments</a><br>
<a href="{% url 'widget_calendar:pageview' %}">Calendar</a><br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Post{% endblock %}
{% block content %}
<h2>Add a new post:</h2>
<p>
<form action='' method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save New Post"/>
</form>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ forumpost.title}} {% endblock %}
{% block content %}
<h2>{{ forumpost.title }}</h2>
<h3> by {{forumpost.author.first_name}} {{ forumpost.author.last_name }}</h3>
<p>{{forumpost.pub_datetime}}</p>
<br>
<p>{{forumpost.body}}</p>
<br>
<h2>POST REPLIES:</h2>
<br>
{% for reply in replys %}
<h3> by {{reply.author.first_name}} {{ reply.author.last_name }}</h3>
<p>{{reply.pub_datetime}}</p>
<br>
<p>{{reply.body}}</p>
<br>
{% endfor %}
<button> <a href="{% url 'forum:forumpost-edit' forumpost.pk %}">Edit Post</a></button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Post{% endblock %}
{% block content %}
<h2>Edit post:</h2>
<p>
<form action='' method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save Changes to Post"/>
</form>
</p>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import pageview
from .views import pageview, ForumpostDetailView, ForumpostCreateView, ForumpostUpdateView
urlpatterns = [
path('', pageview, name='pageview')
path('', pageview, name='pageview'),
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 .models import ForumPost, Reply
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
def pageview(request):
forumposts = ForumPost.objects.all()
forumposts = ForumPost.objects.order_by("-pub_datetime")
replys = Reply.objects.all()
string_builder = "Widget's Forum <br> <br> Forum Posts: <br> "
return render(request, 'forum/forum.html', {'forumposts': forumposts, 'replys': replys})
for forumpost in forumposts:
class ForumpostDetailView(DetailView):
def get(self, request, pk):
forumpost = ForumPost.objects.get(pk=pk)
replys = Reply.objects.filter(forum_post=forumpost)
return render(request, 'forum/forumpost-details.html', {'forumpost': forumpost, 'replys': replys})
string_builder = "{} <br> {} by {} posted {} <br> {}".format(
string_builder,
forumpost.title,
forumpost.author,
forumpost.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
forumpost.body
)
for reply in replys:
if reply.forum_post == forumpost:
string_builder = "{} <br> Reply by {} posted {} <br> {}".format(
string_builder,
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
reply.body
)
string_builder += "<br>"
return HttpResponse(string_builder)
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'
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