Commit b6424f86 authored by Ysabella Panghulan's avatar Ysabella Panghulan

Merge branch 'calendarv2'

parents e521c58b c7916771
from django import forms
from django.forms import ModelForm
from .models import Location, Event
class LocationForm(ModelForm):
class Meta:
model = Location
fields = '__all__'
class EventForm(ModelForm):
class Meta:
model = Event
fields = '__all__'
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
# Create your models here. # Create your models here.
class Location(models.Model): class Location(models.Model):
...@@ -23,4 +24,7 @@ class Event(models.Model): ...@@ -23,4 +24,7 @@ class Event(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE) course = models.ForeignKey(Course, on_delete = models.CASCADE)
def __str__(self): def __str__(self):
return self.activity return self.activity
\ No newline at end of file
def get_absolute_url(self):
return reverse('event-details', kwargs={'pk': self.pk})
\ No newline at end of file
{%extends 'base.html'%}
{% block title %} Widget's Calendar of Activties {% endblock %}
{% block header %}
<h2>Widget's Calendar of Activties</h2>
{% endblock %}
{% block body %}
{% block content %}
<ul>
{% for event in events %}
<a href="{{ event.get_absolute_url }}">
<li>{{ event }}</li>
</a>
{% endfor %}
</ul>
{% endblock %}
<div class="calendar-links">
<a href="events/add" class="btn-primary">New Activity</a>
<a href="../dashboard" class="btn-primary">Dashboard</a>
<a href="../announcements" class="btn-primary">Announcements</a>
<a href="../forum" class="btn-primary">Forum</a>
<a href="../assignments" class="btn-primary">Assignments</a>
</div>
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block title %}Add Activity{% endblock %}
{% block header %}
<h2>Add a new activity:</h2>
{% endblock %}
{% block body %}
{% block content %}
<div class="form">
<form method="POST" action="">
{% csrf_token %}
{{form}}
<input type="Submit" value="Save New Activity">
</form>
</div>
{% endblock %}
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block title %}{{ object }}{% endblock %}
{% block header %}
<h2>{{ object }}</h2>
{% endblock %}
{% block body %}
<div class="event-content">
{% block content %}
<h4>Date and Time: {{ object.target_datetime|date:'m/d/Y' }} {{ object.target_datetime|date:'h:i A' }} </h4>
<h4>Estimated Hours: {{ object.estimated_hours }}</h4>
<h4>{{ object.course.code }} {{ object.course.title }} - {{ object.course.section }}</h4>
<h4>Mode: {{ object.location.mode }}</h4>
<h4>Venue: {{ object.location.venue }}</h4>
{% endblock %}
</div>
<div class="links">
<a href="{{object.get_absolute_url}}../edit" class="btn-primary">Edit Activity</a>
</div>
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block title %} Edit Activity {% endblock %}
{% block header %}
<h2>Edit Activity:</h2>
{% endblock %}
{% block body %}
{% block content %}
<div class="form">
<form method="POST" action="">
{% csrf_token %}
{{form}}
<input type="Submit" value="Save New Activity">
</form>
</div>
{% endblock %}
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import (EventDetailView, EventCreateView, EventUpdateView)
urlpatterns = [ urlpatterns = [
path('', views.index, name='calendar'), path('', views.Calendar, name=''),
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'),
] ]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from .models import Location, Event from .models import Location, Event
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .forms import LocationForm, EventForm
# Create your views here. # Create your views here.
def index(request): def Calendar(request):
events = Event.objects.all() locations = Location.objects.all()
welcomeMessage = 'Widget\'s Calendar of Activities <br><br>' events = Event.objects.all()
activities = '' context = {
'locations': locations,
'events': events,
}
return render(request, 'widget_calendar/calendar.html', context)
class EventDetailView(DetailView):
model = Event
template_name = 'widget_calendar/event-details.html'
class EventCreateView(CreateView):
model = Event
template_name = 'widget_calendar/event-add.html'
fields = '__all__'
for event in events: def post(self, request, *args, **kwargs):
activities += 'Date and Time: ' + event.target_datetime.strftime('%m/%d/%Y, %I:%M %p') + '<br>' form = EventForm(request.POST)
activities += 'Activity: '+ event.activity + '<br>' if form.is_valid():
activities += 'Estimated Hours: ' + str(event.estimated_hours) + '<br>' event = form.save()
activities += 'Course/Section: ' + event.course.code + ' ' + event.course.title + '-' + event.course.section + '<br>' return redirect('event-details', pk=event.pk)
activities += 'Mode: ' + event.location.mode + '<br>' else:
activities += 'Venue: ' + event.location.venue + '<br><br>' form = EventForm()
context = {
'form': form
}
return render(request, 'widget_calendar/event-add.html', context)
return HttpResponse(welcomeMessage + activities) class EventUpdateView(UpdateView):
\ No newline at end of file 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