Sfoglia il codice sorgente

Latest fixes for python 3 branch

feature/python-3-migration
tr4ck3ur des JM2L 4 anni fa
parent
commit
3e22a6a890
9 ha cambiato i file con 56 aggiunte e 70 eliminazioni
  1. +2
    -3
      jm2l/__init__.py
  2. +3
    -1
      jm2l/auth.py
  3. +1
    -1
      jm2l/models.py
  4. +1
    -0
      jm2l/security.py
  5. +1
    -1
      jm2l/templates/Public/Programme.mako
  6. +2
    -2
      jm2l/templates/edit_event.mako
  7. +2
    -2
      jm2l/templates/helpers.mako
  8. +3
    -19
      jm2l/templates/layout.mako
  9. +41
    -41
      jm2l/views.py

+ 2
- 3
jm2l/__init__.py Vedi File

@@ -33,10 +33,10 @@ def add_renderer_globals(event):
# @sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=7)
def mailer_tasks(config):
# Send the Welcome Mail
mailer = config.registry['mailer']
contact = DBSession.query(User).filter(User.uid == 1).one()
request = Request.blank('/', base_url='http://jm2l.linux-azur.org')
request.registry = config.registry
mailer = request.mailer
for staff_user in DBSession.query(User).filter(User.Staff is True):
# Skip mail to contact
if staff_user == contact:
@@ -81,8 +81,7 @@ def main(global_config, **settings):
authentication_policy=authentication_policy,
authorization_policy=authorization_policy
)
#config.include('pyramid_mailer')
config.include('pyramid_mailer.debug')
config.include('pyramid_mailer')
config.add_subscriber(add_renderer_globals, BeforeRender)
print(settings)
# config.registry['mailer'] = mailer_factory_from_settings(settings)


+ 3
- 1
jm2l/auth.py Vedi File

@@ -12,10 +12,12 @@ from .security import check_logged
import datetime
import re


@view_config(route_name='auth', match_param="action=login", renderer="jm2l:templates/login.mako")
def login(request):
return {"comefrom":request.GET.get('from', "")}


@view_config(route_name='auth', match_param="action=forgot", renderer="jm2l:templates/login.mako")
def forgot(request):
if request.method == 'POST' and request.POST:
@@ -31,7 +33,7 @@ def forgot(request):
return { 'forgot': True }
else:
# Send the Forgot Mail
mailer = request.registry['mailer']
mailer = request.mailer
# Prepare Plain Text Message :
Mail_template = Template(filename='jm2l/templates/mail_plain.mako')
mail_plain = Mail_template.render(request=request, User=UserFound, action="Forgot")


+ 1
- 1
jm2l/models.py Vedi File

@@ -657,7 +657,7 @@ class Event(Base):
intervenants = relationship(User,
secondary='user_event_link',
backref=backref('participate', uselist=False),
lazy='dynamic')
lazy='subquery')
interventions = relationship(User_Event, backref="matching_events")
Salle = relationship(Salles, backref='allevents')



+ 1
- 0
jm2l/security.py Vedi File

@@ -15,6 +15,7 @@ def check_logged(request):
# Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')


def check_staff(request):
""" This function is intended to raise an exception if the user is not a Staff member"""
check_logged(request)


+ 1
- 1
jm2l/templates/Public/Programme.mako Vedi File

@@ -132,7 +132,7 @@ if Counter==0:
</span>
<br/>
avec
% for num, inter in enumerate(event.intervenants.all()):
% for num, inter in enumerate(event.intervenants):
%if num>0:
,
%endif


+ 2
- 2
jm2l/templates/edit_event.mako Vedi File

@@ -43,7 +43,7 @@
<div class="borderbox">
Intervenants programmés:
<ul>
% if event.intervenants.count()==0:
% if len(event.intervenants)==0:
<i><b>Aucun</b></i>
% else:
% for num, iterv in enumerate(event.intervenants):
@@ -160,7 +160,7 @@ DicForm = {
<td>
<u>Les Intervenants:</u>
<ul>
% if event.intervenants.count()==0:
% if len(event.intervenants)==0:
<i><b>Aucun</b></i>
% else:
% for num, iterv in enumerate(event.intervenants):


+ 2
- 2
jm2l/templates/helpers.mako Vedi File

@@ -391,9 +391,9 @@ TabJs = {'select':[], 'desc':[]}
</div>
% endif
<br/>
% if event.intervenants.count()>1:
% if len(event.intervenants)>1:
avec
% for num, inter in enumerate(event.intervenants.all()):
% for num, inter in enumerate(event.intervenants):
<%
if inter==uprofil:
continue


+ 3
- 19
jm2l/templates/layout.mako Vedi File

@@ -188,18 +188,18 @@ ${helpers.uploader_js()}
<div class="container">
<h4>JM2L 2005-2020</h4>
<p>
Concocté par <a href="http://www.linux-azur.org/">Linux Azur</a> ~
Concocté par <a href="https://www.linux-azur.org/">Linux Azur</a> ~
<a href="http://creativecommons.org/licenses/by-sa/4.0/">CopyFriendly</a>
</p>
<p>
+33 6 52 42 31 37 ~ contact at jm2l.linux-azur dot org
</p>
<p>
Conception et construction en <a href="http://git.linux-azur.org/JM2L/jm2l/src/master">DIY</a> ~
Conception et construction en <a href="https://git.linux-azur.org/tr4ck3ur/jm2l/src/branch/feature/python-3-migration">DIY</a> ~
Hébergé par <a href="http://www.heberg-24.com/"> Heberg24 </a>
</p>
<p>
Vous avez trouvé un bug ? <a href="http://git.linux-azur.org/JM2L/jm2l/issues">Reportez-le ici</a>
Vous avez trouvé un bug ? <a href="https://git.linux-azur.org/tr4ck3ur/jm2l/issues/new">Reportez-le ici</a>
</p>
</div>
</footer>
@@ -222,22 +222,6 @@ ${jsitem | n}
HandleControls();
</script>

<!-- Piwik
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//stats.style-python.fr/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 4]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//stats.style-python.fr/piwik.php?idsite=4" style="border:0;" alt="" /></p></noscript>
End Piwik Code -->
% if request.user:
<script>
function handlevote() {


+ 41
- 41
jm2l/views.py Vedi File

@@ -25,6 +25,7 @@ from pyramid_mailer.message import Message
from .security import check_staff, check_logged
# Then, standard libs
import csv

try:
from StringIO import StringIO
except ImportError:
@@ -41,7 +42,7 @@ from jm2l.const import CurrentYear
from passlib.hash import argon2


## =-=- Here, We keep some usefull function -=-=
# =-=- Here, We keep some usefull function -=-=
def remove_accents(input_str):
""" This function is intended to remove all accent from input unicode string """
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}


## =-=- Here, We handle ICal requests -=-=
# =-=- Here, We handle ICal requests -=-=
@view_config(route_name='progr_iCal', renderer="string")
def ICal_Progamme_Request(request):
year = int(request.matchdict.get('year', CurrentYear))
@@ -170,40 +171,39 @@ def ICal_Progamme_Dyn_Request(request):
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")
def JSON_User_Request(request):
""" Build a JSON answer with active users and pagination handling """
# Check arguments consitency
pageSize = request.params.get('pageSize', "8")
page_size = request.params.get('pageSize', "8")
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
if not request.user:
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)
pageSize = int(pageSize)
page_size = int(page_size)
else:
return HTTPBadRequest('pageSize and pageNum accept only digits.')
# 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")
@@ -223,13 +223,13 @@ def JSON_Tiers_Request(request):
else:
return HTTPBadRequest('pageSize and pageNum accept only digits.')
# 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}


@@ -237,25 +237,25 @@ def JSON_Tiers_Request(request):
def JSON_Progamme_Request(request):
year = int(request.matchdict.get('year', CurrentYear))
# Initialization
DicResult = dict()
dic_result = dict()
# Query database
# 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.event_type != None) \
.filter(Event.event_type is not None) \
.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.event_type != 'Stand') \
.filter(text("strftime('%d', start_time) = :dow")).params(dow=Day.day) \
.order_by(Event.start_time)

ListEv = []
for ev in Events:
list_ev = []
for ev in events:
if ev.event_type:
ListEv.append({
list_ev.append({
"uid": "%d/%d" % (year, ev.uid),
"desc": ev.name,
"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"),
"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")
@@ -2027,8 +2027,8 @@ def edit_tiers_category(request):
if dic_result[opt.slug_entity_type]['title'] != opt.entity_type or \
tst[1] != opt.entity_subtype:
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:
list_changes.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype))



Caricamento…
Annulla
Salva