Updated Calendar widget to new specifications

parent 510374f1
...@@ -24,7 +24,3 @@ class WidgetUser(models.Model): ...@@ -24,7 +24,3 @@ class WidgetUser(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('widgetuser-add', kwargs={'pk': self.pk}) return reverse('widgetuser-add', kwargs={'pk': self.pk})
\ No newline at end of file
...@@ -10,7 +10,6 @@ urlpatterns = [ ...@@ -10,7 +10,6 @@ urlpatterns = [
name='widgetuser-add'), name='widgetuser-add'),
path('Widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(), path('Widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(),
name='widgetuser-edit') name='widgetuser-edit')
] ]
app_name = "Dashboard" app_name = "Dashboard"
import string from .models import WidgetUser
from .models import WidgetUser, Department
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views import generic from django.views import generic
...@@ -33,13 +31,13 @@ def Dashboard_list_view(request): ...@@ -33,13 +31,13 @@ def Dashboard_list_view(request):
return HttpResponse(html_string_final) return HttpResponse(html_string_final)
class WidgetUserDetailView(generic.DetailView): class WidgetUserDetailView(generic.DetailView):
model = WidgetUser model = WidgetUser
template_name = 'widgetuser-details.html' template_name = 'widgetuser-details.html'
queryset = WidgetUser.objects.all() queryset = WidgetUser.objects.all()
context_object_name = 'widgetuser-detail' context_object_name = 'widgetuser-detail'
class WidgetUserAddView(generic.CreateView): class WidgetUserAddView(generic.CreateView):
model = WidgetUser model = WidgetUser
fields = '__all__' fields = '__all__'
......
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>Add Event</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<a href="/Events/{{Event.pk}}/details">
<button type="submit">Add Event</button>
</a>
</form>
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<title>Event</title>
<br><br>
<h2>{{object.activity}}</h2>
<h3>Date and Time: {{object.target_datetime}}</h3>
<h3>Estimated Hours: {{object.estimated_hours}}</h3>
<h3>{{course}}</h3>
<h3>Mode: {{location.mode}}</h3>
<h3>Venue: {{location.venue}}</h3>
<a href="/Events/{{ object.id }}/edit">
<input type="button" value="Edit Event">
</a>"
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>Edit Event</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Edit Event" />
</a>
</form>
{% endblock content %}
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
from Assignments.models import Course from Assignments.models import Course
...@@ -29,3 +30,10 @@ class Event(models.Model): ...@@ -29,3 +30,10 @@ 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)
def get_absolute_url(self):
return reverse('event-detail', kwargs={'pk': self.pk})
def get_absolute_url(self):
return reverse('event-add', kwargs={'pk': self.pk})
from django.urls import path from django.urls import path
from .views import index from .views import (index, EventDetailView, EventAddView, EventUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('Events/<int:pk>/details', EventDetailView.as_view(),
name='event-detail'),
path('Events/add/', EventAddView.as_view(),
name='event-add'),
path('Events/<int:pk>/edit/', EventUpdateView.as_view(),
name='event-edit')
] ]
app_name = "widget_Calendar" app_name = "widget_Calendar"
from .models import Event, Location from .models import Event
from django.http import HttpResponse from django.http import HttpResponse
from forum.views import convert_utc_to_local from forum.views import convert_utc_to_local
from django.views import generic
from django.urls import reverse
def index(request): def index(request):
html_string = 'robo_mommy’s Calendar of Activities<br>' html_string = 'robo_mommy’s Calendar of Activities<br><ul>'
for eventItem in Event.objects.all(): for eventItem in Event.objects.all():
eventId = str(eventItem.pk)
href = '<a href="/Events/'+eventId+'/details">'
html_string += ''' html_string += '''
<br> <br><li> {}
Date and Time: {}<br> Date and Time: {}<br>
Activity: {}<br> Activity: {}<br>
Estimated Hours: {}<br> Estimated Hours: {}<br>
Course/Section: {}<br> Course/Section: {}<br>
Mode: {}<br> Mode: {}<br>
Venue: {}<br><br> Venue: {}<br>
</li><br>
'''.format( '''.format(
href,
convert_utc_to_local(eventItem.target_datetime, '%d/%m/%Y|%I:%M %p'), convert_utc_to_local(eventItem.target_datetime, '%d/%m/%Y|%I:%M %p'),
eventItem.activity, eventItem.activity,
eventItem.estimated_hours, eventItem.estimated_hours,
...@@ -22,4 +28,40 @@ def index(request): ...@@ -22,4 +28,40 @@ def index(request):
eventItem.location.mode, eventItem.location.mode,
eventItem.location.venue, eventItem.location.venue,
) )
html_string += '''
</ul>
<a href="/Events/add"><button value="click here">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>
'''
return HttpResponse(html_string) return HttpResponse(html_string)
class EventDetailView(generic.DetailView):
model = Event
template_name = 'event-details.html'
queryset = Event.objects.all()
context_object_name = 'event-detail'
class EventAddView(generic.CreateView):
model = Event
fields = '__all__'
template_name = 'event-add.html'
def get_success_url(self):
return reverse('widget_Calendar:event-detail', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class EventUpdateView(generic.UpdateView):
model = Event
template_name = 'event-edit.html'
fields = '__all__'
success_url = "widget_Calendar/"
def get_success_url(self):
return reverse('widget_Calendar:eventuser-detail', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
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