Commit c6c826e5 authored by Jiuvi Anne Hu's avatar Jiuvi Anne Hu

Merge branch 'dev' of https://gitlab.discs.ateneo.edu/RJC/midterm_robo_mommy into announcementsv2

Merge to prevent errors later.
parents 5e97e902 510374f1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (midterm_robo_mommy)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
# Generated by Django 3.2 on 2023-05-11 11:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_widgetuser'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='department', to='Dashboard.department'),
),
]
...@@ -16,6 +16,9 @@ class WidgetUser(models.Model): ...@@ -16,6 +16,9 @@ class WidgetUser(models.Model):
last_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50)
department = models.ForeignKey(Department, related_name="department", on_delete=models.CASCADE) department = models.ForeignKey(Department, related_name="department", on_delete=models.CASCADE)
def __str__(self) -> str:
return str(self.last_name + ', ' + self.first_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('widgetuser-detail', kwargs={'pk': self.pk}) return reverse('widgetuser-detail', kwargs={'pk': self.pk})
......
...@@ -23,10 +23,10 @@ def Dashboard_list_view(request): ...@@ -23,10 +23,10 @@ def Dashboard_list_view(request):
wu.department.home_unit) wu.department.home_unit)
html_string_2 += '</ul></li>' html_string_2 += '</ul></li>'
html_string_3 = '<a href="/Widgetusers/add"><button value="click here" > Add Widget User</button></a><br><br>' html_string_3 = '<a href="/Widgetusers/add"><button value="click here" > Add Widget User</button></a><br><br>'
html_string_3 += '<a href="/Announcements/">Announcement Board</a><br>' html_string_3 += '<a href="/announcements/">Announcement Board</a><br>'
html_string_3 += '<a href="/Forum/">Forum</a><br>' html_string_3 += '<a href="/forum/">Forum</a><br>'
html_string_3 += '<a href="/Assignments">Assignment</a><br>' html_string_3 += '<a href="/Assignments">Assignment</a><br>'
html_string_3 += '<a href="/Calendar/">Calendar</a><br>' html_string_3 += '<a href="/widget_Calendar/">Calendar</a><br>'
html_string_final = html_string_1 + html_string_2 + html_string_3 + '</html>' html_string_final = html_string_1 + html_string_2 + html_string_3 + '</html>'
......
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Widget's Forum</title>
<h1>Welcome to Widget's Forum</h1>
<h2>Forum posts:</h2>
{% for post in posts %}
<a href="forumposts/{{ post.pk }}/details/">{{ post.title }} by {{ post.author.first_name }} {{ post.author.last_name }}</a><br>
{% endfor %}
<br><br>
<a href="forumposts/add/"><button value="click here">New Post</button></a><br><br>
<a href="/Dashboard/">Dashboard</a><br>
<a href="/announcements/">Announcements</a><br>
<a href="/Assignments/">Assignments</a><br>
<a href="/widget_Calendar/">Calendar</a><br>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Add Post</title>
<h1>Add a new post:</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Post">
</form>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>{{ posts.title }}</title>
<h1>{{ posts.title }}</h1>
<h2>by {{ posts.author.first_name }} {{ posts.author.last_name }}</h2>
<p>{{ posts.pub_datetime|date:"M/d/Y, f A"}}</p>
<p>{{ posts.body }}</p>
<h3>POST REPLIES:</h3>
{% for reply in posts.reply.all %}
by {{ reply.author.first_name }} {{ reply.author.last_name }}<br>
{{ reply.pub_datetime|date:"M/d/Y, f A"}}<br>
{{ reply.body }}<br><br>
{% endfor %}
<a href="/forum/forumposts/{{ posts.pk }}/edit/"><button value="click here">Edit Post</button></a>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<title>Edit Post</title>
<h1>Edit post:</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Post">
</form>
{% endblock content %}
\ No newline at end of file
...@@ -2,5 +2,10 @@ from django.urls import path ...@@ -2,5 +2,10 @@ from django.urls import path
from .views import * from .views import *
urlpatterns = [ urlpatterns = [
path('forum/', forum_post_list_view, name='forum_post_list_view') path('forum/', forum_post_list_view, name='forum_post_list_view'),
path('forum/forumposts/<int:pk>/details/', ForumPostDetailView.as_view(), name='forumpostdetailview'),
path('forum/forumposts/add/', ForumPostCreateView.as_view(), name='forumpostcreateview'),
path('forum/forumposts/<int:pk>/edit/', ForumPostUpdateView.as_view(), name='forumpostupdateview'),
] ]
app_name = 'forum'
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views import generic
from django.urls import reverse
from .models import ForumPost from .models import ForumPost
import pytz import pytz
from django.utils import timezone from django.utils import timezone
# helper function to convert utc datetime object to local time # helper function to convert utc datetime object to local time
def convert_utc_to_local(utctime, format): def convert_utc_to_local(utctime, format):
datetime_format = format datetime_format = format
...@@ -13,26 +15,35 @@ def convert_utc_to_local(utctime, format): ...@@ -13,26 +15,35 @@ def convert_utc_to_local(utctime, format):
def forum_post_list_view(request): def forum_post_list_view(request):
html_string_1 = '<html lang="en"><head><meta charset="UTF-8"><title>Forum Post List</title>' \ posts = ForumPost.objects.all().order_by('-pub_datetime')
'<h1>Forum Post List</h1></head><ul>' context = {
html_string_2 = '' 'posts': posts
for fp in ForumPost.objects.all(): }
html_string_2 += '<li><b style="font-size: 30px">{}</b>' \ return render(request, 'forum/forum.html', context)
' by <b style="font-size: large">{} {}</b>' \
' posted <b>{}</b><p>{}</p><ul>'.format(fp.title,
fp.author.first_name, class ForumPostDetailView(generic.DetailView):
fp.author.last_name, model = ForumPost
convert_utc_to_local(fp.pub_datetime, template_name = 'forum/forumpost-details.html'
'%d/%m/%Y %I:%M %p'), queryset = ForumPost.objects.all()
fp.body) context_object_name = 'posts'
for replies in fp.reply.all():
html_string_2 += '<li> Reply by <b>{} {}</b> ' \
'posted <b>{}</b><p>{}</p></li>'.format(replies.author.first_name, class ForumPostCreateView(generic.CreateView):
replies.author.last_name, model = ForumPost
convert_utc_to_local(replies.pub_datetime, template_name = 'forum/forumpost-add.html'
'%d/%m/%Y %I:%M %p'), fields = '__all__'
replies.body)
html_string_2 += '</ul></li>' def get_success_url(self):
html_string_final = html_string_1 + html_string_2 + '</ul></html>' return reverse('forum:forumpostdetailview', kwargs={ 'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
return HttpResponse(html_string_final)
class ForumPostUpdateView(generic.UpdateView):
model = ForumPost
template_name = 'forum/forumpost-edit.html'
fields = '__all__'
def get_success_url(self):
return reverse('forum:forumpostdetailview', kwargs={ 'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
\ No newline at end of file
...@@ -24,5 +24,5 @@ urlpatterns = [ ...@@ -24,5 +24,5 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('Assignments/', include('Assignments.urls', namespace="Assignments")), path('Assignments/', include('Assignments.urls', namespace="Assignments")),
path('', include(('forum.urls', 'forum'), namespace='forum')), path('', include(('forum.urls', 'forum'), namespace='forum')),
path('Dashboard/', include('Dashboard.urls', namespace="Dashboard")), # path('Dashboard/', include('Dashboard.urls', namespace="Dashboard")),
] ]
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