diff options
-rw-r--r-- | jm2l/captcha.py | 18 | ||||
-rw-r--r-- | jm2l/models.py | 24 | ||||
-rw-r--r-- | jm2l/templates/Interventions/Interventions.mako | 4 | ||||
-rw-r--r-- | jm2l/templates/Logistique/Dialog_Covoit.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/Logistique/Dialog_Heberg.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/Logistique/Dialog_Matos.mako | 4 | ||||
-rw-r--r-- | jm2l/templates/Logistique/Logistique.mako | 8 | ||||
-rw-r--r-- | jm2l/templates/Logistique/Tables.mako | 8 | ||||
-rw-r--r-- | jm2l/templates/Profil/Sejour.mako | 16 | ||||
-rw-r--r-- | jm2l/templates/Public/Programme.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/Staff/list.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/edit_event.mako | 8 | ||||
-rw-r--r-- | jm2l/templates/helpers.mako | 12 | ||||
-rw-r--r-- | jm2l/templates/index.mako | 4 | ||||
-rw-r--r-- | jm2l/templates/index_profil.mako | 4 | ||||
-rw-r--r-- | jm2l/templates/show_user.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/view_event.mako | 4 | ||||
-rw-r--r-- | jm2l/templates/view_tiers.mako | 2 | ||||
-rw-r--r-- | jm2l/templates/view_user.mako | 2 | ||||
-rw-r--r-- | jm2l/upload.py | 14 | ||||
-rw-r--r-- | jm2l/views.py | 45 | ||||
-rw-r--r-- | setup.py | 5 |
22 files changed, 96 insertions, 96 deletions
diff --git a/jm2l/captcha.py b/jm2l/captcha.py index 65ab5db..521d726 100644 --- a/jm2l/captcha.py +++ b/jm2l/captcha.py @@ -3,7 +3,7 @@ import random from PIL import Image, ImageDraw, ImageFont, ImageFilter -import StringIO +from io import BytesIO import math from pyramid.view import view_config from .words import TabMots @@ -48,17 +48,17 @@ class _PyCaptcha_WarpBase(object): def render(self, image): r = self.resolution - xPoints = image.size[0] / r + 2 - yPoints = image.size[1] / r + 2 + xPoints = image.size[0] // r + 2 + yPoints = image.size[1] // r + 2 f = self.get_transform(image) # Create a list of arrays with transformed points xRows = [] yRows = [] - for j in xrange(yPoints): + for j in range(yPoints): xRow = [] yRow = [] - for i in xrange(xPoints): + for i in range(xPoints): x, y = f(i*r, j*r) # Clamp the edges so we don't get black undefined areas @@ -73,8 +73,8 @@ class _PyCaptcha_WarpBase(object): # Create the mesh list, with a transformation for # each square between points on the grid mesh = [] - for j in xrange(yPoints-1): - for i in xrange(xPoints-1): + for j in range(yPoints-1): + for i in range(xPoints-1): mesh.append(( # Destination rectangle (i*r, j*r, @@ -124,7 +124,7 @@ def DoCaptcha(request): # Choose a word for captcha text = random.choice(TabMots) Xt, Yt = font.getsize(text) - OrX, OrY = (ImgSize[0]-Xt)/2, (ImgSize[1]-Yt)/2 + OrX, OrY = (ImgSize[0]-Xt)//2, (ImgSize[1]-Yt)//2 draw.text((OrX, OrY), text, font=font, fill="#000000") # Apply a Blur # WorkImg=WorkImg.filter(ImageFilter.BLUR) @@ -145,7 +145,7 @@ def DoCaptcha(request): # Save Result request.session['Captcha'] = text #session.save() - ImgHandle = StringIO.StringIO() + ImgHandle = BytesIO() WorkImg.save(ImgHandle,'png') ImgHandle.seek(0) return Response(app_iter=ImgHandle, content_type = 'image/png') diff --git a/jm2l/models.py b/jm2l/models.py index 9e33644..54acdf3 100644 --- a/jm2l/models.py +++ b/jm2l/models.py @@ -19,9 +19,9 @@ from sqlalchemy import ( ) from slugify import slugify -from webhelpers.text import urlify -from webhelpers.paginate import PageURL_WebOb, Page -from webhelpers.date import time_ago_in_words +from webhelpers2.text import urlify +from webhelpers2.date import time_ago_in_words +from paginate import Page from collections import namedtuple @@ -161,14 +161,14 @@ class User(Base): @property def my_hash(self): m = hashlib.sha1() - m.update("Nobody inspects ") + m.update("Nobody inspects ".encode('utf-8')) if self.nom: - m.update(unicode.encode(self.nom,'utf8')) + m.update(self.nom.encode('utf-8')) if self.pseudo: - m.update(unicode.encode(self.pseudo,'utf8')) - if self.prenom: - m.update(unicode.encode(self.prenom,'utf8')) - m.update(" the spammish repetition") + m.update(self.pseudo.encode('utf-8')) + if self.prenom: + m.update(self.prenom.encode('utf-8')) + m.update(" the spammish repetition".encode('utf-8')) return m.hexdigest() @property @@ -587,7 +587,7 @@ class Entry(Base): @classmethod def all(cls): - return DBSession.query(Entry).order_by(sa.desc(Entry.created)) + return DBSession.query(Entry).order_by(sa.desc(Entry.created)).all() @classmethod def by_id(cls, id): @@ -603,8 +603,8 @@ class Entry(Base): @classmethod def get_paginator(cls, request, page=1): - page_url = PageURL_WebOb(request) - return Page(Entry.all(), page, url=page_url, items_per_page=5) + return Page(Entry.all(), page, items_per_page=5, + url_maker=lambda p: "%s?page=%s" % (request.application_url, p)) #class Seances(Base): # __tablename__ = 'seances' diff --git a/jm2l/templates/Interventions/Interventions.mako b/jm2l/templates/Interventions/Interventions.mako index 8877efc..f917e63 100644 --- a/jm2l/templates/Interventions/Interventions.mako +++ b/jm2l/templates/Interventions/Interventions.mako @@ -65,7 +65,7 @@ elif Type=='T': <fieldset> <legend>Vos ${CurTitles} programmés pour 2015</legend> <% -Selection = filter(lambda x:(x.event_type==CurEventType and x.for_year==2015), uprofil.events) +Selection = [ x for x in uprofil.events if (x.event_type==CurEventType and x.for_year==2015) ] HeadHistTitle = u"L'historique de vos %s ( %d ) " % ( CurTitles, len(Selection) ) NothingTitle = u"Vous n'avez pas sollicité d'intervention %s." % CurEvent %> @@ -224,7 +224,7 @@ NothingTitle = u"Vous n'avez pas sollicité d'intervention %s." % CurEvent <fieldset> <legend>Historique</legend> <% -Selection = filter(lambda x:(x.event_type==CurEventType and x.for_year!=2015), uprofil.events) +Selection = [ x for x in uprofil.events if (x.event_type==CurEventType and x.for_year!=2015) ] HeadHistTitle = u"L'historique de vos %s ( %d ) " % ( CurTitles, len(Selection) ) NothingTitle = u"Désolé, Il n'y a rien dans l'historique vous concernant." %> diff --git a/jm2l/templates/Logistique/Dialog_Covoit.mako b/jm2l/templates/Logistique/Dialog_Covoit.mako index 7e2bf9b..3530f15 100644 --- a/jm2l/templates/Logistique/Dialog_Covoit.mako +++ b/jm2l/templates/Logistique/Dialog_Covoit.mako @@ -30,7 +30,7 @@ </tbody> </table> <center> - Pour un co-voiturage le <u>${Exch.start_time.strftime("%a %d %b").decode('utf-8')}</u> + Pour un co-voiturage le <u>${Exch.start_time.strftime("%a %d %b")}</u> vers <strong>${Exch.start_time.strftime("%H:%M")}</strong> </center> Temps de voyage estimé à <span id="summary"></span> diff --git a/jm2l/templates/Logistique/Dialog_Heberg.mako b/jm2l/templates/Logistique/Dialog_Heberg.mako index 75f6ce3..737dfd5 100644 --- a/jm2l/templates/Logistique/Dialog_Heberg.mako +++ b/jm2l/templates/Logistique/Dialog_Heberg.mako @@ -12,7 +12,7 @@ <dd>Un hébergement</dd> % endif <dt>Quand </dt> - <dd>La nuit du ${Exch.start_time.strftime('%A %d %b %Y').decode('utf-8')} jusqu'au lendemain</dd> + <dd>La nuit du ${Exch.start_time.strftime('%A %d %b %Y')} jusqu'au lendemain</dd> % if Exch.description: <dt>Détails </dt> <dd>${Exch.description}</dd> diff --git a/jm2l/templates/Logistique/Dialog_Matos.mako b/jm2l/templates/Logistique/Dialog_Matos.mako index 4f2085c..4974dd9 100644 --- a/jm2l/templates/Logistique/Dialog_Matos.mako +++ b/jm2l/templates/Logistique/Dialog_Matos.mako @@ -8,8 +8,8 @@ <dt>Catégorie</dt> <dd>${Exch.Category.exch_subtype}</dd> <dt>Quand </dt> - <dd>de ${Exch.start_time.strftime('%A %d %b %Y').decode('utf-8')} vers ${Exch.start_time.strftime('%Hh%M')} - à ${Exch.end_time.strftime('%A %d %b %Y').decode('utf-8')} vers ${Exch.end_time.strftime('%Hh%M')} + <dd>de ${Exch.start_time.strftime('%A %d %b %Y')} vers ${Exch.start_time.strftime('%Hh%M')} + à ${Exch.end_time.strftime('%A %d %b %Y')} vers ${Exch.end_time.strftime('%Hh%M')} </dd> <dt>Détails </dt> <dd>${Exch.description}</dd> diff --git a/jm2l/templates/Logistique/Logistique.mako b/jm2l/templates/Logistique/Logistique.mako index adb55ae..ce3f86b 100644 --- a/jm2l/templates/Logistique/Logistique.mako +++ b/jm2l/templates/Logistique/Logistique.mako @@ -112,7 +112,7 @@ elif Type=='M': <a href="/user/${item.provider.slug}"> ${item.provider.prenom} ${item.provider.nom} </a> offre % endif % if item.exch_type=="C": - un co-voiturage le ${item.start_time.strftime('%a %d %b vers %Hh%M').decode('utf-8')} + un co-voiturage le ${item.start_time.strftime('%a %d %b vers %Hh%M')} de <a href="javascript:DoGetLieu('/2015/modal/Place/${item.Itin.start.place_id}')">${item.Itin.start.display_name}</a> à <a href="javascript:DoGetLieu('/2015/modal/Place/${item.Itin.arrival.place_id}')">${item.Itin.arrival.display_name}</a> % elif item.exch_type=="M": @@ -122,8 +122,8 @@ elif Type=='M': % if item.description: ${item.description[:30]} % endif - de ${item.start_time.strftime('%a %d %b %Hh%M').decode('utf-8')} - à ${item.end_time.strftime('%a %d %b %Hh%M').decode('utf-8')} + de ${item.start_time.strftime('%a %d %b %Hh%M')} + à ${item.end_time.strftime('%a %d %b %Hh%M')} % else: % if item.Category: <i>${item.Category.exch_subtype}</i> @@ -131,7 +131,7 @@ elif Type=='M': % if item.description: ${item.description[:30]} % endif - ${item.start_time.strftime('%a %d %b').decode('utf-8')} soir + ${item.start_time.strftime('%a %d %b')} soir % endif </p> </td> diff --git a/jm2l/templates/Logistique/Tables.mako b/jm2l/templates/Logistique/Tables.mako index c97ea83..a8bbf06 100644 --- a/jm2l/templates/Logistique/Tables.mako +++ b/jm2l/templates/Logistique/Tables.mako @@ -97,17 +97,17 @@ elif Type=='M': </td> <td> %if Type=='C': - ${item.start_time.strftime('%A %d %b %Y').decode('utf-8')} vers ${item.start_time.strftime('%Hh%M')} + ${item.start_time.strftime('%A %d %b %Y')} vers ${item.start_time.strftime('%Hh%M')} de <a href="javascript:DoGetLieu('/2015/modal/Place/${item.Itin.start.place_id}')">${item.Itin.start.display_name}</a> à <a href="javascript:DoGetLieu('/2015/modal/Place/${item.Itin.arrival.place_id}')">${item.Itin.arrival.display_name}</a> %elif Type=='H': % if item.Category: <i>${item.Category.exch_subtype}</i>, % endif - La nuit du ${item.start_time.strftime('%A %d %b %Y').decode('utf-8')}<br> + La nuit du ${item.start_time.strftime('%A %d %b %Y')}<br> %elif Type=='M': - de ${item.start_time.strftime('%A %d %b %Y').decode('utf-8')} vers ${item.start_time.strftime('%Hh%M')} - à ${item.end_time.strftime('%A %d %b %Y').decode('utf-8')} vers ${item.end_time.strftime('%Hh%M')}<br> + de ${item.start_time.strftime('%A %d %b %Y')} vers ${item.start_time.strftime('%Hh%M')} + à ${item.end_time.strftime('%A %d %b %Y')} vers ${item.end_time.strftime('%Hh%M')}<br> ${item.Category.exch_subtype} %endif %if item.description: diff --git a/jm2l/templates/Profil/Sejour.mako b/jm2l/templates/Profil/Sejour.mako index 3fcd647..c1f5355 100644 --- a/jm2l/templates/Profil/Sejour.mako +++ b/jm2l/templates/Profil/Sejour.mako @@ -42,10 +42,10 @@ fieldset:disabled { </select> <% - context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Place').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Day').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Confidence').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Hour').select2({width:'resolve'});" % jsitem ) + context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Place').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Day').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Confidence').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Arrival\\\\:Hour').select2({width:'resolve'});") %> ##<script type="text/javascript"> ## $("#Arrival\\:Place").select2({}); @@ -122,10 +122,10 @@ fieldset:disabled { </select> <% - context._kwargs['postpone_js'].append( "$('#Departure\\\\:Place').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Departure\\\\:Day').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Departure\\\\:Confidence').select2({width:'resolve'});" % jsitem ) - context._kwargs['postpone_js'].append( "$('#Departure\\\\:Hour').select2({width:'resolve'});" % jsitem ) + context._kwargs['postpone_js'].append( "$('#Departure\\\\:Place').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Departure\\\\:Day').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Departure\\\\:Confidence').select2({width:'resolve'});") + context._kwargs['postpone_js'].append( "$('#Departure\\\\:Hour').select2({width:'resolve'});") %> ##<script type="text/javascript"> diff --git a/jm2l/templates/Public/Programme.mako b/jm2l/templates/Public/Programme.mako index a3274a1..cc066cf 100644 --- a/jm2l/templates/Public/Programme.mako +++ b/jm2l/templates/Public/Programme.mako @@ -105,7 +105,7 @@ if Counter==0: vid = event.video.first() pres = event.presentation.first() %> - ${event.start_time.strftime("%a %d %b").decode('utf-8')}<br> + ${event.start_time.strftime("%a %d %b")}<br> ${event.start_time.strftime("%H:%M")} - ${event.end_time.strftime("%H:%M")} </td> <td style="position: relative;"> diff --git a/jm2l/templates/Staff/list.mako b/jm2l/templates/Staff/list.mako index fbee9e5..712e488 100644 --- a/jm2l/templates/Staff/list.mako +++ b/jm2l/templates/Staff/list.mako @@ -56,7 +56,7 @@ from slugify import slugify <a href="/Staff/tasks/${task.uid}"> <span class="name">${task.name}</span> </a> - <span style="float:right;">${task.due_date.strftime("%d %b").decode("utf-8")}</span> + <span style="float:right;">${task.due_date.strftime("%d %b")}</span> % endif </td> <td style="position: relative;width:70px;"> diff --git a/jm2l/templates/edit_event.mako b/jm2l/templates/edit_event.mako index f033810..1c6aa66 100644 --- a/jm2l/templates/edit_event.mako +++ b/jm2l/templates/edit_event.mako @@ -46,7 +46,7 @@ % if 'uid' in form._fields: <div class="borderboxtime"> - ${event.start_time.strftime('%d %b %Y').decode('utf-8')} - + ${event.start_time.strftime('%d %b %Y')} - ${event.start_time.strftime('%H:%M')} à ${event.end_time.strftime('%H:%M')} %if event.Salle: - <strong>Salle</strong>: ${event.Salle.name} @@ -177,10 +177,10 @@ TabFields = [ </form> </fieldset> <div class="clearfix"> </div> - <p style="float:right;">Créé le ${event.created.strftime('%d %b %Y').decode('utf-8')}</p> + <p style="float:right;">Créé le ${event.created.strftime('%d %b %Y')}</p> %else: <p style="float:right;">Créé le - ${datetime.now().strftime('%d %b %Y').decode('utf-8')} + ${datetime.now().strftime('%d %b %Y')} </p> % endif <br/> @@ -217,4 +217,4 @@ if formAdd: context._kwargs['postpone_js'].append( "$('#%s-help').popover();" % jsitem ) %> ##${helpers.uploader_js()} -% endif
\ No newline at end of file +% endif diff --git a/jm2l/templates/helpers.mako b/jm2l/templates/helpers.mako index a8623d7..78a5262 100644 --- a/jm2l/templates/helpers.mako +++ b/jm2l/templates/helpers.mako @@ -6,7 +6,7 @@ TabJs = {'select':[], 'desc':[]} %> % for FieldName, Field in form._fields.items(): - % if DicFormat.has_key(Field.name) and DicFormat[Field.name].get("Ignore"): + % if Field.name in DicFormat and DicFormat[Field.name].get("Ignore"): <% continue %> % endif % if Field.type in ['HiddenField', 'CSRFTokenField']: @@ -15,11 +15,11 @@ TabJs = {'select':[], 'desc':[]} % elif Field.type=="SelectField": <% TabJs['select'].append(Field.label.field_id) %> % endif -% if DicFormat.has_key(Field.name) and DicFormat[Field.name].get("fieldset"): +% if Field.name in DicFormat and DicFormat[Field.name].get("fieldset"): <fieldset> <legend>${Field.label.text}</legend> % else: - % if DicFormat.has_key(Field.name) and DicFormat[Field.name].get("ContainerStyle"): + % if Field.name in DicFormat and DicFormat[Field.name].get("ContainerStyle"): <div style="padding-right:5px;${DicFormat[Field.name].get("ContainerStyle")}"> % else: <div style="padding-right:5px;"> @@ -35,7 +35,7 @@ TabJs = {'select':[], 'desc':[]} % endif </label> % endif - % if DicFormat.has_key(Field.name): + % if Field.name in DicFormat: <% PlaceHolder = DicFormat[Field.name].get("PlaceHolder") FieldStyle = DicFormat[Field.name].get("FieldStyle") @@ -56,7 +56,7 @@ TabJs = {'select':[], 'desc':[]} ${ error } </div> % endfor -% if DicFormat.has_key(Field.name) and DicFormat[Field.name].get("fieldset"): +% if Field.name in DicFormat and DicFormat[Field.name].get("fieldset"): </fieldset> % else: </div> @@ -282,7 +282,7 @@ TabJs = {'select':[], 'desc':[]} vid = event.video.first() pres = event.presentation.first() %> - ${event.start_time.strftime('%d %b %Y').decode('utf-8')} + ${event.start_time.strftime('%d %b %Y')} ${start.hour}:${"%.2d" % start.minute}-${end.hour}:${"%.2d" % end.minute} </td> <td style="position: relative;">${event.event_type}: diff --git a/jm2l/templates/index.mako b/jm2l/templates/index.mako index fb53150..7b24413 100644 --- a/jm2l/templates/index.mako +++ b/jm2l/templates/index.mako @@ -21,7 +21,7 @@ ${vars(user_id)} % if paginator.items: - ${paginator.pager()} + ${paginator.pager() | n} <h2>Blog entries</h2> @@ -34,7 +34,7 @@ ${vars(user_id)} % endfor </ul> - ${paginator.pager()} + ${paginator.pager() | n} % else: diff --git a/jm2l/templates/index_profil.mako b/jm2l/templates/index_profil.mako index 87667a4..ec12831 100644 --- a/jm2l/templates/index_profil.mako +++ b/jm2l/templates/index_profil.mako @@ -102,7 +102,7 @@ user_id = authenticated_userid(request) % if paginator.items: - ${paginator.pager()} + ${paginator.pager() | n} <h2>Blog entries</h2> @@ -115,7 +115,7 @@ user_id = authenticated_userid(request) % endfor </ul> - ${paginator.pager()} + ${paginator.pager() | n} % else: diff --git a/jm2l/templates/show_user.mako b/jm2l/templates/show_user.mako index f661346..e96ee0b 100644 --- a/jm2l/templates/show_user.mako +++ b/jm2l/templates/show_user.mako @@ -73,5 +73,5 @@ </div> <br/> <hr/> -<p style="float:right;">Créé le ${DispUser.created.strftime('%d %b %Y').decode('utf-8')}</p> +<p style="float:right;">Créé le ${DispUser.created.strftime('%d %b %Y')}</p> diff --git a/jm2l/templates/view_event.mako b/jm2l/templates/view_event.mako index 64d90d9..bc6b782 100644 --- a/jm2l/templates/view_event.mako +++ b/jm2l/templates/view_event.mako @@ -1,7 +1,7 @@ <%inherit file="jm2l:templates/layout.mako"/> <strong>${event.event_type}</strong>: <div class="borderboxtime"> -${event.start_time.strftime('%d %b %Y').decode('utf-8')} - +${event.start_time.strftime('%d %b %Y')} - ${event.start_time.strftime('%H:%M')} à ${event.end_time.strftime('%H:%M')} %if event.Salle: - <strong>Salle</strong>: ${event.Salle.name} @@ -63,7 +63,7 @@ ${event.start_time.strftime('%H:%M')} à ${event.end_time.strftime('%H:%M')} </p> % endfor <div class="clearfix"> </div> -<p style="float:right;">Créé le ${event.created.strftime('%d %b %Y').decode('utf-8')}</p> +<p style="float:right;">Créé le ${event.created.strftime('%d %b %Y')}</p> <br/> <hr/> diff --git a/jm2l/templates/view_tiers.mako b/jm2l/templates/view_tiers.mako index cbb84f2..d7b9d25 100644 --- a/jm2l/templates/view_tiers.mako +++ b/jm2l/templates/view_tiers.mako @@ -78,7 +78,7 @@ ${The_entity_type.entity_subtype} </p> % endfor -<p style="float:right;">Créé le ${entity.created.strftime('%d %b %Y').decode('utf-8')}</p> +<p style="float:right;">Créé le ${entity.created.strftime('%d %b %Y')}</p> <br/> <hr/> diff --git a/jm2l/templates/view_user.mako b/jm2l/templates/view_user.mako index 4a9f6d1..5012da4 100644 --- a/jm2l/templates/view_user.mako +++ b/jm2l/templates/view_user.mako @@ -41,5 +41,5 @@ <h4>Ses interventions :</h4> ${helpers.show_Interventions(DispUser.events)} % endif -<p style="float:right;">Créé le ${DispUser.created.strftime('%d %b %Y').decode('utf-8')}</p> +<p style="float:right;">Créé le ${DispUser.created.strftime('%d %b %Y')}</p> diff --git a/jm2l/upload.py b/jm2l/upload.py index 029862f..c4a8534 100644 --- a/jm2l/upload.py +++ b/jm2l/upload.py @@ -9,7 +9,7 @@ from os import path import mimetypes import magic import subprocess -import cStringIO as StringIO +from io import StringIO # Database access imports from .models import User, Place, Tiers, Event @@ -136,7 +136,7 @@ class MediaUpload(MediaPath): def validate(self, result, filecontent): # let's say we don't trust the uploader - RealMime = magic.from_buffer( filecontent.read(1024), mime=True) + RealMime = magic.from_buffer( filecontent.read(1024), mime=True).decode('utf-8') filecontent.seek(0) if RealMime!=result['type']: result['error'] = 'l\'extension du fichier ne correspond pas à son contenu - ' @@ -182,7 +182,7 @@ class MediaUpload(MediaPath): timage = Image.new('RGBA', (THUMBNAIL_SIZE, THUMBNAIL_SIZE), (255, 255, 255, 0)) timage.paste( image, - ((THUMBNAIL_SIZE - image.size[0]) / 2, (THUMBNAIL_SIZE - image.size[1]) / 2)) + ((THUMBNAIL_SIZE - image.size[0]) // 2, (THUMBNAIL_SIZE - image.size[1]) // 2)) TargetFileName = self.thumbnailpath(filename) timage.save( TargetFileName ) return self.thumbnailurl( os.path.basename(TargetFileName) ) @@ -199,7 +199,7 @@ class MediaUpload(MediaPath): # Add thumbnail timage.paste( image, - ((THUMBNAIL_SIZE - image.size[0]) / 2, (THUMBNAIL_SIZE - image.size[1]) / 2)) + ((THUMBNAIL_SIZE - image.size[0]) // 2, (THUMBNAIL_SIZE - image.size[1]) // 2)) # Stamp with PDF file type timage.paste( pdf_indicator, @@ -227,13 +227,13 @@ class MediaUpload(MediaPath): ('Impress','odp'), ('Calc','ods'), ('Draw','odg')] - stampfilename = filter(lambda (x,y): ext.endswith(y), istamp) + stampfilename = filter(lambda x,y : ext.endswith(y), istamp) stamp = Image.open( "jm2l/static/img/%s-icon.png" % stampfilename[0][0]) timage = Image.new('RGBA', (THUMBNAIL_SIZE, THUMBNAIL_SIZE), (255, 255, 255, 0)) # Add thumbnail timage.paste( image, - ((THUMBNAIL_SIZE - image.size[0]) / 2, (THUMBNAIL_SIZE - image.size[1]) / 2)) + ((THUMBNAIL_SIZE - image.size[0]) // 2, (THUMBNAIL_SIZE - image.size[1]) // 2)) # Stamp with PDF file type timage.paste( stamp, @@ -334,7 +334,7 @@ class MediaUpload(MediaPath): return self.delete() results = [] for name, fieldStorage in self.request.POST.items(): - if isinstance(fieldStorage,unicode): + if isinstance(fieldStorage,str): # FIXME continue result = {} result['name'] = os.path.basename(fieldStorage.filename) diff --git a/jm2l/views.py b/jm2l/views.py index 28d34b7..6fe3e4a 100644 --- a/jm2l/views.py +++ b/jm2l/views.py @@ -6,6 +6,7 @@ from pyramid.response import Response from pyramid.view import notfound_view_config, forbidden_view_config from pyramid.view import view_config from pyramid_mailer import get_mailer +from pyramid_mailer.message import Attachment, Message from mako.template import Template # Import Web Forms from .forms import * @@ -18,10 +19,8 @@ from slugify import slugify from icalendar import Calendar from pytz import timezone from icalendar import Event as Evt -from pyramid_mailer import get_mailer -from pyramid_mailer.message import Attachment, Message # Then, standard libs -import webhelpers.paginate as paginate +import paginate import unicodedata import time import datetime @@ -87,8 +86,8 @@ def JSON_User_Request(request): # 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) + records = paginate.Page(Users, current_page, items_per_page=pageSize, + url_maker=lambda p: "%s?page=%s" % (request.application_url, p)) 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 } @@ -112,8 +111,8 @@ def JSON_Tiers_Request(request): # Query database JTiers = DBSession.query(Tiers.uid, Tiers.name)\ .filter(Tiers.slug.contains( remove_accents(TiersQuery) )) - page_url = paginate.PageURL_WebOb(request) - records = paginate.Page(JTiers, current_page, url=page_url, items_per_page=pageSize) + records = paginate.Page(JTiers, current_page, items_per_page=pageSize, + url_maker=lambda p: "%s?page=%s" % (request.application_url, p)) ListMatchTiers = map( lambda t:{"id": t.uid, "text": t.name }, records ) return { "Results": ListMatchTiers, "Total":records.item_count, "logged_in":request.authenticated_userid } @@ -580,20 +579,20 @@ def Modal(request): form.populate_obj(Exch) if modtype in ['AskC', 'PropC']: Exch.itin_id = Itinerary.itin_id - if form._fields.has_key("Hour_start"): + if "Hour_start" in form._fields: TargetTime = datetime.datetime.strptime('%d %d %d %s' % (year, int(Week), \ int(form.Day_start.data), form.Hour_start.data), "%Y %W %w %H:%M") Exch.start_time = TargetTime - elif form._fields.has_key("Day_start"): + elif "Day_start" in form._fields: TargetTime = datetime.datetime.strptime('%d %d %d' % (year, int(Week), \ int(form.Day_start.data)), "%Y %W %w") Exch.start_time = TargetTime - if form._fields.has_key("Hour_end"): + if "Hour_end" in form._fields: TargetTime = datetime.datetime.strptime('%d %d %d %s' % (year, int(Week), \ int(form.Day_end.data), form.Hour_end.data), "%Y %W %w %H:%M") Exch.end_time = TargetTime - elif form._fields.has_key("Day_end"): + elif "Day_end" in form._fields: TargetTime = datetime.datetime.strptime('%d %d %d' % (year, int(Week), \ int(form.Day_end.data)), "%Y %W %w") Exch.end_time = TargetTime @@ -816,7 +815,7 @@ def edit_event(request): ] if not duration in [15, 30, 60, 90]: form.duration.choices.append( (duration,u'Conférence (%d min)' % duration) ) - if not form._fields.has_key("uid"): + if not "uid" in form._fields: form.duration.data=60 elif intervention=="Stand": form.duration.choices =[ @@ -826,12 +825,12 @@ def edit_event(request): elif intervention=="Atelier": form.duration.choices = map( lambda d:(d, u'Atelier (%dh%.2d)' % (d/60, d%60) ), \ [60, 90, 120, 150, 180, 210, 240] ) - if not duration in map(lambda (d,y): d, form.duration.choices): + if not duration in map(lambda d,y: d, form.duration.choices): form.duration.choices.append( (duration,u'Atelier (%dh%.2d)' % (duration/60, duration%60) ) ) elif intervention=="Table_Ronde": form.duration.choices = map( lambda d:(d, u'Table ronde (%dh%.2d)' % (d/60, d%60) ), \ [60, 90, 120, 150] ) - if not duration in map(lambda (d,y): d, form.duration.choices): + if not duration in map(lambda d,y: d, form.duration.choices): form.duration.choices.append( (duration,u'Table ronde (%dh%.2d)' % (duration/60, duration%60) ) ) else: return HTTPForbidden(u"Pas encore disponible.") @@ -848,7 +847,7 @@ def edit_event(request): TheEvent.start_time = TheYear[0].AvailableTimeSlots[form.start_sel.data] TheEvent.end_time = TheEvent.start_time + datetime.timedelta(minutes=form.duration.data) # Ok, time to put in database - if not form._fields.has_key("uid"): + if not "uid" in form._fields: TheEvent.slug = slugify(TheEvent.name) DBSession.add(TheEvent) # Append creator by default @@ -954,7 +953,7 @@ def edit_tiers(request): form.populate_obj(TheTiers) # Handle Remove of accents TheTiers.slug = slugify(form.name.data) - if not form._fields.has_key('uid'): + if not "uid" in form._fields: TheTiers.creator_id = request.user.uid DBSession.add(TheTiers) DBSession.flush() @@ -981,32 +980,32 @@ def edit_tiers_category(request): regT= RegTitle.match(key) reg = RegExist.match(key) if reg: - if not DicResult.has_key(reg.group('slug')): + if not reg.group('slug') in DicResult: DicResult[reg.group('slug')] = dict() - if DicResult[reg.group('slug')].has_key('items'): + if 'items' in DicResult[reg.group('slug')]: DicResult[reg.group('slug')]['items'].append( ( int(reg.group('id')), value ) ) else: DicResult[reg.group('slug')]['items'] = [ ( int(reg.group('id')), value ) ] elif regN: - if not DicResult.has_key(regN.group('slug')): + if not regN.group('slug') in DicResult: DicResult[regN.group('slug')] = dict() - if DicResult[regN.group('slug')].has_key('items'): + if 'items' in DicResult[regN.group('slug')]: DicResult[regN.group('slug')]['items'].append( ( 'id', value ) ) else: DicResult[regN.group('slug')]['items'] = [ ( 'id', value ) ] ListChanges.append(('add', 0, DicResult[regN.group('slug')]['title'], value)) elif regT: - if not DicResult.has_key(regT.group('slug')): + if not regT.group('slug') in DicResult: DicResult[regT.group('slug')] = dict() DicResult[regT.group('slug')]['title'] = value else: raise for opt in DBSession.query(TiersOpt).all(): - if DicResult.has_key(opt.slug_entity_type): - found = filter( lambda (x,y): opt.uid==x, + if opt.slug_entity_type in DicResult: + found = filter( lambda x,y: opt.uid==x, DicResult[opt.slug_entity_type].get('items', [])) if not found: ListChanges.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype)) @@ -21,7 +21,7 @@ requires = [ 'zope.sqlalchemy', 'waitress', 'wtforms', - 'webhelpers', + 'webhelpers2', 'lxml', 'python-slugify', 'icalendar', @@ -29,7 +29,8 @@ requires = [ 'Pillow', 'pyramid_exclog', 'repoze.sendmail==4.1', - 'pyramid_mailer' + 'pyramid_mailer', + 'paginate' ] setup(name='JM2L', |