Commit 2d730eb0 authored by Marco Anton O. Paeldon's avatar Marco Anton O. Paeldon

Merge remote-tracking branch 'origin/forumv2'

parents fd4f4e81 6ccf5db8
......@@ -26,6 +26,9 @@ class WidgetUser(models.Model):
return self.department.home_unit
def __str__(self):
return self.last_name+ ", "+ self.first_name
def display_text(self):
return '{}, {} {}: {}, {}'.format(self.last_name, self.first_name, self.middle_name, self.dept_name, self.home_unit)
def get_absolute_url(self):
......
......@@ -8,13 +8,14 @@ from .models import WidgetUser
# Create your views here.
def dashboard(request):
users = WidgetUser.objects.all()
return render(request, 'dashboard/dashboard.html', {
'users': users
})
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
......
No preview for this file type
# Generated by Django 4.1.7 on 2023-05-13 13:56
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('forum', '0003_rename_reply_to_reply_forum_post'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-05-13 14:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('forum', '0004_alter_forumpost_author'),
]
operations = [
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-05-13 15:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_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-13 16:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0006_forumpost_replies'),
]
operations = [
migrations.RemoveField(
model_name='forumpost',
name='replies',
),
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'),
),
]
from django.db import models
from django.urls import reverse
# Create your models here.
class ForumPost (models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.CharField(max_length=100)
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
......@@ -13,11 +15,20 @@ class ForumPost (models.Model):
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
def get_absolute_url(self):
return reverse('forum:PostDetailView', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('forum:PostUpdateView', kwargs={'pk': self.pk})
class Reply (models.Model):
body = models.TextField()
author = models.CharField(max_length=100)
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE, related_name = 'post_replies')
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
\ No newline at end of file
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Widget's Forum
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum</h1>
<h2>Forum posts:</h2>
<div>
{% for post in posts %}
<a href = "{{post.get_absolute_url}}">"{{post.title}}" by {{post.author.first_name}} {{post.author.last_name}}</a>
<br>
{% endfor %}
<br><br><br>
<a href = "{% url 'forum:addPost' %}"><button>New Post</button></a>
<br><br>
<a href="{% url 'dashboard:index' %}"> Dashboard</a>
<br>
<a href="{% url 'announcements:index' %}"> Announcements</a>
<br>
<a href="{% url 'Assignments:index' %}"> Assignments</a>
<br>
<a href="{% url 'calendar_app:index' %}"> Calendar</a>
<br>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h1> Add a new post:</h1><br>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Post">
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{object.title}}
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<p1>
<h1>{{object.title}}</h1>
by {{object.author.first_name}}, {{object.author.last_name}}
<br>
{{object.datetime_posted}}
<br>
{{object.body}}
</p1>
<br><br>
<p2>
Post Replies: <br><br>
{% for reply in object.post_replies.all %}
by {{reply.author.first_name}} {{reply.author.last_name}} <br>
{{reply.datetime_posted}} <br>
{{reply.body}} <br>
<br>
{% endfor %}
</p2>
<br>
<a href = "{{object.get_update_url}}"><button>Edit Post</button></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Edit Post
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h1>Edit Post</h1><br>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Post">
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import *
urlpatterns = [
path('', index, name='index'),
path('forumposts/add/', PostCreateView.as_view(), name='addPost'),
path('forumposts/<int:pk>/details', PostDetailView.as_view(), name='PostDetailView'),
path('forumposts/<int:pk>/edit', PostUpdateView.as_view(), name='PostUpdateView'),
]
app_name="forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView
# Create your views here.
def index(request):
return_string = "Widget's Forums <br> <br> Forum Posts:<br>"
for i in ForumPost.objects.all():
return_string+=(
i.title + " by " + i.author + " posted " + i.datetime_posted() + ":<br>"
+ i.body + "<br>"
)
for n in Reply.objects.all():
if n.forum_post == i:
return_string+=(
"Reply by " + n.author + " posted " + n.datetime_posted() + ":<br>"
+ n.body + "<br>"
)
return_string+="<br>"
return HttpResponse(return_string)
\ No newline at end of file
post_list = reversed(ForumPost.objects.all())
return render(request,"forum/forum.html",{"posts":post_list})
class PostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class PostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
class PostDetailView(DetailView):
model = ForumPost
template_name = 'forum/forumpost-details.html'
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
......@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
import os
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -60,7 +61,7 @@ ROOT_URLCONF = 'widget_group3.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'template')],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
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