Commit 68d03b5a authored by shibadisaster's avatar shibadisaster

Merge branch 'forum' into main

parents 8fdc7d50 d56aa856
<<<<<<< HEAD
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
...@@ -158,3 +159,7 @@ cython_debug/ ...@@ -158,3 +159,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
=======
.env
*.pyc
>>>>>>> forum
# Generated by Django 3.2 on 2023-03-05 07:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcementBoard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reaction',
name='annoucement',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcementBoard.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.PositiveIntegerField(default=0),
),
]
from django.contrib import admin
from .models import ForumPost, Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ('title', 'body', 'author', 'pub_datetime')
search_fields = ('title', 'author', 'pub_datetime',)
list_filter = ('title', 'author', 'pub_datetime',)
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ('body', 'post', 'author', 'pub_datetime',)
search_fields = ('author', 'pub_datetime',)
list_filter = ('author', 'pub_datetime',)
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 3.2 on 2023-03-05 07:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.CharField(max_length=200)),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('body', models.CharField(max_length=200)),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
]
# Generated by Django 3.2 on 2023-03-05 08:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='reply',
name='post',
field=models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost'),
),
]
# forum/models.py
from django.db import models
from dashboard.models import WidgetUser
class ForumPost(models.Model):
title = models.CharField(max_length=100)
body = models.CharField(max_length=200)
author = models.ForeignKey(
WidgetUser,
null=True,
default=True,
on_delete=models.CASCADE,
)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reply(models.Model):
post = models.ForeignKey(
ForumPost,
null=True,
default=True,
on_delete=models.CASCADE,
)
body = models.CharField(max_length=200)
author = models.ForeignKey(
WidgetUser,
null=True,
default=True,
on_delete=models.CASCADE,
)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.body
def format_pub_datetime(self):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
from django.test import TestCase
# Create your tests here.
# forum/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
# This might be needed, depending on your Django version
app_name = "forum"
# appname/views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from dashboard.models import WidgetUser
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:450%;'>\
Widget Forum\
</h1>"
body = "<h2>Forum Posts:</h2>"
for post in ForumPost.objects.all():
body += "<div style='border: 2px solid gray; border-radius:5px; padding:20px 30px;'>\
<b>{}</b> by {} {} posted {}:\
<br>\
{}".format(post.title, post.author.first_name, post.author.last_name, post.format_pub_datetime(), post.body)
for reply in Reply.objects.all():
if reply.post == post:
body += "<p style='border: 1px dashed gray; border-radius:5px; padding:20px 30px;'>\
Reply by {} {} posted {}:\
<br>\
{}".format(reply.author.first_name, reply.author.last_name, reply.format_pub_datetime(), reply.body)
body += "</div>"
body += "<p>&nbsp;</p>"
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
...@@ -43,6 +43,7 @@ INSTALLED_APPS = [ ...@@ -43,6 +43,7 @@ INSTALLED_APPS = [
'dashboard', 'dashboard',
'assignments', 'assignments',
'announcementBoard', 'announcementBoard',
'forum',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -21,4 +21,5 @@ urlpatterns = [ ...@@ -21,4 +21,5 @@ urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('assignments/', include('assignments.urls', namespace="assignments")), path('assignments/', include('assignments.urls', namespace="assignments")),
path('announcementBoard/', include('announcementBoard.urls', namespace="announcementBoard")), path('announcementBoard/', include('announcementBoard.urls', namespace="announcementBoard")),
path('forum/', include('forum.urls', namespace="forum")),
] ]
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