added calendar app with some placeholder variables for assignments app

parent 8b0039aa
...@@ -2,7 +2,7 @@ CSCI 40-F ...@@ -2,7 +2,7 @@ CSCI 40-F
Group Members: Group Members:
CASTILLO, Gareth Xerxes CASTILLO, Gareth Xerxes
GARCIA, Ann Colleen GARCIA, Ann Colleen
OLIVARES, Christian Louis 193636 OLIVARES, Christian Louis
204374 RODRIGUEZ, Neal Luigi D. 204374 RODRIGUEZ, Neal Luigi D.
204655 SEE, Eurydice Gabrielle Madison O. 204655 SEE, Eurydice Gabrielle Madison O.
......
...@@ -40,6 +40,7 @@ INSTALLED_APPS = [ ...@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'widgetcalendar'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
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 include, path
urlpatterns = [ urlpatterns = [
path('widgetcalendar/', include('widgetcalendar.urls', namespace="calendar")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
from django.contrib import admin
from .models import Location, Event
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = ('mode', 'venue')
class Eventadmin(admin.ModelAdmin):
model = Event
list_display = ('target_datetime', 'activity', 'estimated_hours', 'location', 'course')
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin.site.register(Location, LocationAdmin)
admin.site.register(Event, Eventadmin)
\ No newline at end of file
from django.apps import AppConfig
class WidgetcalendarConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'widgetcalendar'
# Generated by Django 4.1.7 on 2023-03-02 12:44
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')], max_length=6)),
('venue', models.CharField(default='', max_length=50)),
],
),
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(default='', max_length=100)),
('estimated_hours', models.FloatField()),
('course', models.CharField(max_length=50)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='course_name', to='widgetcalendar.location')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 06:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widgetcalendar', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='location',
name='venue',
field=models.TextField(default='', max_length=200),
),
]
from django.db import models
from django.urls import reverse
#FOR LUIGI: PLS UNCOMMENT WHEN YOU'RE DONE WITH YOUR APPS
#from assignments.models import Course
class Location(models.Model):
MODE_CHOICES = (
('onsite', 'onsite'),
('online', 'online'),
('hybrid', 'hybrid'),
)
mode = models.CharField(max_length=6, choices=MODE_CHOICES)
venue = models.TextField(max_length=200, default='')
def __str__(self):
return '{}, {} mode'.format(self.venue, self.mode)
def get_absolute_url(self):
return reverse('location_detail', args=[str(self.venue)])
class Event(models.Model):
target_datetime= models.DateTimeField()
activity = models.TextField(max_length=200, default='')
estimated_hours = models.FloatField()
location = models.ForeignKey(
Location,
on_delete=models.CASCADE,
related_name='course_name'
)
#FOR LUIGI: IF YOU'RE DONE PLS REPLACE THE CURRENT CODE FOR COURSE WITH THE COMMENTED ONE
# course = models.ForeignKey(
# Course,
# on_delete=models.CASCADE,
# related_name='course_name'
# )
course = models.CharField(max_length=50)
def __str__(self):
return '{}'.format(self.activity)
def get_absolute_url(self):
return reverse('event_detail', args=[str(self.activity)])
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 = "widgetcalendar"
\ No newline at end of file
from django.http import HttpResponse
from .models import Event
#Date format source: https://ourcodeworld.com/articles/read/555/how-to-format-datetime-objects-in-the-view-and-template-in-django
def index(request):
return_string = ''
for events in Event.objects.all():
return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Secion: {}<br>Mode: {}<br>Venue: {}<br></br>'.format(
events.target_datetime.strftime("%x, %I:%M %p"), events.activity, events.estimated_hours, events.course, events.location.mode, events.location.venue
)
html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string)
return HttpResponse(html_string)
\ 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