Commit cc64cb6e authored by mantlei's avatar mantlei

merged calendar_app into master

parents f8e7bddb 5abd66dd
...@@ -6,6 +6,7 @@ BS Computer Science CSCI 40-E ...@@ -6,6 +6,7 @@ BS Computer Science CSCI 40-E
# in alphabetical order by last name # in alphabetical order by last name
Amador, John Michael T. 206105 Amador, John Michael T. 206105
Andrada, Alvin Joshua M. 195478 Andrada, Alvin Joshua M. 195478
Rodillas, Ron Lawrence C. 204364
Fausto, Brendan Gabrielle M. 202033 Fausto, Brendan Gabrielle M. 202033
Paeldon, Marco Anton O. 193752 Paeldon, Marco Anton O. 193752
...@@ -16,19 +17,26 @@ Widget v1 ...@@ -16,19 +17,26 @@ Widget v1
Amador - Assignments App Amador - Assignments App
Andrada - Calendar App Andrada - Calendar App
Fausto - Dashboard App Fausto - Dashboard App
Rodillas - Forum App
Paeldon- Announcements App Paeldon- Announcements App
# date of submission; # date of submission;
4 March 2023
# a statement, in your group’s own words, that the project was truthfully completed by your group; # a statement, in your group’s own words, that the project was truthfully completed by your group;
This project was accomplished truthfully only by the people whose names are listed above. This project was accomplished truthfully only by the people whose names are listed above.
(lol di ko alam please check - alvin) (lol di ko alam please check - alvin)
# list of references used; and # list of references used;
Queries - Django Documentation
https://docs.djangoproject.com/en/4.1/topics/db/queries/#retrieving-a-single-object-with-get
Datetime Import
https://docs.python.org/3/library/datetime.html
# members’ signatures in the form (sgd) your complete name, date # members’ signatures in the form (sgd) your complete name, date
John Michael T. Amador (sgd) February 28, 2023 John Michael T. Amador (sgd) February 28, 2023
Alvin Joshua M. Andrada (sgd) March 2, 2023 Alvin Joshua M. Andrada (sgd) March 2, 2023
Ron Lawrence C. Rodillas (sgd) March 5, 2023
Brendan Gabrielle M. Fausto (sgd) March 6, 2023 Brendan Gabrielle M. Fausto (sgd) March 6, 2023
Marco Anton O. Paeldon (sgd) March 6, 2023 Marco Anton O. Paeldon (sgd) March 6, 2023
from django.contrib import admin
from .models import Event, Location
class EventInline(admin.TabularInline):
model = Event
class EventAdmin(admin.ModelAdmin):
model = Event
class LocationAdmin(admin.ModelAdmin):
model = Location
#Shows all events that occur at the same location
inlines = [EventInline,]
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
from django.apps import AppConfig
class CalendarAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'calendar_app'
# Generated by Django 4.1.7 on 2023-03-02 17:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mode', models.CharField(choices=[('onsite', 'onsite'), ('online', 'online'), ('hybrid', 'hybrid')], default='onsite', max_length=6)),
('venue', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField()),
('activity', models.CharField(max_length=100)),
('estimated_hours', models.FloatField()),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendar_app.location')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-02 22:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0005_rename_assignments_assignment'),
('calendar_app', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='event',
name='course',
field=models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='Assignments.course'),
preserve_default=False,
),
]
from django.db import models
from Assignments.models import Course
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100)
estimated_hours = models.FloatField()
location = models.ForeignKey(
'Location',
on_delete = models.CASCADE,
)
course = models.ForeignKey(
'Assignments.Course',
on_delete = models.CASCADE,
)
def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model):
mode_choices = [
('onsite','onsite'),
('online','online'),
('hybrid','hybrid'),
]
mode = models.CharField(
max_length=6,
choices=mode_choices,
default='onsite',
)
venue = models.CharField(max_length=200)
def __str__(self):
return self.venue
from django.test import TestCase
# Create your tests here.
#calendar_app/urls
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "calendar_app"
#References:
# Queries - Django Documentation
# https://docs.djangoproject.com/en/4.1/topics/db/queries/#retrieving-a-single-object-with-get
# Datetime Import
# https://docs.python.org/3/library/datetime.html
from django.shortcuts import render
from django.http import HttpResponse
from .models import Event, Location
import datetime
def index(request):
total_objects = Event.objects.count()
page_format = "Widget's Calendar of Activities <br>"
#displays the details for each events
for i in range(1,total_objects+1):
page_format += '<br>' + display_details(i)
return HttpResponse(page_format)
def display_details(index):
#gets all the object's attributes
event = Event.objects.get(pk=index)
date = event.target_datetime.date().strftime("%m/%d/%Y")
time = event.target_datetime.time().strftime("%I:%M %p")
activity = event.activity
estimated_hours = event.estimated_hours
course_code = event.course.code
course_title = event.course.title
section = event.course.section
mode = event.location.mode
venue = event.location.venue
#arrange all the details
display = 'Date and Time: {}, {} <br>'.format(date,time)
display += 'Activity: {} <br>'.format(activity)
display += 'Estimated Hours {} <br>'.format(estimated_hours)
display += 'Course/Section: {} {}-{} <br>'.format(course_code,course_title,section)
display += 'Mode: {} <br>'.format(mode)
display += 'Venue: {} <br>'.format(venue)
return display
\ No newline at end of file
from django.contrib import admin
from .models import ForumPost, Reply
# Register your models here.
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ('title', 'author', 'pub_datetime')
search_fields = ('title', 'author')
list_filter = ('pub_datetime',)
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ('author', 'pub_datetime')
search_fields = ('author',)
list_filter = ('pub_datetime',)
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 4.1.7 on 2023-03-05 07:32
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
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.TextField()),
('author', models.CharField(max_length=100)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('author', models.CharField(max_length=100)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
],
),
]
# Generated by Django 4.1.7 on 2023-03-05 11:48
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='reply_to',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost'),
preserve_default=False,
),
]
# Generated by Django 4.1.7 on 2023-03-06 06:08
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_reply_reply_to'),
]
operations = [
migrations.RenameField(
model_name='reply',
old_name='reply_to',
new_name='forum_post',
),
]
from django.db import models
# Create your models here.
class ForumPost (models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
class Reply (models.Model):
body = models.TextField()
author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField(auto_now_add=True)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name="forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here.
def index(request):
return_string = "Widget's Forums <br> <br> Forum Posts:<br>"
for i in ForumPost.objects.all():
return_string+=(
i.title + " by " + i.author + " posted " + i.datetime_posted() + ":<br>"
+ i.body + "<br>"
)
for n in Reply.objects.all():
if n.forum_post == i:
return_string+=(
"Reply by " + n.author + " posted " + n.datetime_posted() + ":<br>"
+ n.body + "<br>"
)
return_string+="<br>"
return HttpResponse(return_string)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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