Commit 8f91c608 authored by Rau Layug's avatar Rau Layug

Added calendarapp final project requirements

parent 7e51a993
from django import forms
from django.db import models
import datetime
from .models import Location, Event
from assignments.models import Course
'''
class LocationForm(forms.ModelForm):
model = Location
fields = ['mode', 'venue', 'image']
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ['target_date', 'activity', 'estimated_hours', 'course',
'location']
'''
class EventForm(forms.Form):
target_date = forms.DateField(initial=datetime.date.today)
activity = forms.CharField(label='Activity', max_length=150)
estimated_hours = forms.FloatField(label='Estimated Hours', min_value=0)
course = forms.ModelChoiceField(queryset=Course.objects.all())
mode = forms.ChoiceField(choices=Location.MODE_CHOICES)
venue = forms.CharField(max_length=150)
image = forms.ImageField(max_length=100)
......@@ -12,7 +12,7 @@ class Location(models.Model):
]
mode = models.CharField(max_length=3, choices=MODE_CHOICES)
venue = models.CharField(max_length=150)
image = models.ImageField(upload_to='widget_group_25/widget_group_25/static/calendarapp/img', height_field=None, width_field=None, max_length=100)
image = models.ImageField(upload_to='calendarapp/location_images', height_field=None, width_field=None, max_length=100)
def __str__(self):
......
from django.http import HttpResponse
from django.shortcuts import render
from django.core.files.storage import FileSystemStorage
from .models import Event
from .models import Event, Location
from .forms import EventForm
from assignments.models import Course
# Create your views here.
def add_event(request):
if request.method == 'POST':
form = EventForm(request.POST, request.FILES)
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.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.save()
return render(request, 'calendarapp/events.html', {'event': Event.objects.get(id=new_event.id)})
return HttpResponse('invalid form')
else:
form = EventForm()
return render(request, 'calendarapp/add_event.html', {'form': form})
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')})
def events(request, id):
return render(request, 'calendarapp/events.html', {'event': Event.objects.get(id=id)})
This diff is collapsed.
......@@ -119,6 +119,10 @@ USE_I18N = True
USE_TZ = True
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
......
......@@ -8,6 +8,19 @@
padding: 0 2rem;
}
#course_block {
width: 25rem;
padding: .5rem;
margin: .8rem;
border: .4rem solid lightcoral;
background-color: lightyellow;
}
b {
color: mediumpurple;
font-weight: 700;
}
body {
background-color: aliceblue;
border: 1rem solid aquamarine;
......@@ -20,17 +33,14 @@ body {
margin: 0 auto;
}
b {
color: mediumpurple;
button {
font-size: 1.5rem;
font-weight: 700;
}
#course_block {
width: 25rem;
padding: .5rem;
margin: .8rem;
border: .4rem solid lightcoral;
background-color: lightyellow;
border: .4rem dashed lightgreen;
background-color: honeydew;
padding: 15px 32px;
color: rgb(72, 72, 72);
cursor: pointer;
}
img {
......@@ -43,5 +53,5 @@ img {
}
ul {
list-style: none
list-style: none;
}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Calendar{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'calendarapp/css/styles.css' %}">
{% endblock %}
{% block content %}
<h1>New Event</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
<a href="http://127.0.0.1:8000/calendar"><button>Events Page</button></a>
{% endblock %}
\ No newline at end of file
......@@ -4,7 +4,7 @@
{% block title %}Calendar{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'calendarapp/styles.css' %}">
<link rel="stylesheet" href="{% static 'calendarapp/css/styles.css' %}">
{% endblock %}
{% block content %}
......@@ -23,4 +23,5 @@
</li>
{% endfor %}
</ul>
<a href="http://127.0.0.1:8000/events/add/"><button type="button">New Event</button></a>
{% endblock %}
\ No newline at end of file
......@@ -4,7 +4,7 @@
{% block title %}Calendar{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'calendarapp/styles.css' %}">
<link rel="stylesheet" href="{% static 'calendarapp/css/styles.css' %}">
{% endblock %}
{% block content %}
......@@ -15,7 +15,8 @@
<li><b>Estimated Hours:</b> {{ event.estimated_hours }} hours</li>
<li><b>Mode:</b> {{ event.location.get_mode_display }}</li>
<li><b>Venue:</b> {{ event.location.venue }}</li>
<li><b>Image:</b> <img src="{% static event.location.image.url|slice:'40:' %}" alt="{{ event.location.image.url|slice:'40:' }}" /></li>
<li><b>Image:</b> <img src="{{ event.location.image.url }}" alt="{{ event.location.image.url }}" /></li>
<li><b>ID:</b> {{ event.id }}</li>
</ul>
<a href="http://127.0.0.1:8000/calendar"><button>Events Page</button></a>
{% endblock %}
\ No newline at end of file
......@@ -16,13 +16,16 @@ Including another URLconf
from django.contrib import admin
from django.urls import include, path
from calendarapp import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('homepage/', include('homepage.urls', namespace="homepage")),
path('announcements/', include('announcementboard.urls', namespace="announcementboard")),
path('forum/', include('forum.urls', namespace="forum")),
path('calendar/', include('calendarapp.urls', namespace="calendar")),
path('events/add/', views.add_event, name="add_events"),
path('events/<int:id>/details/', views.events, name="events"),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls)
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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