Commit ad8567a4 authored by Rau Layug's avatar Rau Layug

Merge branch 'layug/calendar' into 'master'

Layug/calendar

See merge request !28
parents 487b2cfa a8870cc9
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): ...@@ -12,7 +12,7 @@ class Location(models.Model):
] ]
mode = models.CharField(max_length=3, choices=MODE_CHOICES) mode = models.CharField(max_length=3, choices=MODE_CHOICES)
venue = models.CharField(max_length=150) 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): def __str__(self):
......
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.views import View
from .models import Event from .models import Event, Location
from .forms import EventForm
from assignments.models import Course from assignments.models import Course
# Create your views here. # Create your views here.
def calendar(request): 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')}) 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):
if request.method == 'POST':
form = EventForm(request.POST, request.FILES)
if form.is_valid():
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): def events(request, id):
return render(request, 'calendarapp/events.html', {'event': Event.objects.get(id=id)}) return render(request, 'calendarapp/events.html', {'event': Event.objects.get(id=id)})
...@@ -119,6 +119,10 @@ USE_I18N = True ...@@ -119,6 +119,10 @@ USE_I18N = True
USE_TZ = True USE_TZ = True
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/ # https://docs.djangoproject.com/en/4.0/howto/static-files/
......
...@@ -8,6 +8,19 @@ ...@@ -8,6 +8,19 @@
padding: 0 2rem; 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 { body {
background-color: aliceblue; background-color: aliceblue;
border: 1rem solid aquamarine; border: 1rem solid aquamarine;
...@@ -20,17 +33,14 @@ body { ...@@ -20,17 +33,14 @@ body {
margin: 0 auto; margin: 0 auto;
} }
b { button {
color: mediumpurple; font-size: 1.5rem;
font-weight: 700; font-weight: 700;
} border: .4rem dashed lightgreen;
background-color: honeydew;
#course_block { padding: 15px 32px;
width: 25rem; color: rgb(72, 72, 72);
padding: .5rem; cursor: pointer;
margin: .8rem;
border: .4rem solid lightcoral;
background-color: lightyellow;
} }
img { img {
...@@ -42,6 +52,11 @@ img { ...@@ -42,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
{% 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 %}
<table>
{{ 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>
<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 @@ ...@@ -4,7 +4,7 @@
{% block title %}Calendar{% endblock %} {% block title %}Calendar{% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'calendarapp/styles.css' %}"> <link rel="stylesheet" href="{% static 'calendarapp/css/styles.css' %}">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -23,4 +23,5 @@ ...@@ -23,4 +23,5 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<a href="http://127.0.0.1:8000/events/add/"><button type="button">New Event</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block title %}Calendar{% endblock %} {% block title %}Calendar{% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{% static 'calendarapp/styles.css' %}"> <link rel="stylesheet" href="{% static 'calendarapp/css/styles.css' %}">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<li><b>Estimated Hours:</b> {{ event.estimated_hours }} hours</li> <li><b>Estimated Hours:</b> {{ event.estimated_hours }} hours</li>
<li><b>Mode:</b> {{ event.location.get_mode_display }}</li> <li><b>Mode:</b> {{ event.location.get_mode_display }}</li>
<li><b>Venue:</b> {{ event.location.venue }}</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> <li><b>ID:</b> {{ event.id }}</li>
</ul> </ul>
<a href="http://127.0.0.1:8000/calendar"><button>Events Page</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -16,13 +16,16 @@ Including another URLconf ...@@ -16,13 +16,16 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from calendarapp import views from calendarapp import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('homepage/', include('homepage.urls', namespace="homepage")), path('homepage/', include('homepage.urls', namespace="homepage")),
path('announcements/', include('announcementboard.urls', namespace="announcementboard")), path('announcements/', include('announcementboard.urls', namespace="announcementboard")),
path('forum/', include('forum.urls', namespace="forum")), path('forum/', include('forum.urls', namespace="forum")),
path('calendar/', include('calendarapp.urls', namespace="calendar")), 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('events/<int:id>/details/', views.events, name="events"),
path('assignments/', include('assignments.urls', namespace="assignments")), path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls) 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