Browse Source

Some Fixes to take in account the year of JM2L event

master
tr4ck3ur des JM2L 7 years ago
parent
commit
2a2cd02477
6 changed files with 57 additions and 21 deletions
  1. +2
    -2
      jm2l/__init__.py
  2. +2
    -1
      jm2l/badge.py
  3. +20
    -4
      jm2l/models.py
  4. +7
    -3
      jm2l/templates/Participant/list_users.mako
  5. +1
    -1
      jm2l/templates/layout.mako
  6. +25
    -10
      jm2l/views.py

+ 2
- 2
jm2l/__init__.py View File

@@ -126,8 +126,8 @@ def main(global_config, **settings):
config.add_route('action_salle', '/Salles/{action:(\w+)}/{salle_id:(\d+)}') config.add_route('action_salle', '/Salles/{action:(\w+)}/{salle_id:(\d+)}')
config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}') config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}')


config.add_route('list_users', '/ListParticipant')
config.add_route('list_orga', '/ListOrga')
config.add_route('list_users', '/{year:\d+}/ListParticipant')
config.add_route('list_orga', '/{year:\d+}/ListOrga')


# HTML Routes - Public # HTML Routes - Public
config.add_route('home', '/{year:(\d+/)?}') config.add_route('home', '/{year:(\d+/)?}')


+ 2
- 1
jm2l/badge.py View File

@@ -11,6 +11,7 @@ from reportlab.lib.units import mm
import qrcode import qrcode
import subprocess import subprocess
from .upload import MediaPath from .upload import MediaPath
from jm2l.const import CurrentYear
# Create PDF container # Create PDF container
EXPIRATION_TIME = 300 # seconds EXPIRATION_TIME = 300 # seconds
WIDTH = 85 * mm WIDTH = 85 * mm
@@ -32,7 +33,7 @@ def JM2L_Logo(canvas, Offset=(0,0)):
yearobject.setTextRenderMode(0) yearobject.setTextRenderMode(0)
yearobject.setTextOrigin(OffX+12 , OffY+35) yearobject.setTextOrigin(OffX+12 , OffY+35)
yearobject.setWordSpace(13) yearobject.setWordSpace(13)
yearobject.textLines("2 0 1 5")
yearobject.textLines(" ".join(str(CurrentYear)))
canvas.drawText(yearobject) canvas.drawText(yearobject)


def Tiers_Logo(canvas, DispUser, StartPos=None, Offset=(0,0)): def Tiers_Logo(canvas, DispUser, StartPos=None, Offset=(0,0)):


+ 20
- 4
jm2l/models.py View File

@@ -184,7 +184,13 @@ class User(Base):
return None return None


@property @property
def is_Intervenant(self, year=CurrentYear):
def is_Intervenant(self):
""" This property will return if User do an event on specified year """
return DBSession.query(Event).join(User_Event) \
.filter(User_Event.user_uid==self.uid) \
.filter(Event.for_year==CurrentYear).count()

def is_IntervenantOnYear(self, year=CurrentYear):
""" This property will return if User do an event on specified year """ """ This property will return if User do an event on specified year """
return DBSession.query(Event).join(User_Event) \ return DBSession.query(Event).join(User_Event) \
.filter(User_Event.user_uid==self.uid) \ .filter(User_Event.user_uid==self.uid) \
@@ -193,7 +199,14 @@ class User(Base):
@property @property
def is_crew(self, year=CurrentYear): def is_crew(self, year=CurrentYear):
""" This property will return if User subscribe orga task on specified year """ """ This property will return if User subscribe orga task on specified year """
return DBSession.query(User,Sejour.orga_part).outerjoin(Sejour).filter(User.uid == self.uid).one()[1]
orga_checked = DBSession.query(User, Sejour.orga_part)\
.outerjoin(Sejour) \
.filter(Sejour.for_year == year)\
.filter(User.uid == self.uid).first()
if orga_checked:
return orga_checked
else:
return False
def year_events(self, EventType='All', year=CurrentYear): def year_events(self, EventType='All', year=CurrentYear):
@@ -591,8 +604,11 @@ class Sejour(Base):
last_change = Column(DateTime, default=datetime.datetime.now) last_change = Column(DateTime, default=datetime.datetime.now)
@classmethod @classmethod
def by_user(cls, uid):
return DBSession.query(cls).filter(cls.user_id == uid).first()
def by_user(cls, uid, year):
return DBSession.query(cls)\
.filter(cls.user_id == uid)\
.filter(cls.for_year == year)\
.first()


class Event(Base): class Event(Base):
__tablename__ = 'events' __tablename__ = 'events'


+ 7
- 3
jm2l/templates/Participant/list_users.mako View File

@@ -23,8 +23,12 @@ now = datetime.datetime.now()
</tr> </tr>
</thead> </thead>
<tbody id="list"> <tbody id="list">
% for u, s in Users:
<tr>
% for u, s in Users:
% if u.is_IntervenantOnYear(for_year):
<tr>
% else:
<tr style="color:lightgray">
% endif
<td style="text-align:center;"> <td style="text-align:center;">
<span class="data">${u.slug}</span> <span class="data">${u.slug}</span>
<a href="/MesJM2L?user=${u.uid}">${u.nom} ${u.prenom}</a><br /> <a href="/MesJM2L?user=${u.uid}">${u.nom} ${u.prenom}</a><br />
@@ -38,7 +42,7 @@ now = datetime.datetime.now()
<i class="icon-star"></i> <i class="icon-star"></i>
</a> </a>
% endif % endif
% if u.Staff==0:
% if u.is_IntervenantOnYear(for_year):
<a href="javascript:alert('${u.nom}, ${u.prenom}\nIntervenant');"> <a href="javascript:alert('${u.nom}, ${u.prenom}\nIntervenant');">
<i class="icon-user"></i> <i class="icon-user"></i>
</a> </a>


+ 1
- 1
jm2l/templates/layout.mako View File

@@ -126,7 +126,7 @@ ${helpers.uploader_js()}
% if request.user: % if request.user:
% if request.user.Staff: % if request.user.Staff:
<li><a href="/${DisplayYear}/Staff">Partie Staff</a></li> <li><a href="/${DisplayYear}/Staff">Partie Staff</a></li>
<li><a href="/ListParticipant">Gérer les intervenants</a></li>
<li><a href="/${DisplayYear}/ListParticipant">Gérer les intervenants</a></li>
<li><a href="/ListSalles">Gérer les salles</a></li> <li><a href="/ListSalles">Gérer les salles</a></li>
<li><a href="/entities">Gérer les entités</a></li> <li><a href="/entities">Gérer les entités</a></li>
<li><a href="/${DisplayYear}/ListOrga">Participations à l'orga</a></li> <li><a href="/${DisplayYear}/ListOrga">Participations à l'orga</a></li>


+ 25
- 10
jm2l/views.py View File

@@ -13,6 +13,7 @@ from .forms import *
from .models import * from .models import *
from .helpers import Orga_helpers from .helpers import Orga_helpers
from sqlalchemy import func, or_, text, and_ from sqlalchemy import func, or_, text, and_
from sqlalchemy.orm import aliased
from os import path, makedirs, listdir from os import path, makedirs, listdir
# Usefull tools # Usefull tools
from slugify import slugify from slugify import slugify
@@ -105,13 +106,13 @@ def ICal_Progamme_Dyn_Request(request):
event = Evt() event = Evt()
event['uid'] = "%d/%d" % ( year, 100 ) event['uid'] = "%d/%d" % ( year, 100 )
event.add('summary', "Les stands JM2L 2015" )
event.add('summary', "Les stands JM2L %s" % year )
event.add('dtstart', datetime.datetime.now().replace(tzinfo=tz, hour=10, minute=00 ) ) event.add('dtstart', datetime.datetime.now().replace(tzinfo=tz, hour=10, minute=00 ) )
event.add('dtend', datetime.datetime.now().replace(tzinfo=tz, hour=18, minute=00 ) ) event.add('dtend', datetime.datetime.now().replace(tzinfo=tz, hour=18, minute=00 ) )
event.add('created', datetime.datetime.now().replace(tzinfo=tz, hour=10, minute=00 ) ) event.add('created', datetime.datetime.now().replace(tzinfo=tz, hour=10, minute=00 ) )
event.add('description', "https://www.youtube.com/watch?v=91X65eEKxvU&t=6s" ) event.add('description', "https://www.youtube.com/watch?v=91X65eEKxvU&t=6s" )
event.add('location', "http://jm2l.linux-azur.org/img/325.gif" ) event.add('location', "http://jm2l.linux-azur.org/img/325.gif" )
event.add('url', "http://jm2l.linux-azur.org/2015/le-programme" )
event.add('url', "http://jm2l.linux-azur.org/%s/le-programme" % CurrentYear)
event.add('priority', 5) event.add('priority', 5)
cal.add_component(event) cal.add_component(event)


@@ -814,7 +815,7 @@ def miam(request):
miam_form = MiamForm(request.POST, request.user, meta={'csrf_context': request.session}) miam_form = MiamForm(request.POST, request.user, meta={'csrf_context': request.session})
if request.method == 'POST' and miam_form.validate(): if request.method == 'POST' and miam_form.validate():
FicheSejour = Sejour.by_user(request.user.uid)
FicheSejour = Sejour.by_user(request.user.uid, CurrentYear)
if FicheSejour: if FicheSejour:
Update=True Update=True
else: else:
@@ -846,7 +847,7 @@ def sejour(request):
# Don't answer to users that aren't logged # Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
if request.method == 'POST': if request.method == 'POST':
FicheSejour = Sejour.by_user(request.user.uid)
FicheSejour = Sejour.by_user(request.user.uid, CurrentYear)
if FicheSejour: if FicheSejour:
Update=True Update=True
else: else:
@@ -895,7 +896,7 @@ def orga(request):
# Don't answer to users that aren't logged # Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
if request.method == 'POST': if request.method == 'POST':
FicheSejour = Sejour.by_user(request.user.uid)
FicheSejour = Sejour.by_user(request.user.uid, CurrentYear)
UpdateOrga=False UpdateOrga=False
if FicheSejour: if FicheSejour:
Update=True Update=True
@@ -951,13 +952,23 @@ def vote_logo(request):


@view_config(route_name='list_users', renderer="jm2l:templates/Participant/list_users.mako") @view_config(route_name='list_users', renderer="jm2l:templates/Participant/list_users.mako")
def list_users(request): def list_users(request):
for_year = int(request.matchdict.get('year', CurrentYear))
if request.user is None: if request.user is None:
# Don't answer to users that aren't logged # Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
if not request.user.Staff: if not request.user.Staff:
raise HTTPForbidden(u'Vous n\'avez pas l\'autorité suffisante pour effectuer cette action.') raise HTTPForbidden(u'Vous n\'avez pas l\'autorité suffisante pour effectuer cette action.')
Data = DBSession.query(User, Sejour).outerjoin(Sejour).all()
Repas = DBSession.query(Sejour.repas).all()

stmt = (DBSession.query(Sejour).filter(Sejour.for_year==for_year)).subquery()
adalias = aliased(Sejour, stmt)
Data = DBSession.query(User, adalias ) \
.outerjoin(adalias)\
.all()

Repas = DBSession.query(Sejour.repas) \
.filter(Sejour.for_year == for_year ) \
.all()

DicRepas = {"Ven":0, "Midi":0, "Soir":0} DicRepas = {"Ven":0, "Midi":0, "Soir":0}
for r in Repas: for r in Repas:
if r[0] is None: if r[0] is None:
@@ -965,16 +976,20 @@ def list_users(request):
if (r[0] & 1 == 1): DicRepas["Ven"]+=1 if (r[0] & 1 == 1): DicRepas["Ven"]+=1
if (r[0] & 2 == 2): DicRepas["Midi"]+=1 if (r[0] & 2 == 2): DicRepas["Midi"]+=1
if (r[0] & 4 == 4): DicRepas["Soir"]+=1 if (r[0] & 4 == 4): DicRepas["Soir"]+=1
return { 'Users':Data, 'UserEvent' : User_Event, "DicRepas":DicRepas }
return { 'Users':Data, 'UserEvent' : User_Event, "DicRepas":DicRepas, "for_year": for_year }


@view_config(route_name='list_orga', renderer="jm2l:templates/Participant/list_orga.mako") @view_config(route_name='list_orga', renderer="jm2l:templates/Participant/list_orga.mako")
def list_orga(request): def list_orga(request):
for_year = int(request.matchdict.get('year', CurrentYear))
if request.user is None: if request.user is None:
# Don't answer to users that aren't logged # Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
if not request.user.Staff: if not request.user.Staff:
raise HTTPForbidden(u'Vous n\'avez pas l\'autorité suffisante pour effectuer cette action.') raise HTTPForbidden(u'Vous n\'avez pas l\'autorité suffisante pour effectuer cette action.')
Data = DBSession.query(User, Sejour).outerjoin(Sejour).all()
Data = DBSession.query(User, Sejour)\
.outerjoin(Sejour)\
.filter(Sejour.for_year == for_year)\
.all()
return { 'Users':Data } return { 'Users':Data }


@view_config(route_name='jm2l', renderer="jm2l:templates/jm2l.mako") @view_config(route_name='jm2l', renderer="jm2l:templates/jm2l.mako")
@@ -1002,7 +1017,7 @@ def jm2l_page(request):
# Feed FicheSejour if any # Feed FicheSejour if any
FicheSejour = Sejour.by_user(profil.uid)
FicheSejour = Sejour.by_user(profil.uid, CurrentYear)
if FicheSejour: if FicheSejour:
if FicheSejour.repas is not None: if FicheSejour.repas is not None:
for num, item in enumerate(['RepasVendredi', 'RepasSamediMidi', 'RepasSamediSoir']): for num, item in enumerate(['RepasVendredi', 'RepasSamediMidi', 'RepasSamediSoir']):


Loading…
Cancel
Save