Commit 3f51690f authored by Mariam Garsin's avatar Mariam Garsin

Merge branch 'calendarv2' into 'master'

Implemented the Homepage, Add, Edit, and Details page of the Calendar app

See merge request !11
parents d75b6645 9e7cfb4b
No preview for this file type
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.urls import reverse
class Location(models.Model): class Location(models.Model):
ONSITE = 'onsite' ONSITE = 'onsite'
...@@ -15,6 +17,9 @@ class Location(models.Model): ...@@ -15,6 +17,9 @@ class Location(models.Model):
mode = models.CharField(max_length=10, choices=MODE_CHOICES) mode = models.CharField(max_length=10, choices=MODE_CHOICES)
venue = models.CharField(max_length=1000) venue = models.CharField(max_length=1000)
def __str__(self):
return '{} [{}]'.format(self.mode.capitalize(), self.venue)
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField() target_datetime = models.DateTimeField()
activity = models.TextField(max_length=100) activity = models.TextField(max_length=100)
...@@ -23,4 +28,10 @@ class Event(models.Model): ...@@ -23,4 +28,10 @@ class Event(models.Model):
course = models.CharField(max_length=1000) course = models.CharField(max_length=1000)
def __str__(self): def __str__(self):
return '{}, {}'.format(self.target_datetime, self.activity) return '{}, {}'.format(self.target_datetime, self.activity)
\ No newline at end of file
def event_name(self):
return '{}'.format(self.activity)
def get_absolute_url(self):
return reverse('widget_calendar:event-details', kwargs={'pk':self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<h1>Widget's Calendar of Activities</h1>
<h3>
{% for event in events %}
<a href="{{ event.get_absolute_url }}">{{ event.activity }}</a><br>
{% endfor %}
</h3>
{% endblock %}
{% block scripts %}
<a href="/calendar/events/add"><input type="submit" value="New Activity"></a><br><br>
<a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcement Board</a><br>
<a href="/forum">Forum</a><br>
<a href="/assignments">Assignments</a><br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% 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 %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ event.event_name }}{% endblock %}
{% block content %}
<h1>{{ event.event_name }}</h1>
<h3>{{ event.course }}<br>
Date and Time: {{ event.target_datetime|date:"m/d/Y, h:i A" }}<br>
Estimated Hours: {{ event.estimated_hours }}<br>
Mode: {{ event.location.mode.capitalize }}<br>
Venue: {{ event.location.venue }}<br>
</h3>
{% endblock %}
{% block scripts %}
<a href="/calendar/events/{{ event.pk }}/edit"><input type="submit" value="Edit Activity"></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Activity{% endblock %}
<h1>Edit Activity:</h1>
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Activity">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
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/add/', EventCreateView.as_view(), name='event-add'),
path('events/<int:pk>/edit', EventUpdateView.as_view(), name='event-edit'),
] ]
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.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from.models import Event, Location from.models import Event
def index(request): def index(request):
page_content="""<H1>Widget’s Calendar of Activities</H1>""" return render(request, 'widget_calendar/calendar.html', {'events': Event.objects.all()})
for event in Event.objects.all():
newEventDateTime = event.target_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<ul> class EventDetailView(DetailView):
<li>Date and Time: {}<br> model = Event
<li>Activity: {}<br>
<li>Estimated Hours: {}<br> def get(self, request, pk):
<li>Course/Section: {}<br> return render(request, 'widget_calendar/event-details.html', {'event': self.model.objects.get(pk=pk)})
<li>Mode: {}<br>
<li>Venue: {}<br>
</ul>""".format(newEventDateTime, event.activity, class EventCreateView(CreateView):
event.estimated_hours, event.course, model = Event
event.location.mode, event.location.venue) fields = '__all__'
return HttpResponse(page_content) template_name = 'widget_calendar/event-add.html'
\ No newline at end of file
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