Commit 2b05602d authored by Neal Luigi D. Rodriguez's avatar Neal Luigi D. Rodriguez

Merge branch 'widgetcalendarv2'

parents 351a03b7 d5e56536
...@@ -20,8 +20,8 @@ class Location(models.Model): ...@@ -20,8 +20,8 @@ class Location(models.Model):
class Event(models.Model): class Event(models.Model):
target_datetime= models.DateTimeField()
activity = models.TextField(max_length=1000, default='') activity = models.TextField(max_length=1000, default='')
target_datetime= models.DateTimeField()
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey( location = models.ForeignKey(
Location, Location,
...@@ -38,5 +38,7 @@ class Event(models.Model): ...@@ -38,5 +38,7 @@ class Event(models.Model):
return '{}'.format(self.activity) return '{}'.format(self.activity)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('event_detail', args=[str(self.activity)]) return reverse('widgetcalendar:event-detail', kwargs={'pk': self.pk})
def get_edit_url(self):
return reverse('widgetcalendar:event-edit', kwargs={'pk' : self.pk} )
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Calendar of Activities {% endblock %}
{% block content %}
<h1>Widget's Calendar of Activities</h1>
<ul>
{% for object in events %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.activity }}</a>
</li>
{% endfor %}
</ul>
<button onclick="window.location.href='../../Calendar/events/add/';">
New Activity
</button>
<p>
<a href="/Dashboard">Dashboard</a><br>
<a href="/Announcement">Announcements</a><br>
<a href="/Forum">Forum</a><br>
<a href="/Assignments">Assignments</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Activity {% endblock %}
{% block content %}
<h1>Add a New Activity</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.activity }}{% endblock %}
{% block content %}
<h1>{{ object.activity }}</h1>
<h2>Date and Time: {{ object.target_datetime|date:"m/d/Y, "}}{{ object.target_datetime|time:"h:i A" }} </h2>
<h2>Estimated Hours: {{ object.estimated_hours }}</h2>
<h2>{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }}</h2>
<ul>
<li>Mode: {{ object.location.mode }}</li>
<li>Venue: {{ object.location.venue }}</li>
</ul>
<button onclick="document.location='{{object.get_edit_url}}'">
Edit Activity
</button>
{% comment %} <button onclick="document.location='{{object.get_edit_url}}'">Edit Activity</button> {% endcomment %}
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Activity {% endblock %}
{% block content %}
<h1>Edit Assignment</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Activity">
</form>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import index, EventDetailView, EditEventView, AddEventView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='Calendar'),
path('events/<int:pk>/details/', EventDetailView.as_view(), name ="event-detail"),
path('events/add/', AddEventView.as_view(), name ="event-add"),
path('events/<int:pk>/edit/', EditEventView.as_view(), name ="event-edit"),
] ]
app_name = "widgetcalendar" app_name = "widgetcalendar"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event from .models import Event
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.shortcuts import render
#Date format source: https://ourcodeworld.com/articles/read/555/how-to-format-datetime-objects-in-the-view-and-template-in-django #Date format source: https://ourcodeworld.com/articles/read/555/how-to-format-datetime-objects-in-the-view-and-template-in-django
# def index(request):
# return_string = ''
# for events in Event.objects.all():
# return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {} {}-{}<br>Mode: {}<br>Venue: {}<br></br>'.format(
# events.target_datetime.strftime("%x, %I:%M %p"), events.activity, events.estimated_hours, events.course.code, events.course.title, events.course.section, events.location.mode, events.location.venue
# )
# html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string)
# return HttpResponse(html_string)
def index(request): def index(request):
return_string = '' events = Event.objects.all()
for events in Event.objects.all(): context = {'events': events}
return_string += 'Date and Time: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {} {}-{}<br>Mode: {}<br>Venue: {}<br></br>'.format( return render(request, 'widgetcalendar/calendar.html', context)
events.target_datetime.strftime("%x, %I:%M %p"), events.activity, events.estimated_hours, events.course.code, events.course.title, events.course.section, events.location.mode, events.location.venue
) class EventDetailView(DetailView):
html_string = '<html><head>Widget\'s Calendar of Activities<br></br></head><body>{}</body><html>'.format(return_string) model = Event
return HttpResponse(html_string) template_name = 'widgetcalendar/event-details.html'
\ No newline at end of file
class EditEventView(UpdateView):
model = Event
fields = '__all__'
template_name = 'widgetcalendar/event-edit.html'
class AddEventView(CreateView):
model = Event
fields = '__all__'
template_name = 'widgetcalendar/event-add.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