Commit f9ddc191 authored by Jonathan Talbot's avatar Jonathan Talbot

Merge branch 'main' into detorres/assignments

parents f1e47d65 9655250f
File added
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction from .models import Announcement, Reaction
class ReactionInline(admin.TabularInline):
model = Reaction
class AnnouncementAdmin(admin.ModelAdmin): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
...@@ -15,28 +17,25 @@ class AnnouncementAdmin(admin.ModelAdmin): ...@@ -15,28 +17,25 @@ class AnnouncementAdmin(admin.ModelAdmin):
'announcement_title', 'announcement_title',
'announcement_body', 'announcement_body',
'authors_First_Name', 'authors_First_Name',
'authors_Last_Name', 'authors_Last_Name'
] ]
}) })
] ]
inlines = [ReactionInline,]
class ReactionAdmin(admin.ModelAdmin): class ReactionAdmin(admin.ModelAdmin):
model = Reaction model = Reaction
search_fields = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3') search_fields = ('reaction_name', 'tally')
list_display = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3') list_display = ('reaction_name', 'tally')
list_filter = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3') list_filter = ('reaction_name', 'tally')
fieldsets = [ fieldsets = [
('Department Data', { ('Reaction Data', {
'fields': [ 'fields': [
'reaction_name1', 'reaction_name',
'tally1', 'tally',
'reaction_name2',
'tally2',
'reaction_name3',
'tally3',
] ]
}), }),
] ]
......
# Generated by Django 4.0.3 on 2022-05-22 10:59 # Generated by Django 4.0.3 on 2022-05-23 00:24
import django.core.validators
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -16,12 +17,8 @@ class Migration(migrations.Migration): ...@@ -16,12 +17,8 @@ class Migration(migrations.Migration):
name='Reaction', name='Reaction',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name1', models.CharField(max_length=15)), ('reaction_name', models.CharField(max_length=15)),
('tally1', models.IntegerField(max_length=3)), ('tally', models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')])),
('reaction_name2', models.CharField(max_length=15)),
('tally2', models.IntegerField(max_length=3)),
('reaction_name3', models.CharField(max_length=15)),
('tally3', models.IntegerField(max_length=3)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
......
# Generated by Django 4.0.3 on 2022-05-22 11:01
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='tally1',
field=models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')]),
),
migrations.AlterField(
model_name='reaction',
name='tally2',
field=models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')]),
),
migrations.AlterField(
model_name='reaction',
name='tally3',
field=models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')]),
),
]
# Generated by Django 4.0.3 on 2022-05-23 00:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
),
]
...@@ -2,14 +2,6 @@ from django.db import models ...@@ -2,14 +2,6 @@ from django.db import models
from django.urls import reverse from django.urls import reverse
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
class Reaction(models.Model):
reaction_name1 = models.CharField(max_length=15)
tally1 = models.CharField(max_length=3, validators=[RegexValidator(r'^\d{1,10}$')])
reaction_name2 = models.CharField(max_length=15)
tally2 = models.CharField(max_length=3, validators=[RegexValidator(r'^\d{1,10}$')])
reaction_name3 = models.CharField(max_length=15)
tally3 = models.CharField(max_length=3, validators=[RegexValidator(r'^\d{1,10}$')])
class Announcement(models.Model): class Announcement(models.Model):
announcement_title= models.CharField(max_length=50) announcement_title= models.CharField(max_length=50)
...@@ -17,13 +9,17 @@ class Announcement(models.Model): ...@@ -17,13 +9,17 @@ class Announcement(models.Model):
authors_First_Name = models.CharField(max_length=20) authors_First_Name = models.CharField(max_length=20)
authors_Last_Name = models.CharField(max_length=20) authors_Last_Name = models.CharField(max_length=20)
pub_date = models.DateTimeField(auto_now_add=True, editable=False) pub_date = models.DateTimeField(auto_now_add=True, editable=False)
reaction = models.ForeignKey(Reaction, on_delete=models.CASCADE, default=1)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('Announcement', args=[(self.full_announcement)]) return reverse('announcement-detail', args=[(self.pk)])
@property @property
def full_announcement(self): def full_announcement(self):
return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date) return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date)
class Reaction(models.Model):
reaction_name = models.CharField(max_length=15)
tally = models.CharField(max_length=3, validators=[RegexValidator(r'^\d{1,10}$')])
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, default=1)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Announcement Detail</title>
</head>
<body>
<h2>{{ announcement.announcement_title }}</h2>
<h3>by {{ announcement.First_Name }} {{ announcement.Last_Name }}, {{ announcement.pub_date|date:"d/m/yy" }}</h3>
<p>{{ announcement.announcement_body }}</p>
<hr>
{% for reaction in reactions %}
{%if reaction.announcement == announcement %}
<p>{{ reaction.reaction_name }} : {{ reaction.tally }}</p>
{%endif%}
{% endfor %}
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Announcements List</title>
</head>
<body>
<h1>Important Announcements:</h1>
{% for announcement in announcements %}
<a href="{{ announcement.get_absolute_url }}">{{ announcement.announcement_title }} by {{ announcement.authors_First_Name }} {{ announcement.authors_Last_Name }} dated {{ announcement.pub_date }}</a>
<br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import announcements from .views import AnnouncementListView, AnnouncementDetailView
urlpatterns = [ urlpatterns = [
path('', announcements, name='Announcement Board') path('', AnnouncementListView.as_view(), name='announcement-list'),
path('<int:pk>/details', AnnouncementDetailView, name='announcement-detail'),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Announcement, Reaction from .models import Announcement, Reaction
def announcements(request): # def announcements(request):
announcements = Announcement.objects.all() # announcements = Announcement.objects.all()
reactions = Reaction.objects.all() # reactions = Reaction.objects.all()
output = "ANNOUNCEMENTS:\n" + "\n".join( # output = "ANNOUNCEMENTS:\n" + "\n".join(
['{} by {} {} dated by {}: \n {} \n'.format( # ['{} by {} {} dated by {}: \n {} \n'.format(
str(announcement.announcement_title), # str(announcement.announcement_title),
str(announcement.authors_First_Name), # str(announcement.authors_First_Name),
str(announcement.authors_Last_Name), # str(announcement.authors_Last_Name),
str(announcement.pub_date), # str(announcement.pub_date),
str(announcement.announcement_body), # str(announcement.announcement_body),
) # )
# for announcement in announcements]
# ) + "REACTIONS:\n" + "\n".join(
# ['{}: {} \n {}: {} \n {}: {}'.format(
# str(reaction.reaction_name1),
# str(reaction.tally1),
# str(reaction.reaction_name2),
# str(reaction.tally2),
# str(reaction.reaction_name3),
# str(reaction.tally3),
# )
for announcement in announcements] # for reaction in reactions]
) + "REACTIONS:\n" + "\n".join( # )
['{}: {} \n {}: {} \n {}: {}'.format( # return HttpResponse(output, content_type="text/plain")
str(reaction.reaction_name1),
str(reaction.tally1),
str(reaction.reaction_name2),
str(reaction.tally2),
str(reaction.reaction_name3),
str(reaction.tally3),
)
for reaction in reactions] class AnnouncementListView(View):
) def get(self, request):
return HttpResponse(output, content_type="text/plain") announcements = Announcement.objects.order_by('pub_date').all()
context = {
'announcements': announcements,
}
return render(request, 'announcements/announcements_list.html', context)
def AnnouncementDetailView(request, pk):
announcement = get_object_or_404(Announcement, pk=pk)
reactions = Reaction.objects.all()
return render(request, 'announcements/announcements_detail.html', {
'announcement': announcement,
'reactions': reactions
})
No preview for this file type
from django.forms import ModelForm
from .models import Post
class PostForm(ModelForm):
class Meta:
model = Post
fields = ['post_title', 'post_body', 'author'] # Selected fields for the form
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.core.validators import RegexValidator
# Using WidgetUser from homepage # Using WidgetUser from homepage
from homepage.models import WidgetUser from homepage.models import WidgetUser
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField('Title', max_length=100)
post_body = models.CharField(max_length=100) post_body = models.CharField('Body', max_length=1000)
pub_date = models.DateTimeField(auto_now_add=True, editable=False) pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
# author_name = WidgetUser.objects.get(fk=author).full_name()
def __str__(self):
return '{} by {} dated {}:\n {}'.format(self.post_title, self.author.full_name(), self.pub_date, self.post_body)
# Takes URL to ForumDetailView
def get_absolute_url(self): def get_absolute_url(self):
return reverse('forum', args=[(self.post_title)]) return reverse('Details', args=[(self.pk)])
def get_author_name(self):
return str(self.author.first_name + " " + self.author.last_name)
author_name = get_author_name
class Reply(models.Model): class Reply(models.Model):
reply_body = models.CharField(max_length=100) reply_body = models.CharField(max_length=500)
pub_date = models.DateTimeField(auto_now_add=True, editable=False) pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
replied_post = models.ForeignKey(Post, on_delete=models.CASCADE) replied_post = models.ForeignKey(Post, related_name = 'replies', on_delete=models.CASCADE)
def get_author_name(self):
return str(self.author.first_name + " " + self.author.last_name)
def __str__(self): author_name = get_author_name
return '\nReply by {} dated {}:\n {}'.format(self.author.full_name(), self.pub_date, self.reply_body) \ No newline at end of file
\ No newline at end of file
{% block content %}
<h3>{{post.post_title}}</h3>
<p>by {{post.author_name}}, {{post.pub_date|date:"d/m/Y"}}<p>
{{post.post_body}}
<ul>
{% for reply in post.replies.all %}
<li>
{{reply.author_name}}, {{reply.pub_date|date:"d/m/Y"}}:<br>
{{reply.reply_body}}
</li>
{% endfor %}
</ul>
<a href="{% url 'Forum' %}">Back to Forum</a>
{% endblock %}
\ No newline at end of file
{% block content %}
<h3>New Forum Post</h3>
<form action="{% url 'Add' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Post">
</form>
<a href="{% url 'Forum' %}">Back to Forum</a>
{% endblock %}
\ No newline at end of file
{% block content %}
{% block title %}Welcome to Widget’s Forum!{% endblock %}
<p>Forum posts:</p>
{% if post_list %}
<ul>
{% for post in post_list %}
<li>
<a href="{{ post.get_absolute_url }}">{{ post.post_title }}</a> by {{post.author_name}} dated {{post.pub_date|date:"d/m/Y"}}<br>
</li>
{% endfor %}
</ul>
{% else %}
<p>There are no posts.</p>
{% endif %}
<p><a href="{% url 'Add' %}">New Forum Post</a></p>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import forum from . import views
from .views import ForumListView, ForumDetailView
urlpatterns = [ urlpatterns = [
path('', forum, name='forum') path('', ForumListView.as_view(), name='Forum'),
path('<int:pk>/details/', ForumDetailView.as_view(), name='Details'),
path('add/', views.addPost, name='Add'),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.views.generic import ListView, DetailView
from .models import Post, Reply from django.shortcuts import render, redirect
from django.db import models
from .models import Post
from .forms import PostForm
def forum(request): class ForumListView(ListView):
post = Post.objects.all() queryset = Post.objects.order_by('-pub_date') # Orders publication by most recent
reply = Reply.objects.all() context_object_name = "post_list"
output = "FORUM POSTS: \n" + "\n".join([str(x) for x in post]) + "\n".join([str(z) for z in reply]) template_name = "post_list.html"
return HttpResponse(output, content_type="text/plain")
class ForumDetailView(DetailView):
model = Post
template_name = "forum/post_detail.html"
def addPost(request):
form = PostForm()
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
form.pub_date = models.DateTimeField(auto_now_add=True, editable=False) # Sets current time as pub_date
new_post = form.save() # Creates new post
return redirect('Details', pk=new_post.pk) # Redirects to detailed view of new post
else:
form = PostForm()
context = {'form':form}
return render(request,'forum/post_form.html', context) # Takes post_form template and displays form and post button
\ No newline at end of file
from django import forms from django.forms import ModelForm
from .models import WidgetUser
class IndexCardForm(forms.Form): class WidgetUserForm(ModelForm):
name = forms.CharField(label='Full Name', max_length=100) class Meta:
section = forms.CharField(label='CSCI40 Section', max_length=5) model = WidgetUser
age = forms.IntegerField(label='Current Age') fields = ['last_name', 'first_name', 'middle_name', 'id_num', 'email', 'department'] # Selected fields for the form
\ No newline at end of file \ No newline at end of file
...@@ -12,5 +12,7 @@ ...@@ -12,5 +12,7 @@
<p>{{user.email}}</p> <p>{{user.email}}</p>
<p>{{user.department.dept_name}}</p> <p>{{user.department.dept_name}}</p>
<p>{{user.department.home_unit}}</p> <p>{{user.department.home_unit}}</p>
<hr>
<a href="{% url 'widget_user-list' %}">Back to Homepage</a>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -8,5 +8,13 @@ ...@@ -8,5 +8,13 @@
</head> </head>
<body> <body>
<h1>Add Widget User</h1> <h1>Add Widget User</h1>
<hr>
<form action="{% url 'widget_user-add' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save WidgetUser">
</form>
<hr>
<a href="{% url 'widget_user-list' %}">Back to Homepage</a>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -8,10 +8,18 @@ ...@@ -8,10 +8,18 @@
</head> </head>
<body> <body>
<h1>Welcome to Widget!</h1> <h1>Welcome to Widget!</h1>
<hr>
<p>Widget Users:</p>
{% if object_list %}
<ul>
{% for user in object_list %} {% for user in object_list %}
<a href="{{ user.get_absolute_url }}"> {{ user.last_name }}, {{user.first_name}} {{user.middle_name}} </a> <br> <li><a href="{{ user.get_absolute_url }}"> {{ user.last_name }}, {{user.first_name}} {{user.middle_name}} </a></li><br>
{% endfor %} {% endfor %}
</ul>
<a href="/users/add">test</a> {% else %}
<p>There are no widget users.</p>
{% endif %}
<hr>
<a href="{% url 'widget_user-add' %}"><button>Add Widget User</button></a>
</body> </body>
</html> </html>
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import homepage, UserDetailView, UserListView from .views import UserDetailView, UserListView, addWidgetUser
urlpatterns = [ urlpatterns = [
path('', UserListView.as_view(), name='widget_user-list'), path('', UserListView.as_view(), name='widget_user-list'),
path('<int:pk>/details', UserDetailView, name='widget_user-detail'), path('<int:pk>/details', UserDetailView, name='widget_user-detail'),
path('add/', addWidgetUser, name='widget_user-add'),
] ]
\ No newline at end of file
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404, redirect
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from .models import WidgetUser, Department from .models import WidgetUser, Department
from .forms import WidgetUserForm
class homepage(View):
def get(self, request):
widget_users = WidgetUser.objects.all()
context = {
'widget_users': widget_users,
}
return render(request, 'homepage/homepage.html', context)
def UserDetailView(request, pk): def UserDetailView(request, pk):
user = get_object_or_404(WidgetUser, pk=pk) user = get_object_or_404(WidgetUser, pk=pk)
...@@ -19,4 +13,18 @@ def UserDetailView(request, pk): ...@@ -19,4 +13,18 @@ def UserDetailView(request, pk):
}) })
class UserListView(ListView): class UserListView(ListView):
model = WidgetUser queryset = WidgetUser.objects.order_by('last_name') # Orders by last name alphabetically
\ No newline at end of file context_object_name = "post_list"
template_name = "post_list.html"
def addWidgetUser(request):
form = WidgetUserForm()
if request.method == 'POST':
form = WidgetUserForm(request.POST)
if form.is_valid():
new_widgetuser = form.save() # Creates new widget user
return redirect('widget_user-detail', pk=new_widgetuser.pk) # Redirects to detailed view of new widget user
else:
form = WidgetUserForm()
context = {'form':form}
return render(request,'homepage/widgetuser_form.html', context)
\ No newline at end of file
"""widget_group3 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
...@@ -23,6 +8,7 @@ urlpatterns = [ ...@@ -23,6 +8,7 @@ urlpatterns = [
path('homepage/', include('homepage.urls'), name='Homepage'), path('homepage/', include('homepage.urls'), name='Homepage'),
path('users/', include('homepage.urls'), name='Homepage'), path('users/', include('homepage.urls'), name='Homepage'),
path('forum/', include('forum.urls'), name='Forum'), path('forum/', include('forum.urls'), name='Forum'),
path('posts/', include('forum.urls'), name='Forum'),
path('assignments/', include('assignments.urls'), name='Assignments'), path('assignments/', include('assignments.urls'), name='Assignments'),
path('announcements/', include('announcements.urls'), name='Announcement Board'), path('announcements/', include('announcements.urls'), name='Announcement Board'),
] ]
\ No newline at end of file
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