Created calendar.html in templates

parent 77a89ab8
from django.db import models from django.db import models
from django.urls import reverse
from datetime import datetime from datetime import datetime
from assignments.models import Course from assignments.models import Course
...@@ -12,6 +12,7 @@ class Location(models.Model): ...@@ -12,6 +12,7 @@ class Location(models.Model):
return '{} {}'.format(self.mode, self.venue) return '{} {}'.format(self.mode, self.venue)
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField(default=datetime.now()) target_datetime = models.DateTimeField(default=datetime.now())
activity = models.CharField(max_length=100, default="") activity = models.CharField(max_length=100, default="")
...@@ -23,8 +24,11 @@ class Event(models.Model): ...@@ -23,8 +24,11 @@ class Event(models.Model):
location = models.ForeignKey( location = models.ForeignKey(
Location, Location,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='Venue' related_name='venues'
) )
def __str__(self): def __str__(self):
return "{} {} {} {}".format(self.target_datetime, self.activity, self.estimated_hours, self.location) return "{} {} {} {}".format(self.target_datetime, self.activity, self.estimated_hours, self.location)
def get_absolute_url(self):
return reverse('calendar:calender-details', kwargs={'pk': self.pk})
+{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block heading %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<ul>
{% for event in events %}
<li>
<a href="#">
{{ event }}</a>
</li>
{% endfor %}
</ul>
<button onclick="window.location.href='#';">
New Activity
</button>
<div id="footer">
<a href="{% url 'dashboard:index' %}">Dashboard</a>
<a href="{% url 'announcementBoard:index' %}">Announcement Board</a>
<a href="{% url 'forum:index' %}">Forum</a>
<a href="{% url 'assignments:homePage' %}">Assignments</a>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import index
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('calendar/', index, name='index')
] ]
app_name = "widget_calendar" app_name = "widget_calendar"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic.detail import DetailView
from .models import Event, Location from .models import Event, Location
def index(request): def index(request):
events = Event.objects.all()
head = "<h1 style='border-bottom:4px solid lightgray;\ return render(request, 'calendar/calendar.html',
padding-bottom:30px;\ {'events': events, })
font-size:500%;'>\
Widget’s Calendar of Activities\
</h1>"
body = ""
for event in Event.objects.all():
location = event.location
datetime = str(event.target_datetime)
estimated_hours = str(event.estimated_hours)
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
Date and Time: "+datetime+" <br>\
Activity: "+event.activity+" <br>\
Estimated Hours: "+estimated_hours+" <br>\
Course/Section: "+event.course.course_title+" <br>\
Mode: "+location.mode+" <br>\
Venue: "+location.venue+" <br>\
</p>"
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
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