Sfoglia il codice sorgente

Merge branch 'tr4ck3ur/various_fixes_2017' of JM2L/jm2l into master

master
JM2L 5 anni fa
committed by Gogs
parent
commit
25a1a52aee
3 ha cambiato i file con 45 aggiunte e 0 eliminazioni
  1. +1
    -0
      jm2l/__init__.py
  2. +5
    -0
      jm2l/templates/Participant/list_users.mako
  3. +39
    -0
      jm2l/views.py

+ 1
- 0
jm2l/__init__.py Vedi File

@@ -127,6 +127,7 @@ def main(global_config, **settings):
config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}')

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

# HTML Routes - Public


+ 5
- 0
jm2l/templates/Participant/list_users.mako Vedi File

@@ -8,6 +8,7 @@ now = datetime.datetime.now()
%>

<form class="filterform" action="#">

<table class="table table-bordered table-hover">
<thead>
<tr>
@@ -160,3 +161,7 @@ now = datetime.datetime.now()
</tbody>
</table>
</form>

<div class="align-center">
<a class="btn" href="ListParticipant.csv">Export csv des participants ${for_year}</a>
</div>

+ 39
- 0
jm2l/views.py Vedi File

@@ -4,6 +4,7 @@ from pyramid.httpexceptions import HTTPBadRequest, HTTPUnauthorized
from pyramid.renderers import render_to_response
from pyramid.view import notfound_view_config, forbidden_view_config
from pyramid.view import view_config
from pyramid.response import Response
from mako.template import Template
from pyramid_mailer.message import Message
from .upload import IMAGEPATH
@@ -22,6 +23,8 @@ from pytz import timezone
from icalendar import Event as Evt
from pyramid_mailer.message import Message
# Then, standard libs
import csv
import cStringIO as StringIO
import webhelpers.paginate as paginate
import unicodedata
import datetime
@@ -950,6 +953,42 @@ def vote_logo(request):
return HTTPFound(location=come)
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')

@view_config(route_name='list_users_csv', renderer="string")
def list_users_csv(request):
for_year = int(request.matchdict.get('year', CurrentYear))
if request.user is None:
# Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
if not request.user.Staff:
raise HTTPForbidden(u'Vous n\'avez pas l\'autorité suffisante pour effectuer cette action.')

stmt = (DBSession.query(Sejour).filter(Sejour.for_year==for_year)).subquery()
# stmt_event = (DBSession.query(User_Event).filter()
adalias = aliased(Sejour, stmt)
Data = DBSession.query(User, adalias ) \
.outerjoin(adalias)\
.order_by(User.slug)\
.all()
FileHandle = StringIO.StringIO()
fileWriter = csv.writer(FileHandle, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
fileWriter.writerow(["Identifiant_JM2L", "Nom", "Prenom", "Status_%s" % for_year ])
for user, sejour in Data:
tab_identifier = [user.slug, user.nom.encode('utf-8'), user.prenom.encode('utf-8'), '']
if user.is_IntervenantOnYear(CurrentYear):
tab_identifier[3] = "Intervenant"
elif user.Staff:
tab_identifier[3] = "Staff"
elif sejour and sejour.orga_part:
tab_identifier[3] = "Bénévole"
elif sejour:
tab_identifier[3] = "Visiteur"
else:
continue
fileWriter.writerow(tab_identifier)

return Response(app_iter=FileHandle.getvalue(), content_type="text/csv")


@view_config(route_name='list_users', renderer="jm2l:templates/Participant/list_users.mako")
def list_users(request):
for_year = int(request.matchdict.get('year', CurrentYear))


Caricamento…
Annulla
Salva