Commit 59df4fba authored by Giancarlo Angelo U. de Torres's avatar Giancarlo Angelo U. de Torres

Merge branch 'main' into detorres/assignments

parents 226f998b b402ce28
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', args=[(self.full_assignment)])
@property
def full_assignment(self):
return '{} {} {}'.format(self.name, self.description, self.max_points)
@property
def passing_score(self):
return self.max_points * .6
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import assignments
urlpatterns = [
path('', assignments, name='Assignments')
]
\ No newline at end of file
from django.http import HttpResponse
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")
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.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}$')])
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', args=[(self.full_name)])
def full_name(self):
return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import homepage
urlpatterns = [
path('', homepage, name='homepage')
]
\ No newline at end of file
from django.http import HttpResponse
from .models import WidgetUser, Department
def homepage(request):
widget_users = WidgetUser.objects.all()
output = "WIDGET USERS:\n" + "\n".join(
['{}, {} {}: {}, {}, {}'.format(str(user.last_name),
str(user.first_name),
str(user.middle_name),
str(user.id_num),
str(user.email),
str(user.department))
for user in widget_users]
)
return HttpResponse(output, content_type="text/plain")
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from .models import WidgetUser, Forum, Announcement, Assignment, Course
# 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', 'pub_date')
list_display = ('announcement_title', 'announcement_body', 'pub_date')
list_filter = ('announcement_title', 'announcement_body', 'pub_date')
fieldsets = [
('Announcement Data', {
'fields': [
'announcement_title',
'announcement_body',
]
})
]
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 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',
'passing_score'
]
}
)
]
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,]
# Register models
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ 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
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 Announcement(models.Model):
announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
def __str__(self):
return self.full_announcement
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 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', args=[(self.full_assignment)])
@property
def full_assignment(self):
return '{} {} {}'.format(self.name, self.description, self.max_points)
@property
def passing_score(self):
return self.max_points * .6
...@@ -40,7 +40,10 @@ INSTALLED_APPS = [ ...@@ -40,7 +40,10 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'widget_group3' 'homepage',
'forum',
'assignments',
'announcements'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -13,14 +13,15 @@ Including another URLconf ...@@ -13,14 +13,15 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 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 from django.urls import path, include
from .views import homepage, forum, announcements, assignments
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', homepage, name='homepage'), path('', include('homepage.urls'), name='Homepage'),
path('assignments/', assignments, name='assignments'), path('homepage/', include('homepage.urls'), name='Homepage'),
path('announcements/', announcements, name='Announcement Board'), path('forum/', include('forum.urls'), name='Forum'),
path('forum/', forum, name='forum') path('assignments/', include('assignments.urls'), name='Assignments'),
path('announcements/', include('announcements.urls'), name='Announcement Board'),
] ]
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser, Forum, Announcement, Assignment, Course
def homepage(request):
return HttpResponse('Welcome to Widget!')
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")
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