|
@@ -25,6 +25,7 @@ from pyramid_mailer.message import Message |
|
|
from .security import check_staff, check_logged |
|
|
from .security import check_staff, check_logged |
|
|
# Then, standard libs |
|
|
# Then, standard libs |
|
|
import csv |
|
|
import csv |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
from StringIO import StringIO |
|
|
from StringIO import StringIO |
|
|
except ImportError: |
|
|
except ImportError: |
|
@@ -41,7 +42,7 @@ from jm2l.const import CurrentYear |
|
|
from passlib.hash import argon2 |
|
|
from passlib.hash import argon2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## =-=- Here, We keep some usefull function -=-= |
|
|
|
|
|
|
|
|
# =-=- Here, We keep some usefull function -=-= |
|
|
def remove_accents(input_str): |
|
|
def remove_accents(input_str): |
|
|
""" This function is intended to remove all accent from input unicode string """ |
|
|
""" This function is intended to remove all accent from input unicode string """ |
|
|
nkfd_form = unicodedata.normalize('NFKD', input_str) |
|
|
nkfd_form = unicodedata.normalize('NFKD', input_str) |
|
@@ -70,7 +71,7 @@ def Live(request): |
|
|
return {'year': year, "DisplayYear": year, 'events': Events, "logged_in": request.authenticated_userid} |
|
|
return {'year': year, "DisplayYear": year, 'events': Events, "logged_in": request.authenticated_userid} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## =-=- Here, We handle ICal requests -=-= |
|
|
|
|
|
|
|
|
# =-=- Here, We handle ICal requests -=-= |
|
|
@view_config(route_name='progr_iCal', renderer="string") |
|
|
@view_config(route_name='progr_iCal', renderer="string") |
|
|
def ICal_Progamme_Request(request): |
|
|
def ICal_Progamme_Request(request): |
|
|
year = int(request.matchdict.get('year', CurrentYear)) |
|
|
year = int(request.matchdict.get('year', CurrentYear)) |
|
@@ -170,40 +171,39 @@ def ICal_Progamme_Dyn_Request(request): |
|
|
return cal.to_ical() |
|
|
return cal.to_ical() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## =-=- Here, We handle Json requests -=-= |
|
|
|
|
|
|
|
|
## =-=- Here, We handle Json requests -=-= |
|
|
|
|
|
|
|
|
|
|
|
def url_maker(page_number): |
|
|
|
|
|
query = request.GET |
|
|
|
|
|
query["page"] = str(page_number) |
|
|
|
|
|
return request.current_route_url(_query=query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name='users_json', renderer="json") |
|
|
@view_config(route_name='users_json', renderer="json") |
|
|
def JSON_User_Request(request): |
|
|
def JSON_User_Request(request): |
|
|
""" Build a JSON answer with active users and pagination handling """ |
|
|
""" Build a JSON answer with active users and pagination handling """ |
|
|
# Check arguments consitency |
|
|
# Check arguments consitency |
|
|
pageSize = request.params.get('pageSize', "8") |
|
|
|
|
|
|
|
|
page_size = request.params.get('pageSize', "8") |
|
|
current_page = request.params.get('pageNum', "1") |
|
|
current_page = request.params.get('pageNum', "1") |
|
|
UserQuery = request.params.get('searchTerm', u"") |
|
|
|
|
|
|
|
|
user_query = request.params.get('searchTerm', u"") |
|
|
# Don't answer to users that aren't logged |
|
|
# Don't answer to users that aren't logged |
|
|
if not request.user: |
|
|
if not request.user: |
|
|
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') |
|
|
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.') |
|
|
# Check consistancy of parameters |
|
|
|
|
|
if pageSize.isdigit() and current_page.isdigit(): |
|
|
|
|
|
|
|
|
# Check constancy of parameters |
|
|
|
|
|
if page_size.isdigit() and current_page.isdigit(): |
|
|
current_page = int(current_page) |
|
|
current_page = int(current_page) |
|
|
pageSize = int(pageSize) |
|
|
|
|
|
|
|
|
page_size = int(page_size) |
|
|
else: |
|
|
else: |
|
|
return HTTPBadRequest('pageSize and pageNum accept only digits.') |
|
|
return HTTPBadRequest('pageSize and pageNum accept only digits.') |
|
|
# Query database |
|
|
# Query database |
|
|
Users = DBSession.query(User.uid, User.nom, User.prenom) \ |
|
|
|
|
|
.filter(User.slug.contains(remove_accents(UserQuery))) |
|
|
|
|
|
page_url = paginate.PageURL_WebOb(request) |
|
|
|
|
|
records = paginate.Page(Users, current_page, url=page_url, items_per_page=pageSize) |
|
|
|
|
|
ListMatchUser = map(lambda u: {"id": u.uid, "text": "%s %s" % (u.prenom, u.nom)}, records) |
|
|
|
|
|
return {"Results": ListMatchUser, "Total": records.item_count, |
|
|
|
|
|
"logged_in": request.authenticated_userid} |
|
|
|
|
|
|
|
|
|
|
|
def get_paginator(request, page=1, items_per_page=10): |
|
|
|
|
|
def url_maker(page_number): |
|
|
|
|
|
query = request.GET |
|
|
|
|
|
query["page"] = str(page_number) |
|
|
|
|
|
return request.current_route_url(_query=query) |
|
|
|
|
|
|
|
|
|
|
|
return Page(sql-query-here, page=page, items_per_page=items_per_page, url_maker=url_maker) |
|
|
|
|
|
|
|
|
part = remove_accents(user_query) |
|
|
|
|
|
users_set = DBSession.query(User.uid, User.nom, User.prenom) \ |
|
|
|
|
|
.filter(User.slug.contains(part.decode("utf-8"))).all() |
|
|
|
|
|
|
|
|
|
|
|
records = paginate.Page(users_set, current_page, url_maker=url_maker, items_per_page=page_size) |
|
|
|
|
|
list_match_user = list(map(lambda u: {"id": u.uid, "text": "%s %s" % (u.prenom, u.nom)}, records)) |
|
|
|
|
|
return {"Results": list_match_user, "Total": records.item_count, |
|
|
|
|
|
"logged_in": request.authenticated_userid} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name='tiers_json', renderer="json") |
|
|
@view_config(route_name='tiers_json', renderer="json") |
|
@@ -223,13 +223,13 @@ def JSON_Tiers_Request(request): |
|
|
else: |
|
|
else: |
|
|
return HTTPBadRequest('pageSize and pageNum accept only digits.') |
|
|
return HTTPBadRequest('pageSize and pageNum accept only digits.') |
|
|
# Query database |
|
|
# Query database |
|
|
JTiers = DBSession.query(Tiers.uid, Tiers.name) \ |
|
|
|
|
|
.filter(Tiers.slug.contains(remove_accents(TiersQuery))) |
|
|
|
|
|
|
|
|
part = remove_accents(TiersQuery) |
|
|
|
|
|
j_tiers = DBSession.query(Tiers.uid, Tiers.name) \ |
|
|
|
|
|
.filter(Tiers.slug.contains(part.decode("utf-8"))).all() |
|
|
|
|
|
|
|
|
page_url = paginate.PageURL_WebOb(request) |
|
|
|
|
|
records = paginate.Page(JTiers, current_page, url=page_url, items_per_page=pageSize) |
|
|
|
|
|
ListMatchTiers = map(lambda t: {"id": t.uid, "text": t.name}, records) |
|
|
|
|
|
return {"Results": ListMatchTiers, "Total": records.item_count, |
|
|
|
|
|
|
|
|
records = paginate.Page(j_tiers, current_page, url_maker=url_maker, items_per_page=pageSize) |
|
|
|
|
|
list_match_tiers = list(map(lambda t: {"id": t.uid, "text": t.name}, records.items)) |
|
|
|
|
|
return {"Results": list_match_tiers, "Total": records.item_count, |
|
|
"logged_in": request.authenticated_userid} |
|
|
"logged_in": request.authenticated_userid} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -237,25 +237,25 @@ def JSON_Tiers_Request(request): |
|
|
def JSON_Progamme_Request(request): |
|
|
def JSON_Progamme_Request(request): |
|
|
year = int(request.matchdict.get('year', CurrentYear)) |
|
|
year = int(request.matchdict.get('year', CurrentYear)) |
|
|
# Initialization |
|
|
# Initialization |
|
|
DicResult = dict() |
|
|
|
|
|
|
|
|
dic_result = dict() |
|
|
# Query database |
|
|
# Query database |
|
|
# Compute days used by all events matching the specified input year |
|
|
# Compute days used by all events matching the specified input year |
|
|
Days = DBSession.query(func.strftime('%d', Event.start_time).label('day')) \ |
|
|
|
|
|
|
|
|
days = DBSession.query(func.strftime('%d', Event.start_time).label('day')) \ |
|
|
.filter(Event.for_year == year) \ |
|
|
.filter(Event.for_year == year) \ |
|
|
.filter(Event.event_type != None) \ |
|
|
|
|
|
|
|
|
.filter(Event.event_type is not None) \ |
|
|
.group_by(func.strftime('%d', Event.start_time)).all() |
|
|
.group_by(func.strftime('%d', Event.start_time)).all() |
|
|
|
|
|
|
|
|
for Day in Days: |
|
|
|
|
|
Events = DBSession.query(Event) \ |
|
|
|
|
|
|
|
|
for Day in days: |
|
|
|
|
|
events = DBSession.query(Event) \ |
|
|
.filter(Event.for_year == year) \ |
|
|
.filter(Event.for_year == year) \ |
|
|
.filter(Event.event_type != 'Stand') \ |
|
|
.filter(Event.event_type != 'Stand') \ |
|
|
.filter(text("strftime('%d', start_time) = :dow")).params(dow=Day.day) \ |
|
|
.filter(text("strftime('%d', start_time) = :dow")).params(dow=Day.day) \ |
|
|
.order_by(Event.start_time) |
|
|
.order_by(Event.start_time) |
|
|
|
|
|
|
|
|
ListEv = [] |
|
|
|
|
|
for ev in Events: |
|
|
|
|
|
|
|
|
list_ev = [] |
|
|
|
|
|
for ev in events: |
|
|
if ev.event_type: |
|
|
if ev.event_type: |
|
|
ListEv.append({ |
|
|
|
|
|
|
|
|
list_ev.append({ |
|
|
"uid": "%d/%d" % (year, ev.uid), |
|
|
"uid": "%d/%d" % (year, ev.uid), |
|
|
"desc": ev.name, |
|
|
"desc": ev.name, |
|
|
"startDate": ev.start_time.strftime('%Y-%m-%dT%H:%M:%S+01:00'), |
|
|
"startDate": ev.start_time.strftime('%Y-%m-%dT%H:%M:%S+01:00'), |
|
@@ -263,9 +263,9 @@ def JSON_Progamme_Request(request): |
|
|
"placeName": ev.Salle and (ev.Salle.name or "unk"), |
|
|
"placeName": ev.Salle and (ev.Salle.name or "unk"), |
|
|
"status": ev.event_type |
|
|
"status": ev.event_type |
|
|
}) |
|
|
}) |
|
|
DicResult[Day.day] = ListEv |
|
|
|
|
|
|
|
|
dic_result[Day.day] = list_ev |
|
|
|
|
|
|
|
|
return {'all': DicResult} |
|
|
|
|
|
|
|
|
return {'all': dic_result} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name='timeline_json', renderer="json") |
|
|
@view_config(route_name='timeline_json', renderer="json") |
|
@@ -2027,8 +2027,8 @@ def edit_tiers_category(request): |
|
|
if dic_result[opt.slug_entity_type]['title'] != opt.entity_type or \ |
|
|
if dic_result[opt.slug_entity_type]['title'] != opt.entity_type or \ |
|
|
tst[1] != opt.entity_subtype: |
|
|
tst[1] != opt.entity_subtype: |
|
|
list_changes.append(('changed', opt.uid, |
|
|
list_changes.append(('changed', opt.uid, |
|
|
dic_result[opt.slug_entity_type]['title'], |
|
|
|
|
|
tst[1])) |
|
|
|
|
|
|
|
|
dic_result[opt.slug_entity_type]['title'], |
|
|
|
|
|
tst[1])) |
|
|
else: |
|
|
else: |
|
|
list_changes.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype)) |
|
|
list_changes.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype)) |
|
|
|
|
|
|
|
|