|
@@ -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)) |
|
|