Added csv export for issue #11
This commit is contained in:
@@ -127,6 +127,7 @@ def main(global_config, **settings):
|
|||||||
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', '/{year:\d+}/ListParticipant')
|
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')
|
config.add_route('list_orga', '/{year:\d+}/ListOrga')
|
||||||
|
|
||||||
# HTML Routes - Public
|
# HTML Routes - Public
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ now = datetime.datetime.now()
|
|||||||
%>
|
%>
|
||||||
|
|
||||||
<form class="filterform" action="#">
|
<form class="filterform" action="#">
|
||||||
|
|
||||||
<table class="table table-bordered table-hover">
|
<table class="table table-bordered table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -160,3 +161,7 @@ now = datetime.datetime.now()
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div class="align-center">
|
||||||
|
<a class="btn" href="ListParticipant.csv">Export csv des participants ${for_year}</a>
|
||||||
|
</div>
|
||||||
@@ -4,6 +4,7 @@ from pyramid.httpexceptions import HTTPBadRequest, HTTPUnauthorized
|
|||||||
from pyramid.renderers import render_to_response
|
from pyramid.renderers import render_to_response
|
||||||
from pyramid.view import notfound_view_config, forbidden_view_config
|
from pyramid.view import notfound_view_config, forbidden_view_config
|
||||||
from pyramid.view import view_config
|
from pyramid.view import view_config
|
||||||
|
from pyramid.response import Response
|
||||||
from mako.template import Template
|
from mako.template import Template
|
||||||
from pyramid_mailer.message import Message
|
from pyramid_mailer.message import Message
|
||||||
from .upload import IMAGEPATH
|
from .upload import IMAGEPATH
|
||||||
@@ -22,6 +23,8 @@ from pytz import timezone
|
|||||||
from icalendar import Event as Evt
|
from icalendar import Event as Evt
|
||||||
from pyramid_mailer.message import Message
|
from pyramid_mailer.message import Message
|
||||||
# Then, standard libs
|
# Then, standard libs
|
||||||
|
import csv
|
||||||
|
import cStringIO as StringIO
|
||||||
import webhelpers.paginate as paginate
|
import webhelpers.paginate as paginate
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import datetime
|
import datetime
|
||||||
@@ -950,6 +953,42 @@ def vote_logo(request):
|
|||||||
return HTTPFound(location=come)
|
return HTTPFound(location=come)
|
||||||
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
|
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")
|
@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))
|
for_year = int(request.matchdict.get('year', CurrentYear))
|
||||||
|
|||||||
Reference in New Issue
Block a user