Calendrier
This commit is contained in:
parent
04bdb4d2e3
commit
c672bea536
41 changed files with 338 additions and 5 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*/migrations/*
|
Binary file not shown.
Binary file not shown.
|
@ -39,6 +39,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.staticfiles',
|
||||
'gestion',
|
||||
'partitions',
|
||||
'calendrier',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
|
|
@ -13,6 +13,7 @@ urlpatterns = patterns('',
|
|||
url(r'^registration/?$', 'gestion.views.inscription_membre'),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^partitions/', include('partitions.urls')),
|
||||
url(r'^calendar/', include('calendrier.urls')),
|
||||
)
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
0
calendrier/__init__.py
Normal file
0
calendrier/__init__.py
Normal file
BIN
calendrier/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/admin.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/calend.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/calend.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/forms.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/forms.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/models.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/urls.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
calendrier/__pycache__/views.cpython-34.pyc
Normal file
BIN
calendrier/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
3
calendrier/admin.py
Normal file
3
calendrier/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
41
calendrier/calend.py
Normal file
41
calendrier/calend.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from django.utils.html import conditional_escape as esc
|
||||
from itertools import groupby
|
||||
from django.utils.safestring import mark_safe
|
||||
from calendar import HTMLCalendar, monthrange
|
||||
from datetime import *
|
||||
|
||||
class EventCalendar(HTMLCalendar):
|
||||
|
||||
def __init__(self, pEvents):
|
||||
super(EventCalendar, self).__init__()
|
||||
self.events = self.group_by_day(pEvents)
|
||||
|
||||
def formatday(self, day, weekday):
|
||||
if day != 0:
|
||||
cssclass = self.cssclasses[weekday]
|
||||
if date.today() == date(self.year, self.month, day):
|
||||
cssclass += ' today'
|
||||
if day in self.events:
|
||||
cssclass += ' filled'
|
||||
body = []
|
||||
for ev in self.events[day]:
|
||||
body.append('<a href="calendar/%s">' % ev.id)
|
||||
body.append(esc(ev.nom))
|
||||
body.append('</a><br/>')
|
||||
return self.day_cell(cssclass, '<div class="dayNumber">%d</div> %s' % (day, ''.join(body)))
|
||||
return self.day_cell(cssclass, '<div class="dayNumber">%d</div>' % day)
|
||||
return self.day_cell('noday', ' ')
|
||||
|
||||
def formatmonth(self, year, month):
|
||||
self.year, self.month = year, month
|
||||
return super(EventCalendar, self).formatmonth(year, month)
|
||||
|
||||
def group_by_day(self, pEvents):
|
||||
field = lambda ev: ev.date.day
|
||||
return dict(
|
||||
[(dat, list(items)) for dat, items in groupby(pEvents, field)]
|
||||
)
|
||||
|
||||
def day_cell(self, cssclass, body):
|
||||
return '<td class="%s">%s</td>' % (cssclass, body)
|
||||
|
13
calendrier/forms.py
Normal file
13
calendrier/forms.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django import forms
|
||||
from calendrier.models import Event
|
||||
|
||||
class EventForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Event
|
||||
widgets = {
|
||||
'description': forms.Textarea(attrs={"placeholder":"facultatif"}),
|
||||
'date': forms.TextInput(attrs={"placeholder": 'jj/mm/aaaa'}),
|
||||
'debut': forms.TextInput(attrs={"placeholder": 'hh:mm'}),
|
||||
'fin': forms.TextInput(attrs={"placeholder": 'hh:mm facultatif'})
|
||||
}
|
||||
|
14
calendrier/models.py
Normal file
14
calendrier/models.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from django.db import models
|
||||
|
||||
class Event(models.Model):
|
||||
nom = models.CharField(max_length=100)
|
||||
date = models.DateField()
|
||||
debut = models.TimeField()
|
||||
fin = models.TimeField(blank=True, null=True)
|
||||
lieu = models.CharField(max_length=200)
|
||||
description = models.TextField(blank=True)
|
||||
calendrier = models.BooleanField(default=False, verbose_name="Afficher dans le calendrier")
|
||||
|
||||
def __str__(self):
|
||||
return self.nom
|
||||
# Create your models here.
|
BIN
calendrier/templatetags/__pycache__/frenchmonth.cpython-34.pyc
Normal file
BIN
calendrier/templatetags/__pycache__/frenchmonth.cpython-34.pyc
Normal file
Binary file not shown.
32
calendrier/templatetags/frenchmonth.py
Normal file
32
calendrier/templatetags/frenchmonth.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def frenchmonth(tex):
|
||||
rep = tex
|
||||
if tex == "January":
|
||||
rep = "Janvier"
|
||||
if tex == "February":
|
||||
rep = "Février"
|
||||
if tex == "March":
|
||||
rep = "Mars"
|
||||
if tex == "April":
|
||||
rep = "Avril"
|
||||
if tex == "May":
|
||||
rep = "Mai"
|
||||
if tex == "June":
|
||||
rep = "Juin"
|
||||
if tex == "July":
|
||||
rep = "Juillet"
|
||||
if tex == "August":
|
||||
rep = "Août"
|
||||
if tex == "September":
|
||||
rep = "Septembre"
|
||||
if tex == "October":
|
||||
rep = "Octobre"
|
||||
if tex == "November":
|
||||
rep = "Novembre"
|
||||
if tex == "December":
|
||||
rep = "Décembre"
|
||||
return rep
|
3
calendrier/tests.py
Normal file
3
calendrier/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
9
calendrier/urls.py
Normal file
9
calendrier/urls.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
urlpatterns = patterns('calendrier.views',
|
||||
url(r'^new$', 'create_event'),
|
||||
url(r'^$', 'home'),
|
||||
url(r'(?P<pYear>\d+)/(?P<pMonth>\d+)/(?P<id>\d+)/?', 'view_event'),
|
||||
url(r'(?P<pYear>\d+)/(?P<pMonth>\d+)/?$', 'calendar'),
|
||||
url(r'(?P<id>\d+)/?', 'view_eventbis'),
|
||||
)
|
86
calendrier/views.py
Normal file
86
calendrier/views.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
from django.shortcuts import render
|
||||
from calendrier.forms import EventForm
|
||||
from calendrier.models import Event
|
||||
from django.utils.safestring import mark_safe
|
||||
from partitions.decorators import chef_required
|
||||
|
||||
from calendrier.calend import EventCalendar
|
||||
from calendar import monthrange
|
||||
from datetime import *
|
||||
|
||||
def named_month(pMonthNumber):
|
||||
return date(1900, pMonthNumber, 1).strftime('%B')
|
||||
|
||||
def home(request):
|
||||
lToday = datetime.now()
|
||||
return calendar(request, lToday.year, lToday.month)
|
||||
|
||||
def calendar(request, pYear, pMonth):
|
||||
lYear=int(pYear)
|
||||
lMonth = int(pMonth)
|
||||
lCalendarFromMonth = datetime(lYear, lMonth, 1)
|
||||
lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1])
|
||||
lEvents = Event.objects.filter(date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth, calendrier=True)
|
||||
lCalendar = EventCalendar(lEvents).formatmonth(lYear, lMonth)
|
||||
lPreviousYear = lYear
|
||||
lPreviousMonth = lMonth - 1
|
||||
if lPreviousMonth == 0:
|
||||
lPreviousMonth = 12
|
||||
lPreviousYear - 1
|
||||
lNextYear = lYear
|
||||
lNextMonth = lMonth + 1
|
||||
if lNextMonth == 13:
|
||||
lNextMonth = 1
|
||||
lNextYear = lYear + 1
|
||||
lYearAfterThis = lYear + 1
|
||||
lYearBeforeThis = lYear - 1
|
||||
return render(request, 'calendrier/home.html', {'Calendar': mark_safe(lCalendar),
|
||||
'Month': lMonth,
|
||||
'MonthName' : named_month(lMonth),
|
||||
'Year': lYear,
|
||||
'PreviousMonth': lPreviousMonth,
|
||||
'PreviousMonthName': named_month(lPreviousMonth),
|
||||
'PreviousYear': lPreviousYear,
|
||||
'NextMonth': lNextMonth,
|
||||
'NextMonthName': named_month(lNextMonth),
|
||||
'NextYear': lNextYear,
|
||||
'YearBeforeThis': lYearBeforeThis,
|
||||
'YearAfterThis': lYearAfterThis,
|
||||
})
|
||||
|
||||
def view_event(request, pYear, pMonth, id):
|
||||
ev = Event.objects.get(id=id)
|
||||
nom = ev.nom.capitalize
|
||||
fin = False
|
||||
desc = False
|
||||
if ev.fin:
|
||||
fin = True
|
||||
if ev.description:
|
||||
desc = True
|
||||
return render(request, 'calendrier/view_event.html', locals())
|
||||
|
||||
def view_eventbis(request, id):
|
||||
ev = Event.objects.get(id=id)
|
||||
nom = ev.nom.capitalize
|
||||
fin = False
|
||||
desc = False
|
||||
if ev.fin:
|
||||
fin = True
|
||||
if ev.description:
|
||||
desc = True
|
||||
return render(request, 'calendrier/view_event.html', locals())
|
||||
|
||||
@chef_required
|
||||
def create_event(request):
|
||||
if request.method == "POST":
|
||||
form = EventForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
||||
form.save()
|
||||
envoi = True
|
||||
|
||||
else:
|
||||
form = EventForm()
|
||||
|
||||
return render(request, "calendrier/create.html", locals())
|
||||
# Create your views here.
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,6 +2,7 @@ from django.contrib import admin
|
|||
from django.contrib.auth.models import User, Group
|
||||
from gestion.models import ErnestoUser
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from calendrier.models import Event
|
||||
|
||||
class UserProfileInline(admin.StackedInline):
|
||||
model = ErnestoUser
|
||||
|
@ -36,4 +37,5 @@ class UserProfileAdmin(UserAdmin):
|
|||
admin.site.unregister(User)
|
||||
admin.site.unregister(Group)
|
||||
admin.site.register(User, UserProfileAdmin)
|
||||
admin.site.register(Event)
|
||||
# Register your models here.
|
||||
|
|
|
@ -6,11 +6,13 @@ from django.contrib.auth.forms import AuthenticationForm
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from datetime import *
|
||||
import smtplib
|
||||
|
||||
from gestion.forms import InscriptionMembreForm, RegistrationFormUser
|
||||
from gestion.models import ErnestoUser
|
||||
|
||||
from calendrier.views import calendar
|
||||
|
||||
def inscription_membre(request):
|
||||
if request.method == 'POST':
|
||||
|
@ -35,7 +37,8 @@ def inscription_membre(request):
|
|||
return render(request, 'gestion/registration.html', locals())
|
||||
|
||||
def home(request):
|
||||
return render(request, 'gestion/home.html', {} )
|
||||
lToday = datetime.now()
|
||||
return calendar(request, lToday.year, lToday.month)
|
||||
|
||||
def login(request):
|
||||
if request.method == "POST" and "username" in request.POST:
|
||||
|
|
BIN
media/partitions/01_Highway_To_Hell.mp3
Normal file
BIN
media/partitions/01_Highway_To_Hell.mp3
Normal file
Binary file not shown.
BIN
media/partitions/CV.pdf
Normal file
BIN
media/partitions/CV.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -8,3 +8,12 @@ def is_chef(user):
|
|||
return False
|
||||
|
||||
chef_required = user_passes_test(lambda u: is_chef(u))
|
||||
|
||||
def is_ernesto(user):
|
||||
try:
|
||||
profile = user.profile
|
||||
return profile.is_ernesto
|
||||
except:
|
||||
return False
|
||||
|
||||
ernesto_required = user_passes_test(lambda u: is_ernesto(u))
|
||||
|
|
40
static/css/calend.css
Normal file
40
static/css/calend.css
Normal file
|
@ -0,0 +1,40 @@
|
|||
#calendar table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#calendar table tr th {
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
background-color: #316497;
|
||||
color: #99ccff;
|
||||
}
|
||||
|
||||
#calendar table tr td {
|
||||
width: 10%;
|
||||
border: 1px solid #555;
|
||||
vertical-align: top;
|
||||
height: 120px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
#calendar td.noday {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#calendar td.filled {
|
||||
background-color: #99ccff;
|
||||
}
|
||||
|
||||
#calendar td.today {
|
||||
border: 4px solid #316497;
|
||||
}
|
||||
|
||||
#calendar .dayNumber {
|
||||
font-size: 16px !important;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#calendar a {
|
||||
font-size: 16px;
|
||||
color: blue;
|
||||
}
|
|
@ -3,7 +3,20 @@ h2
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
header #menu li
|
||||
header
|
||||
{
|
||||
list-style: outside none none;
|
||||
display: inline-block;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
header ul
|
||||
{
|
||||
list-style-type: none;
|
||||
|
||||
}
|
||||
|
||||
header li
|
||||
{
|
||||
margin-right: 15px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
|
13
templates/calendrier/create.html
Normal file
13
templates/calendrier/create.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block titre%}Création d'Évènement{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if envoi %}Votre message a bien été envoyé !{% endif %}
|
||||
|
||||
<form action="{% url 'calendrier.views.create_event' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
{% endblock %}
|
31
templates/calendrier/home.html
Normal file
31
templates/calendrier/home.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{% extends "base.html" %}
|
||||
{% load staticfiles %}
|
||||
{% load frenchmonth %}
|
||||
|
||||
{% block extrahead %}
|
||||
<link rel="stylesheet" href={% static 'css/calend.css' %} />
|
||||
{% endblock %}
|
||||
|
||||
{% block titre %}L'Ernestophone{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>L'Ernestophone, la fanfare de l'École normale supérieure</h1>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td width="20%" align="left">
|
||||
<< <a href="/calendar/{{PreviousYear}}/{{PreviousMonth}}/">{{PreviousMonthName|frenchmonth}} {{PreviousYear}}</a>
|
||||
</td>
|
||||
<td width="20%" align="center"><a href="/calendar">Today</a></td>
|
||||
<td width="20%" align="right">
|
||||
<a href="/calendar/{{NextYear}}/{{NextMonth}}/">{{NextMonthName|frenchmonth}} {{NextYear}}</a> >>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="calendar">
|
||||
{{Calendar}}
|
||||
</div>
|
||||
{% if user.profile.is_chef %}
|
||||
<a href="{% url "calendrier.views.create_event" %}">Ajouter un évènement</a>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
18
templates/calendrier/view_event.html
Normal file
18
templates/calendrier/view_event.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block titre %}{{ nom }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>{{ nom }}</p>
|
||||
<p>{{ev.date}}</p>
|
||||
<p>{{ev.debut }}
|
||||
{% if fin %}
|
||||
- {{ ev.fin }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<p> Lieu : {{ ev.lieu }}</p>
|
||||
{% if desc %}
|
||||
<p>{{ev.description }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -2,7 +2,7 @@
|
|||
{% block titre %}Liste des partitions{% endblock %}
|
||||
{% block content %}<h1>Liste des partitions</h1>
|
||||
{% if suppression %}
|
||||
<p>{{ suppression }}</p
|
||||
<p>{{ suppression }}</p>
|
||||
{% endif %}
|
||||
<h3><a href="{% url "partitions.views.ajouter_morceau" %}">Ajouter un morceau</a></h3>
|
||||
{% for part in partitions %}
|
||||
|
|
|
@ -20,5 +20,5 @@
|
|||
{% empty %}
|
||||
<p> Pas de partitions pour le moment </p>
|
||||
{% endfor %}
|
||||
<p><a href="{% url "partitions.views.upload" p.nom p.auteur %}">Ajouter une partition</a></p>
|
||||
<p><a href="{% url "partitions.views.upload" p.nom p.auteur %}">Ajouter un média</a></p>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue