Commit 458d9613 authored by Gabriel Geraldo's avatar Gabriel Geraldo

Merge branch 'widget_calendarv2'

parents 6c13082c ac6aefdc
from django import forms
from .models import Event
class EventCreateForm(forms.ModelForm):
class Meta:
model = Event
fields = ['activity', 'target_datetime', 'estimated_hours',
'location', 'course']
widgets = {
'target_datetime': forms.DateTimeInput(attrs={'type': 'datetime-local'})
}
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 Location(models.Model): class Location(models.Model):
ONSITE = 'onsite' ONSITE = 'onsite'
...@@ -20,7 +20,7 @@ class Location(models.Model): ...@@ -20,7 +20,7 @@ class Location(models.Model):
venue = models.CharField(max_length=255) venue = models.CharField(max_length=255)
def __str__(self): def __str__(self):
return '{} ({})'.format( return '{} - {}'.format(
self.venue, self.venue,
self.mode self.mode
) )
...@@ -38,4 +38,11 @@ class Event(models.Model): ...@@ -38,4 +38,11 @@ class Event(models.Model):
self.activity, self.activity,
self.course self.course
) )
def get_absolute_url(self):
return reverse("widget_calendar:event_details", kwargs={"pk": self.pk})
def get_date(self):
return self.target_datetime.strftime("%m/%d/%Y")
def get_time(self):
return self.target_datetime.strftime("%I:%M %p")
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock title %}
{% block content %}
<h1>Widget's Calendar of Activities</h1>
{% for event in events %}
<p><strong>
<a href="{{ event.get_absolute_url }}">
<li>
{{ event.activity }}
</li>
</a>
</strong></p>
{% endfor %}
<form action="events/add">
<input type="submit" value="Add Activity">
</form>
<div>
<a href="../dashboard/">Dashboard</a><br>
<a href="../announcements/">Announcements</a><br>
<a href="../forum/">Forum</a><br>
<a href="../assignments/">Assignments</a><br>
</div>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
<h1>Add a new activity:</h1>
<div class="new_user">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Activity</button>
</form>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.activity }}{% endblock %}
{% block content %}
<div style="text-transform:uppercase;">
<h1>{{ object.activity }}</h1>
</div>
<h2>
Date and Time: {{ object.get_date }}, {{ object.get_time }}<br>
Estimated Hours: {{ object.estimated_hours }} <br>
{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }} <br>
Mode: {{ object.location.mode }} <br>
Venue: {{ object.location.venue }}
</h2>
<form action="edit">
<input type="submit" value="Edit Activity">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block content %}
<h1>Edit Activity:</h1>
<div class="new_user">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Activity</button>
</form>
</div>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import index, EventDetailView, EventCreateView, EventUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index') path('', index, name='index'),
path('events/<int:pk>/details', EventDetailView.as_view(), name='event_details'),
path('events/<int:pk>/edit', EventUpdateView.as_view(), name='event_edit'),
path('events/add', EventCreateView.as_view(), name='event_add'),
] ]
app_name = "widget_calendar" app_name = "widget_calendar"
\ No newline at end of file
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 .forms import EventCreateForm
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView
def index(HttpRequest): def index(HttpRequest):
html_output = ''' events = Event.objects.all()
<html> args = { 'events':events }
<head> return render(HttpRequest, 'widget_calendar/calendar.html', args)
<title>Calendar</title>
</head> class EventDetailView(DetailView):
<body> model = Event
<h1>Widget's Calendar of Activities</h1> template_name = "widget_calendar/event-details.html"
'''
for event in Event.objects.all(): class EventCreateView(CreateView):
html_output += ''' form_class = EventCreateForm
<p> # taken from: https://stackoverflow.com/questions/27321692/override-a-django-generic-class-based-view-widget
Date and Time: {}<br> template_name = "widget_calendar/event-add.html"
Activity: {}<br>
Estimated Hours: {}<br> class EventUpdateView(UpdateView):
Course/Section: {} {}-{}<br> model = Event
Mode: {}<br> form_class = EventCreateForm
Venue: {}<br> template_name="widget_calendar/event-edit.html"
</p>
'''.format(
event.target_datetime.strftime("%m/%d/%Y, %I:%M %p"),
event.activity,
event.estimated_hours,
event.course,
event.course.title,
event.course.section,
event.location.mode,
event.location.venue
)
html_output += '''
</body>
</html>
'''
return HttpResponse(html_output)
\ 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