Commit d94ef6f3 authored by Rau Layug's avatar Rau Layug

Completed calendarapp Final Project

parent 8f91c608
from django.urls import path from django.urls import path
from . import views from .views import CalendarView
urlpatterns = [ urlpatterns = [
path('', views.calendar, name='calendar') path('', CalendarView.as_view(), name='calendar')
] ]
app_name = "calendar" app_name = "calendar"
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.core.files.storage import FileSystemStorage from django.views import View
from .models import Event, Location from .models import Event, Location
from .forms import EventForm from .forms import EventForm
...@@ -8,14 +8,15 @@ from assignments.models import Course ...@@ -8,14 +8,15 @@ from assignments.models import Course
# Create your views here. # Create your views here.
class CalendarView(View):
def get(self, request):
return render(request, 'calendarapp/calendar.html', {'Courses': Course.objects.all().order_by('course_code'), 'Events': Event.objects.all().order_by('target_date')})
def add_event(request): def add_event(request):
if request.method == 'POST': if request.method == 'POST':
form = EventForm(request.POST, request.FILES) form = EventForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
# upload = request.FILES['upload']
# fss = FileSystemStorage()
# file = fss.save(upload.name, upload)
# file_url = fss.url(file)
new_location = Location(mode=form.cleaned_data.get('mode'), venue=form.cleaned_data.get('venue'), image=form.cleaned_data.get('image')) new_location = Location(mode=form.cleaned_data.get('mode'), venue=form.cleaned_data.get('venue'), image=form.cleaned_data.get('image'))
new_location.save() new_location.save()
new_event = Event(target_date=form.cleaned_data.get('target_date'), activity=form.cleaned_data.get('activity'), estimated_hours=form.cleaned_data.get('estimated_hours'), course=form.cleaned_data.get('course'), location=new_location) new_event = Event(target_date=form.cleaned_data.get('target_date'), activity=form.cleaned_data.get('activity'), estimated_hours=form.cleaned_data.get('estimated_hours'), course=form.cleaned_data.get('course'), location=new_location)
...@@ -27,8 +28,8 @@ def add_event(request): ...@@ -27,8 +28,8 @@ def add_event(request):
return render(request, 'calendarapp/add_event.html', {'form': form}) return render(request, 'calendarapp/add_event.html', {'form': form})
def calendar(request): # def calendar(request):
return render(request, 'calendarapp/calendar.html', {'Courses': Course.objects.all().order_by('course_code'), 'Events': Event.objects.all().order_by('target_date')}) # return render(request, 'calendarapp/calendar.html', {'Courses': Course.objects.all().order_by('course_code'), 'Events': Event.objects.all().order_by('target_date')})
def events(request, id): def events(request, id):
......
...@@ -52,6 +52,11 @@ img { ...@@ -52,6 +52,11 @@ img {
display: block; display: block;
} }
input {
font-family: 'Roboto', sans-serif;
font-size: 1rem;
}
ul { ul {
list-style: none; list-style: none;
} }
\ No newline at end of file
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
<h1>New Event</h1> <h1>New Event</h1>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form }} <table>
<input type="submit" value="Submit"> {{ form }}
</table>
<input type="submit" value="Save Event" style="font-size: 2rem; margin-left: 8.2rem; background-color: darkseagreen; color: black; border: 0.2rem solid black">
</form> </form>
<a href="http://127.0.0.1:8000/calendar"><button>Events Page</button></a> <a href="http://127.0.0.1:8000/calendar"><button>Events Page</button></a>
{% endblock %} {% endblock %}
\ 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