Commit 1bd9dab5 authored by Alvin Joshua Andrada's avatar Alvin Joshua Andrada

implemented all calendar pages

parent 9cea9e55
......@@ -9,7 +9,7 @@ class Course(models.Model):
section = models.CharField(max_length=3)
def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section)
return '{}-{}'.format(self.code, self.section)
def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)])
......
from django.db import models
from Assignments.models import Course
from django.urls import reverse
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100)
target_datetime = models.DateTimeField()
estimated_hours = models.FloatField()
location = models.ForeignKey(
'Location',
......@@ -17,6 +18,7 @@ class Event(models.Model):
def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model):
mode_choices = [
('onsite','onsite'),
......@@ -31,5 +33,5 @@ class Location(models.Model):
venue = models.CharField(max_length=200)
def __str__(self):
return self.venue
return '{} - {}'.format(self.mode, self.venue)
<!-- calendar html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<h1>Widget's Calendar of Activities</h1>
{%for object in event%}
<a href="{% url 'calendar_app:event-details' object.id %}">{{ object.activity }}</a>
<br>
{%endfor%}
<br>
<a href="{% url 'calendar_app:event-add'%}"><button>New Activity</button></a> <br> <br>
<a href="/dashboard">Dashboard</a>
<br>
<a href="/announcements">Announcements</a>
<br>
<a href="/forum">Forum</a>
<br>
<a href="/assignments">Assignments</a>
<br>
{% endblock %}
<!-- event add -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Add a new activity:
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
\ No newline at end of file
<!-- event details -->
{% extends 'base.html' %}
{% block title %} {{object.activity}} {% endblock %}
{% block content %}
<h1>{{ object.activity }}</h1>
<h3>Date and Time: {{ object.target_datetime | date:"m/d/Y, h:i A" }}</h3>
<h3>Estimated Hours: {{ object.estimated_hours }}</h3>
<h3>{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }}</h3>
<h3>Mode: {{ object.location.mode }} </h3>
<h3>Venue: {{ object.location.venue }}</h3>
<a href="{% url 'calendar_app:event-edit' object.id %}"><button>Edit Activity</button></a>
{% endblock %}
<!-- event-edit -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Edit activity:
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,10 +2,14 @@
from django.urls import path
from .views import index
from .views import event_view, EventDetailView, EventCreateView, EventUpdateView
urlpatterns = [
path('', index, name='index'),
path('', event_view, name='event_view'),
path('events/<int:pk>/details/', EventDetailView.as_view(), name='event-details'),
path('events/add', EventCreateView.as_view(), name='event-add'),
path('events/<int:pk>/edit', EventUpdateView.as_view(), name='event-edit'),
]
app_name = "calendar_app"
......@@ -8,35 +8,33 @@
from django.shortcuts import render
from django.http import HttpResponse
from .models import Event, Location
from django.views.generic import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.urls import reverse
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
def event_view(request):
event = Event.objects.all()
return render(request, 'calendar_app/calendar.html', {'event': event})
class EventDetailView(DetailView):
model = Event
template_name = 'calendar_app/event-details.html'
class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = 'calendar_app/event-add.html'
#after creating form, sends user to detail page of created activity
def get_success_url(self):
return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'calendar_app/event-edit.html'
#after updating form, sends user to detail page of created activity
def get_success_url(self):
return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
No preview for this file type
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
<title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
......
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