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): ...@@ -9,7 +9,7 @@ class Course(models.Model):
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self): def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section) return '{}-{}'.format(self.code, self.section)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)]) return reverse('course_detail', args=[str(self.section)])
......
from django.db import models from django.db import models
from Assignments.models import Course from Assignments.models import Course
from django.urls import reverse
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100) activity = models.CharField(max_length=100)
target_datetime = models.DateTimeField()
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey( location = models.ForeignKey(
'Location', 'Location',
...@@ -16,6 +17,7 @@ class Event(models.Model): ...@@ -16,6 +17,7 @@ class Event(models.Model):
def __str__(self): def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime) return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model): class Location(models.Model):
mode_choices = [ mode_choices = [
...@@ -31,5 +33,5 @@ class Location(models.Model): ...@@ -31,5 +33,5 @@ class Location(models.Model):
venue = models.CharField(max_length=200) venue = models.CharField(max_length=200)
def __str__(self): 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 @@ ...@@ -2,10 +2,14 @@
from django.urls import path from django.urls import path
from .views import index from .views import event_view, EventDetailView, EventCreateView, EventUpdateView
urlpatterns = [ 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" app_name = "calendar_app"
...@@ -8,35 +8,33 @@ ...@@ -8,35 +8,33 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event, Location 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 import datetime
def event_view(request):
event = Event.objects.all()
return render(request, 'calendar_app/calendar.html', {'event': event})
def index(request): class EventDetailView(DetailView):
total_objects = Event.objects.count() model = Event
page_format = "Widget's Calendar of Activities <br>" template_name = 'calendar_app/event-details.html'
#displays the details for each events class EventCreateView(CreateView):
for i in range(1,total_objects+1): model = Event
page_format += '<br>' + display_details(i) fields = '__all__'
return HttpResponse(page_format) template_name = 'calendar_app/event-add.html'
def display_details(index): #after creating form, sends user to detail page of created activity
#gets all the object's attributes def get_success_url(self):
event = Event.objects.get(pk=index) return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
date = event.target_datetime.date().strftime("%m/%d/%Y")
time = event.target_datetime.time().strftime("%I:%M %p") class EventUpdateView(UpdateView):
activity = event.activity model = Event
estimated_hours = event.estimated_hours fields = '__all__'
course_code = event.course.code template_name = 'calendar_app/event-edit.html'
course_title = event.course.title
section = event.course.section
mode = event.location.mode
venue = event.location.venue
#arrange all the details #after updating form, sends user to detail page of created activity
display = 'Date and Time: {}, {} <br>'.format(date,time) def get_success_url(self):
display += 'Activity: {} <br>'.format(activity) return reverse('calendar_app:event-details', kwargs={'pk': self.object.pk})
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
No preview for this file type
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %} {% block styles %}{% endblock %}
</head> </head>
<body> <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