Commit d14ca48c authored by nheoxoz's avatar nheoxoz

Merge branch 'origin/calendarv2'

parents f08eca11 2e38a414
......@@ -20,7 +20,7 @@ urlpatterns = [
path('', include('dashboard.urls', namespace="dashboard")),
path('forum/', include('forum.urls', namespace="forum")),
path('announcements/', include('announcements.urls', namespace="announcements")),
path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")),
path('calendar/', include('widget_calendar.urls', namespace="calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls),
]
from django.db import models
from django.urls import reverse
class Location(models.Model):
onsite = 'onsite'
......@@ -17,6 +17,8 @@ class Location(models.Model):
def __str__(self):
return '{}, {}'.format(self.mode, self.venue)
class Event(models.Model):
......@@ -32,3 +34,6 @@ class Event(models.Model):
def __str__(self):
return '{}, {}'.format(self.activity, self.target_datetime)
def get_absolute_url(self):
return reverse('widget_calendar:event-details', kwargs={'pk': self.pk})
\ No newline at end of file
<!-- calendar -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Calendar v2{% endblock %}
{% block heading %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<p>
{% for event in activities %}
<a href="{{ event.get_absolute_url }}">
{{ event.activity }}
</a><br>
{% endfor %}
</p>
{% endblock %}
{% block footing %}
<a href="{% url 'widget_calendar:event-add' %}">
<button class="btn add">New Activity</button><br>
</a>
<a href="/dashboard/">Dashboard</a><br>
<a href="/announcements/">Announcements</a><br>
<a href="/forum/">Forum</a><br>
<a href="/assignments/">Assignments</a>
{% endblock %}
<!-- event-add -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Widget User{% endblock %}
{% block heading %}<h1>Add a new activity:</h1>{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
<!-- event-details -->
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.activity }}{% endblock %}
{% block heading %}
<h1>
{{ object.activity }}
</h1>
{% endblock %}
{% block content %}
<p>
Date and Time: {{ object.target_datetime|date:"m/d/Y" }}, {{ object.target_datetime|time:"g:iA" }} <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 }}<br>
</p>
{% endblock %}
{% block footing %}
<a href="{% url 'widget_calendar:event-edit' object.pk %}">
<button class="btn edit">Edit Activity</button>
</a>
{% endblock %}
<!-- event-edit -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block heading %}Edit Activity:{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
from django.urls import path
from .views import index
from .views import (calendar, EventDetailView, EventCreateView, EventUpdateView)
urlpatterns = [
path('', index, name='index'),
path('', calendar, name='calendar'),
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'),
]
# This might be needed, depending on your Django version
app_name = "widget_calendar"
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.views import View
from .models import Event
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
def index(request):
return_string = "<p>Widget's Calendar of Activities</p>"
def calendar(request):
activities = Event.objects.all()
return render(request, 'widget_calendar/calendar.html', {'activities':activities})
for events in Event.objects.all():
round_hours = ("{:0.0f}".format(events.estimated_hours))
return_string += 'Date and Time: {}<br>'.format(
events.target_datetime.strftime('%m/%d/%Y, %H:%M %p')
)
return_string += 'Activity: {}<br>'.format(events.activity)
return_string += 'Estimated Hours: {}<br>'.format(round_hours)
return_string += 'Course/Section: {} {}-{}<br>'.format(
events.course.code,
events.course.title,
events.course.section,
)
return_string += 'Mode: {}<br>'.format(events.location.mode)
return_string += 'Venue: {}<br>'.format(events.location.venue)
return_string += '<br>'
class EventDetailView(DetailView):
model = Event
template_name = "widget_calendar/event-details.html"
html_string = '<html><body>{}</body></html>'.format(return_string)
class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = "widget_calendar/event-add.html"
return HttpResponse(html_string)
class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'widget_calendar/event-edit.html'
\ 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