Commit 8529e972 authored by Jonathan Talbot's avatar Jonathan Talbot

Merge branch 'main' into devera/announcements

parents c1678528 7ab0d4b9
# Group 3 - Lab 1: Widget
# Group 3
### Jonathan Talbot - Homepage
......@@ -9,5 +9,8 @@
### Giancarlo De Torres - Assignments
## Video link:
## Lab 1: Video link:
### https://drive.google.com/file/d/1iEkbHXomN2VUXBepXeVk2zCTFWFxRD0A/view?usp=sharing
## Lab 2: Video link:
### https://drive.google.com/file/d/1JqTDjraUkpCbQ_alrvoAGlDRjvGIuyL4/view?usp=sharing
\ No newline at end of file
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
search_fields = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name')
list_display = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name')
list_filter = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name')
fieldsets = [
('Announcement Data', {
'fields': [
'announcement_title',
'announcement_body',
'authors_First_Name',
'authors_Last_Name',
]
})
]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
search_fields = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_display = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_filter = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
fieldsets = [
('Department Data', {
'fields': [
'reaction_name1',
'tally1',
'reaction_name2',
'tally2',
'reaction_name3',
'tally3',
]
}),
]
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
from django.apps import AppConfig
class AnnouncementsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcements'
# Generated by Django 4.0.3 on 2022-05-22 10:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name1', models.CharField(max_length=15)),
('tally1', models.IntegerField(max_length=3)),
('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(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('announcement_title', models.CharField(max_length=50)),
('announcement_body', models.CharField(max_length=200)),
('authors_First_Name', models.CharField(max_length=20)),
('authors_Last_Name', models.CharField(max_length=20)),
('pub_date', models.DateTimeField(auto_now_add=True)),
('reaction', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='announcements.reaction')),
],
),
]
# 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}$')]),
),
]
from django.db import models
from django.urls import reverse
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):
announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200)
authors_First_Name = models.CharField(max_length=20)
authors_Last_Name = models.CharField(max_length=20)
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):
return reverse('Announcement', args=[(self.full_announcement)])
@property
def full_announcement(self):
return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import announcements
urlpatterns = [
path('', announcements, name='Announcement Board')
]
\ No newline at end of file
from django.http import HttpResponse
from .models import Announcement, Reaction
def announcements(request):
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
output = "ANNOUNCEMENTS:\n" + "\n".join(
['{} by {} {} dated by {}: \n {} \n'.format(
str(announcement.announcement_title),
str(announcement.authors_First_Name),
str(announcement.authors_Last_Name),
str(announcement.pub_date),
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 reaction in reactions]
)
return HttpResponse(output, content_type="text/plain")
from django.contrib import admin
from .models import Assignment, Course
class AssignmentInline(admin.TabularInline):
model = Assignment
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
search_fields = ('name', 'description', 'max_points')
list_display = ('name', 'description', 'max_points')
list_filter = ('name', 'description', 'max_points')
fieldsets = [
('Assignment Data', {
'fields': [
'name',
'description',
'max_points'
]
}
)
]
class CourseAdmin(admin.ModelAdmin):
model = Course
search_fields = ('course_code', 'course_title', 'section')
list_display = ('course_code', 'course_title', 'section')
list_filter = ('course_code', 'course_title', 'section')
fieldsets = [
('Course Data', {
'fields': [
'course_code',
'course_title',
'section'
]
}
)
]
inlines = [AssignmentInline,]
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assignments'
# Generated by Django 4.0.3 on 2022-05-22 10:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
('course', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models
from django.urls import reverse
class Course(models.Model):
course_code = models.CharField(max_length = 10)
course_title = models.CharField(max_length = 100)
section = models.CharField(max_length = 3)
def __str__(self):
return '{} {} {}'.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model):
name = models.CharField(max_length = 100)
description = models.CharField(max_length = 200)
max_points = models.IntegerField()
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
def get_absolute_url(self):
return reverse('assignment-detail', args=[(self.pk)])
@property
def full_assignment(self):
return '{} {} {}'.format(self.name, self.description, self.max_points)
@property
def passing_score(self):
return self.max_points * .6
<!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>Assignment List</title>
</head>
<body>
<h1>Assignments Per Course</h1>
{% for course in courses %}
<ul>
<li>{{ course.course_code }} {{ course.course_title }} {{ course.section }}
<ul>
{% for assignment in assignments %}
{%if assignment.course == course%}
<li><a href="{{assignment.get_absolute_url}}">{{assignment.name}}</a></li>
{%endif%}
{% endfor %}
</ul>
</li>
</ul>
{% endfor %}
</body>
</html>
<!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>Assignment Detail</title>
</head>
<body>
<p>{{assignment.name}}</p>
<p>{{assignment.description}}</p>
<p>Max Points: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p>
<p>{{assignment.course}}</p>
</body>
</html>
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import AssignmentListView, AssignmentDetailView
urlpatterns = [
path('', AssignmentListView.as_view(), name='assignment-list'),
path('<int:pk>/details', AssignmentDetailView, name='assignment-detail'),
]
\ No newline at end of file
from ast import Assign
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 Assignment, Course
# def assignments(request):
# assignments = Assignment.objects.all()
# courses = Course.objects.all()
# output = "ASSIGNMENTS:\n" + "\n".join(
# ['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
# .format(str(assignment.name),
# str(assignment.description),
# str(assignment.max_points),
# str(assignment.passing_score),
# str(assignment.course))
# for assignment in assignments]
# )
# return HttpResponse(output, content_type = "text/plain")
class AssignmentListView(View):
def get(self, request):
assignments = Assignment.objects.all()
courses = Course.objects.all()
context = {
'assignments': assignments,
'courses' : courses
}
return render(request, 'assignments/assignment_list.html', context)
def AssignmentDetailView(request, pk):
assignment = get_object_or_404(Assignment, pk=pk)
return render(request, 'assignments/assignments_detail.html', {
'assignment': assignment
})
# class AssignmentListView(ListView):
# model = Assignment
No preview for this file type
from django.contrib import admin
from .models import Post, Reply
class ReplyInline(admin.TabularInline):
model = Reply
class PostAdmin(admin.ModelAdmin):
model = Post
search_fields = ('post_title', 'post_body', 'pub_date', 'author')
list_display = ('post_title', 'post_body', 'pub_date', 'author')
list_filter = ('post_title', 'post_body', 'pub_date', 'author')
fieldsets = [
('Post Data', {
'fields': [
'post_title',
'post_body',
'author',
]
}),
]
inlines = [ReplyInline,]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
search_fields = ('reply_body', 'pub_date', 'author', 'replied_post')
list_display = ('reply_body', 'pub_date', 'author', 'replied_post')
list_filter = ('reply_body', 'pub_date', 'author', 'replied_post')
fieldsets = [
('Reply Data', {
'fields': [
'reply_body',
'author',
]
}),
]
admin.site.register(Post, PostAdmin)
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 4.0.3 on 2022-05-22 10:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('homepage', '__first__'),
]
operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post_title', models.CharField(max_length=50)),
('post_body', models.CharField(max_length=100)),
('pub_date', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=100)),
('pub_date', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
('replied_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.post')),
],
),
]
from django.db import models
from django.urls import reverse
from django.core.validators import RegexValidator
# Using WidgetUser from homepage
from homepage.models import WidgetUser
class Post(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
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)
def get_absolute_url(self):
return reverse('forum', args=[(self.post_title)])
class Reply(models.Model):
reply_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
replied_post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
return '\nReply by {} dated {}:\n {}'.format(self.author.full_name(), self.pub_date, self.reply_body)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import forum
urlpatterns = [
path('', forum, name='forum')
]
\ No newline at end of file
from django.http import HttpResponse
from .models import Post, Reply
def forum(request):
post = Post.objects.all()
reply = Reply.objects.all()
output = "FORUM POSTS: \n" + "\n".join([str(x) for x in post]) + "\n".join([str(z) for z in reply])
return HttpResponse(output, content_type="text/plain")
from django.contrib import admin
from .models import WidgetUser, Department
class WidgetUserInline(admin.TabularInline):
model = WidgetUser
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
fieldsets = [
('Widget User Data', {
'fields': [
'id_num',
'first_name',
'middle_name',
'last_name',
'email'
]
}),
]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
search_fields = ('dept_name', 'home_unit')
list_display = ('dept_name', 'home_unit')
list_filter = ('dept_name', 'home_unit')
fieldsets = [
('Department Data', {
'fields': [
'dept_name',
'home_unit',
]
}),
]
inlines = [WidgetUserInline,]
# Register Homepage Classes in admin
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
\ No newline at end of file
from django.apps import AppConfig
class HomepageConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'homepage'
from django import forms
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
from django.db import models
from django.urls import reverse
from django.core.validators import RegexValidator
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
id_num = models.CharField(max_length=7, validators=[RegexValidator(r'^\d{1,10}$')], primary_key=True)
first_name = models.CharField(max_length=90)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField()
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=1)
def get_absolute_url(self):
return reverse('widget_user-detail', args=[str(self.id_num)])
# return reverse('widget_user', args=[(self.full_name)])
def full_name(self):
return '{}, {} {}'.format(self.first_name, self.middle_name, self.last_name)
<!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>Add Widget User</title>
</head>
<body>
<h1>Add Widget User</h1>
</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>User Detail</title>
</head>
<body>
<p>{{user.last_name}},{{user.first_name}} {{user.middle_name}}</p>
<p>{{user.id_num}}</p>
<p>{{user.email}}</p>
<p>{{user.department.dept_name}}</p>
<p>{{user.department.home_unit}}</p>
</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>User List</title>
</head>
<body>
<h1>Welcome to Widget!</h1>
{% for user in object_list %}
<a href="{{ user.get_absolute_url }}"> {{ user.last_name }}, {{user.first_name}} {{user.middle_name}} </a> <br>
{% endfor %}
<a href="/users/add">test</a>
</body>
</html>
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import homepage, UserDetailView, UserListView
urlpatterns = [
path('', UserListView.as_view(), name='widget_user-list'),
path('<int:pk>/details', UserDetailView, name='widget_user-detail'),
]
\ No newline at end of file
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 WidgetUser, Department
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):
user = get_object_or_404(WidgetUser, pk=pk)
return render(request, 'homepage/widgetuser_detail.html', {
'user': user
})
class UserListView(ListView):
model = WidgetUser
\ No newline at end of file
from django.contrib import admin
from .models import WidgetUser, Forum, Announcement, Assignment
# Classes
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
search_fields = ('first_name', 'middle_name', 'last_name')
list_display = ('first_name', 'middle_name', 'last_name')
list_filter = ('first_name', 'middle_name', 'last_name')
fieldsets = [
('Widget User Data', {
'fields': [
'first_name',
'middle_name',
'last_name'
]
}),
]
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
search_fields = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
list_display = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
list_filter = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
fieldsets = [
('Announcement Data', {
'fields': [
'announcement_title',
'announcement_body',
'authors_First_Name',
'authors_Last_Name',
'pub_date',
]
})
]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
search_fields = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_display = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_filter = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
fieldsets = [
('Department Data', {
'fields': [
'reaction_name1',
'tally1',
'reaction_name2',
'tally2',
'reaction_name3',
'tally3',
]
}),
]
class ForumAdmin(admin.ModelAdmin):
model = Forum
search_fields = ('post_title', 'post_body', 'pub_date')
list_display = ('post_title', 'post_body', 'pub_date')
list_filter = ('post_title', 'post_body', 'pub_date')
fieldsets = [
('Forum Data', {
'fields': [
'post_title',
'post_body',
]
}),
]
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
search_fields = ('name', 'description', 'max_points')
list_display = ('name', 'description', 'max_points')
list_filter = ('name', 'description', 'max_points')
fieldsets = [
('Assignment Data', {
'fields': [
'name',
'description',
'max_points'
]
}
)
]
# Register models
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
# Generated by Django 4.0.3 on 2022-04-07 22:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('announcement_title', models.CharField(max_length=50)),
('announcement_body', models.CharField(max_length=200)),
('pub_date', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
],
),
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=100)),
('home_unit', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Forum',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post_title', models.CharField(max_length=50)),
('post_body', models.CharField(max_length=100)),
('pub_date', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id_num', models.IntegerField()),
('first_name', models.CharField(max_length=100)),
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('email', models.EmailField(max_length=254)),
('department', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='widget_group3.department')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-08 03:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_group3', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='first_name',
field=models.CharField(max_length=90),
),
]
# Generated by Django 4.0.3 on 2022-04-08 06:12
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_group3', '0002_alter_widgetuser_first_name'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.CharField(max_length=7, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')]),
),
]
from django.db import models
from django.urls import reverse
from django.core.validators import RegexValidator
class Reaction(models.Model):
reaction_name1 = models.CharField(max_length=15)
tally1 = models.IntegerField(max_length=3)
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)
class Announcement(models.Model):
announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200)
authors_First_Name = models.CharField(max_length=20)
authors_Last_Name = models.CharField(max length=20)
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):
return reverse('Announcement', args=[(self.full_announcement)])
@property
def full_announcement(self):
return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date)
class Forum(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
def __str__(self):
return self.post_title
def get_absolute_url(self):
return reverse('forum', args=[(self.post_title)])
class WidgetUser(models.Model):
first_name = models.CharField(max_length=100)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
def __str__(self):
return self.full_name
def get_absolute_url(self):
return reverse('widget_user', args=[(self.full_name)])
@property
def full_name(self):
return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name)
class Assignment(models.Model):
name = models.CharField(max_length = 100)
description = models.CharField(max_length = 200)
max_points = models.IntegerField()
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('assignment', args[(self.name)])
......@@ -40,7 +40,10 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'widget_group3'
'homepage',
'forum',
'assignments',
'announcements'
]
MIDDLEWARE = [
......
......@@ -13,14 +13,16 @@ 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.urls import path
from .views import homepage, forum, announcements, assignments
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', homepage, name='homepage'),
path('assignments/', assignments, name='assignments'),
path('announcements/', announcements, name='Announcement Board'),
path('forum/', forum, name='forum')
path('', include('homepage.urls'), name='Homepage'),
path('homepage/', include('homepage.urls'), name='Homepage'),
path('users/', include('homepage.urls'), name='Homepage'),
path('forum/', include('forum.urls'), name='Forum'),
path('assignments/', include('assignments.urls'), name='Assignments'),
path('announcements/', include('announcements.urls'), name='Announcement Board'),
]
from django.http import HttpResponse
def homepage(request):
return HttpResponse('Welcome to Widget!')
def assignments(request):
return HttpResponse('This is the Assignments page!')
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
output = "ANNOUNCEMENTS:\n" + "\n".join(
['{} by {} {} dated by {}: \n {} \n {}: {} \n {}: {} \n {}: {}'.format(
str(announcements.announcement_title),
str(announcements.authors_First_Name),
str(announcements.authors_Last_Name),
str(announcements.pub_date),
str(announcements.announcement_body),
str(reactions.reaction_name1),
str(reactions.tally1),
str(reactions.reaction_name2),
str(reactions.tally3),
str(reactions.reaction_name3),
)
for announcement in announcements]
)
def announcements(request):
return HttpResponse('This is the Announcement Board!')
def forum(request):
return HttpResponse('Welcome to Widget’s 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