Misc Fixes

This commit is contained in:
2020-08-08 01:17:55 +02:00
parent ad9883ae09
commit 588ce76eee
6 changed files with 577 additions and 498 deletions
+11
View File
@@ -36,3 +36,14 @@ If no error occurs, the webserver should be available on http://localhost:8080/
pserve development.ini pserve development.ini
Enjoy ! Enjoy !
sudo apt install virtualenv git python3-virtualenv
sudo mkdir -p /srv/jm2l
cd /srv/jm2l/
cd /srv
sudo chown luna jm2l
cd jm2l/
virtualenv -p python3 .venv_jm2l
+15 -8
View File
@@ -4,9 +4,11 @@ except ImportError:
from cgi import escape from cgi import escape
# from wtforms import widgets # from wtforms import widgets
from wtforms.widgets import HTMLString, html_params from wtforms.widgets import html_params
from wtforms.fields.core import Field from wtforms.fields.core import Field
from wtforms.compat import text_type, izip from wtforms.compat import text_type, izip
from markupsafe import Markup
class MySelect(object): class MySelect(object):
""" """
@@ -19,6 +21,7 @@ class MySelect(object):
call on rendering; this method must yield tuples of call on rendering; this method must yield tuples of
`(value, label, selected)`. `(value, label, selected)`.
""" """
def __init__(self, multiple=False): def __init__(self, multiple=False):
self.multiple = multiple self.multiple = multiple
@@ -40,7 +43,7 @@ class MySelect(object):
if last_group: if last_group:
html.append(self.render_optgroup(last_group, None)) html.append(self.render_optgroup(last_group, None))
html.append('</select>') html.append('</select>')
return HTMLString(''.join(html)) return Markup(''.join(html))
@classmethod @classmethod
def render_option(cls, value, label, selected, **kwargs): def render_option(cls, value, label, selected, **kwargs):
@@ -51,17 +54,19 @@ class MySelect(object):
options = dict(kwargs, value=value) options = dict(kwargs, value=value)
if selected: if selected:
options['selected'] = True options['selected'] = True
return HTMLString('<option %s>%s</option>' % (html_params(**options), escape(text_type(label), quote=False))) return Markup('<option %s>%s</option>' % (html_params(**options), escape(text_type(label), quote=False)))
@classmethod @classmethod
def render_optgroup(cls, previous_label, label, **kwargs): def render_optgroup(cls, previous_label, label, **kwargs):
options = dict(kwargs) options = dict(kwargs)
if previous_label is None: if previous_label is None:
return HTMLString('<optgroup %s label="%s">' % (html_params(**options), escape(text_type(label), quote=False))) return Markup(
'<optgroup %s label="%s">' % (html_params(**options), escape(text_type(label), quote=False)))
elif label is None: elif label is None:
return HTMLString('</optgroup>') return Markup('</optgroup>')
else: else:
return HTMLString('</optgroup><optgroup %s label="%s">' % (html_params(**options), escape(text_type(label), quote=False))) return Markup(
'</optgroup><optgroup %s label="%s">' % (html_params(**options), escape(text_type(label), quote=False)))
class MyOption(object): class MyOption(object):
@@ -71,6 +76,7 @@ class MyOption(object):
This is just a convenience for various custom rendering situations, and an This is just a convenience for various custom rendering situations, and an
option by itself does not constitute an entire field. option by itself does not constitute an entire field.
""" """
def __call__(self, field, **kwargs): def __call__(self, field, **kwargs):
return MySelect.render_option(field._value(), field.label.text, field.checked, **kwargs) return MySelect.render_option(field._value(), field.label.text, field.checked, **kwargs)
@@ -85,6 +91,7 @@ class MySelectFieldBase(Field):
This isn't a field, but an abstract base class for fields which want to This isn't a field, but an abstract base class for fields which want to
provide this functionality. provide this functionality.
""" """
def __init__(self, label=None, validators=None, option_widget=None, **kwargs): def __init__(self, label=None, validators=None, option_widget=None, **kwargs):
super(MySelectFieldBase, self).__init__(label, validators, **kwargs) super(MySelectFieldBase, self).__init__(label, validators, **kwargs)
@@ -128,11 +135,11 @@ class MySelectField(MySelectFieldBase):
# We should consider choiceA as an optgroup label # We should consider choiceA as an optgroup label
group_label = choiceA group_label = choiceA
for value, label in choiceB: for value, label in choiceB:
yield (group_label, value, label, self.coerce(value) == self.data) yield group_label, value, label, self.coerce(value) == self.data
else: else:
value, label = choiceA, choiceB value, label = choiceA, choiceB
# Not an optgroup, let's fallback to classic usage # Not an optgroup, let's fallback to classic usage
yield (None, value, label, self.coerce(value) == self.data) yield None, value, label, self.coerce(value) == self.data
def process_data(self, value): def process_data(self, value):
try: try:
+44 -44
View File
@@ -20,15 +20,16 @@ from mako.template import Template
from .models import User from .models import User
from jm2l.const import CurrentYear from jm2l.const import CurrentYear
from .models import JM2L_Year from .models import JM2L_Year
import logging import logging
def add_renderer_globals(event): def add_renderer_globals(event):
event['mytrip'] = Sejour_helpers(event) event['mytrip'] = Sejour_helpers(event)
event['myorga'] = Orga_helpers(event) event['myorga'] = Orga_helpers(event)
event['SelectedYear'] = CurrentYear event['SelectedYear'] = CurrentYear
event['CurrentYear'] = CurrentYear event['CurrentYear'] = CurrentYear
# @sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=07) # @sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=07)
def mailer_tasks(config): def mailer_tasks(config):
# Send the Welcome Mail # Send the Welcome Mail
@@ -60,6 +61,7 @@ def mailer_tasks(config):
mailer.send_immediately(message) mailer.send_immediately(message)
def main(global_config, **settings): def main(global_config, **settings):
""" This function returns a Pyramid WSGI application. """ This function returns a Pyramid WSGI application.
""" """
@@ -80,7 +82,7 @@ def main(global_config, **settings):
authorization_policy=authorization_policy authorization_policy=authorization_policy
) )
config.add_subscriber(add_renderer_globals, BeforeRender) config.add_subscriber(add_renderer_globals, BeforeRender)
# config.registry['mailer'] = mailer_factory_from_settings(settings) config.registry['mailer'] = mailer_factory_from_settings(settings)
config.registry['event_date'] = JM2L_Year.get_latest_jm2l_startdate() config.registry['event_date'] = JM2L_Year.get_latest_jm2l_startdate()
sched = BackgroundScheduler() sched = BackgroundScheduler()
sched.add_job(mailer_tasks, 'cron', day_of_week='fri', hour=18, args=[config]) sched.add_job(mailer_tasks, 'cron', day_of_week='fri', hour=18, args=[config])
@@ -100,70 +102,70 @@ def main(global_config, **settings):
config.add_static_view('resources', 'resources', cache_max_age=3600) config.add_static_view('resources', 'resources', cache_max_age=3600)
# ICal Routes # ICal Routes
config.add_route('progr_iCal', '/{year:\d+}/JM2L.ics') config.add_route('progr_iCal', r'/{year:\d+}/JM2L.ics')
config.add_route('progr_dyn_iCal', '/{year:\d+}/JM2L_dyn.ics') config.add_route('progr_dyn_iCal', r'/{year:\d+}/JM2L_dyn.ics')
# JSON Routes # JSON Routes
config.add_route('users_json', '/json-users') config.add_route('users_json', '/json-users')
config.add_route('tiers_json', '/json-tiers') config.add_route('tiers_json', '/json-tiers')
config.add_route('progr_json', '/{year:\d+}/le-prog-json') config.add_route('progr_json', r'/{year:\d+}/le-prog-json')
config.add_route('timeline_json', '/{year:\d+}/timeline-json') config.add_route('timeline_json', r'/{year:\d+}/timeline-json')
# Session setting Routes # Session setting Routes
config.add_route('year', '/year/{year:\d+}') config.add_route('year', r'/year/{year:\d+}')
config.add_route('vote_logo', '/vote_logo/{num:\d+}') config.add_route('vote_logo', r'/vote_logo/{num:\d+}')
# HTML Routes - Staff # HTML Routes - Staff
config.add_route('Live', '/Live') config.add_route('Live', '/Live')
config.add_route('list_expenses', '/{year:\d+}/Staff/compta') config.add_route('list_expenses', r'/{year:\d+}/Staff/compta')
config.add_route('list_task', '/{year:\d+}/Staff') config.add_route('list_task', r'/{year:\d+}/Staff')
config.add_route('handle_pole', '/{year:\d+}/Staff/poles{sep:/*}{pole_id:(\d+)?}') config.add_route('handle_pole', r'/{year:\d+}/Staff/poles{sep:/*}{pole_id:(\d+)?}')
config.add_route('handle_task', '/{year:\d+}/Staff/tasks{sep:/*}{task_id:(\d+)?}') config.add_route('handle_task', r'/{year:\d+}/Staff/tasks{sep:/*}{task_id:(\d+)?}')
config.add_route('action_task', '/{year:\d+}/Staff/{action:(\w+)}/{task_id:(\d+)}') config.add_route('action_task', r'/{year:\d+}/Staff/{action:(\w+)}/{task_id:(\d+)}')
config.add_route('action_task_area', '/{year:\d+}/Staff/pole/{action:(\w+)}/{pole_id:(\d+)}') config.add_route('action_task_area', r'/{year:\d+}/Staff/pole/{action:(\w+)}/{pole_id:(\d+)}')
config.add_route('list_salles', '/ListSalles') config.add_route('list_salles', '/ListSalles')
config.add_route('list_salles_phy', '/ListSallesPhy') config.add_route('list_salles_phy', '/ListSallesPhy')
config.add_route('handle_salle', '/Salles{sep:/*}{salle_id:(\d+)?}') config.add_route('handle_salle', r'/Salles{sep:/*}{salle_id:(\d+)?}')
config.add_route('handle_salle_phy', '/PhySalles{sep:/*}{salle_id:(\d+)?}') config.add_route('handle_salle_phy', r'/PhySalles{sep:/*}{salle_id:(\d+)?}')
config.add_route('action_salle', '/Salles/{action:(\w+)}/{salle_id:(\d+)}') config.add_route('action_salle', r'/Salles/{action:(\w+)}/{salle_id:(\d+)}')
config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}') config.add_route('pict_salle', r'/salle_picture/{salle_id:(\d+)}')
config.add_route('list_users', '/{year:\d+}/ListParticipant') config.add_route('list_users', r'/{year:\d+}/ListParticipant')
config.add_route('list_users_csv', '/{year:\d+}/ListParticipant.csv') config.add_route('list_users_csv', r'/{year:\d+}/ListParticipant.csv')
config.add_route('list_orga', '/{year:\d+}/ListOrga') config.add_route('list_orga', r'/{year:\d+}/ListOrga')
# HTML Routes - Public # HTML Routes - Public
config.add_route('home', '/{year:(\d+/)?}') config.add_route('home', r'/{year:(\d+/)?}')
config.add_route('edit_index', '/{year:\d+}/edit') config.add_route('edit_index', r'/{year:\d+}/edit')
config.add_route('presse', '/{year:\d+}/dossier-de-presse') config.add_route('presse', r'/{year:\d+}/dossier-de-presse')
config.add_route('edit_presse', '/{year:\d+}/dossier-de-presse/edit') config.add_route('edit_presse', r'/{year:\d+}/dossier-de-presse/edit')
config.add_route('programme', '/{year:\d+}/le-programme') config.add_route('programme', r'/{year:\d+}/le-programme')
config.add_route('plan', 'nous-rejoindre') config.add_route('plan', 'nous-rejoindre')
config.add_route('participer', 'participer-l-evenement') config.add_route('participer', 'participer-l-evenement')
config.add_route('captcha', '/captcha') config.add_route('captcha', '/captcha')
## Events ## Events
config.add_route('event', '/event/{year:\d+}/{event_id:([\w-]+)?}') config.add_route('event', r'/event/{year:\d+}/{event_id:([\w-]+)?}')
config.add_route('link_event_user', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user') config.add_route('link_event_user', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user')
config.add_route('delete_link_u', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_user') config.add_route('delete_link_u', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_user')
config.add_route('link_event_tiers', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers') config.add_route('link_event_tiers', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers')
config.add_route('delete_link_t', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_tiers') config.add_route('delete_link_t', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_tiers')
config.add_route('edit_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}') config.add_route('edit_event', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}')
config.add_route('delete_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}/delete') config.add_route('delete_event', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}/delete')
## Entities ## Entities
config.add_route('entities', '/entities') # {sep:/*}{Nature:\w+?}') config.add_route('entities', '/entities') # {sep:/*}{Nature:\w+?}')
config.add_route('add_entity', '/entity') config.add_route('add_entity', '/entity')
config.add_route('delete_entity', '/entity/{entity_id:(\d+)}/delete') config.add_route('delete_entity', r'/entity/{entity_id:(\d+)}/delete')
config.add_route('show_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}') config.add_route('show_entity', r'/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}')
config.add_route('edit_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit') config.add_route('edit_entity', r'/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit')
config.add_route('edit_entity_cat', '/categorie/entity') config.add_route('edit_entity_cat', '/categorie/entity')
## Users ## Users
config.add_route('pict_user', '/user_picture') config.add_route('pict_user', '/user_picture')
config.add_route('show_user', '/user/{user_slug:([\w-]+)?}') config.add_route('show_user', r'/user/{user_slug:([\w-]+)?}')
config.add_route('badge_user', '/user/{user_slug:([\w-]+)?}/badge') config.add_route('badge_user', r'/user/{user_slug:([\w-]+)?}/badge')
config.add_route('all_badges', '/badges') config.add_route('all_badges', '/badges')
config.add_route('place_print', '/place_print') config.add_route('place_print', '/place_print')
config.add_route('stand_print', '/stand_print') config.add_route('stand_print', '/stand_print')
@@ -175,10 +177,10 @@ def main(global_config, **settings):
config.add_route('miam', '/MonMiam') config.add_route('miam', '/MonMiam')
config.add_route('sejour', '/MonSejour') config.add_route('sejour', '/MonSejour')
config.add_route('orga', '/MonOrga') config.add_route('orga', '/MonOrga')
config.add_route('modal', '/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}') config.add_route('modal', r'/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}')
# Handle exchanges # Handle exchanges
config.add_route('exchange', '/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}') config.add_route('exchange', r'/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}')
# Handle authentication # Handle authentication
config.add_route('register', '/register') config.add_route('register', '/register')
@@ -186,10 +188,8 @@ def main(global_config, **settings):
config.add_route('bymail', '/sign/jm2l/{hash}') config.add_route('bymail', '/sign/jm2l/{hash}')
# Handle Multimedia and Uploads # Handle Multimedia and Uploads
config.add_route('media_view', '/image/{media_table:\w+}/{uid:\d+}/{name:.+}') config.add_route('media_view', r'/image/{media_table:\w+}/{uid:\d+}/{name:.+}')
config.add_route('media_upload', '/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}') config.add_route('media_upload', r'/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}')
config.scan() config.scan()
return config.make_wsgi_app() return config.make_wsgi_app()
+21 -19
View File
@@ -3,15 +3,14 @@
import random import random
from PIL import Image, ImageDraw, ImageFont, ImageFilter from PIL import Image, ImageDraw, ImageFont, ImageFilter
try: import io
from StringIO import StringIO # from io import StringIO
except ImportError:
from io import StringIO
import math import math
from pyramid.view import view_config from pyramid.view import view_config
from .words import TabMots from .words import TabMots
from pyramid.response import Response from pyramid.response import Response
class Captcha_Img(object): class Captcha_Img(object):
def __init__(self, width, height): def __init__(self, width, height):
self.width = width self.width = width
@@ -36,6 +35,7 @@ class Captcha_Img(object):
self._image = img self._image = img
return self._image return self._image
class _PyCaptcha_WarpBase(object): class _PyCaptcha_WarpBase(object):
"""Abstract base class for image warping. Subclasses define a """Abstract base class for image warping. Subclasses define a
function that maps points in the output image to points in the input image. function that maps points in the output image to points in the input image.
@@ -58,10 +58,10 @@ class _PyCaptcha_WarpBase(object):
# Create a list of arrays with transformed points # Create a list of arrays with transformed points
xRows = [] xRows = []
yRows = [] yRows = []
for j in xrange(yPoints): for j in range(int(yPoints)):
xRow = [] xRow = []
yRow = [] yRow = []
for i in xrange(xPoints): for i in range(int(xPoints)):
x, y = f(i * r, j * r) x, y = f(i * r, j * r)
# Clamp the edges so we don't get black undefined areas # Clamp the edges so we don't get black undefined areas
@@ -76,8 +76,8 @@ class _PyCaptcha_WarpBase(object):
# Create the mesh list, with a transformation for # Create the mesh list, with a transformation for
# each square between points on the grid # each square between points on the grid
mesh = [] mesh = []
for j in xrange(yPoints-1): for j in range(int(yPoints - 1)):
for i in xrange(xPoints-1): for i in range(int(xPoints - 1)):
mesh.append(( mesh.append((
# Destination rectangle # Destination rectangle
(i * r, j * r, (i * r, j * r,
@@ -91,6 +91,7 @@ class _PyCaptcha_WarpBase(object):
return image.transform(image.size, Image.MESH, mesh, self.filtering) return image.transform(image.size, Image.MESH, mesh, self.filtering)
class _PyCaptcha_SineWarp(_PyCaptcha_WarpBase): class _PyCaptcha_SineWarp(_PyCaptcha_WarpBase):
"""Warp the image using a random composition of sine waves""" """Warp the image using a random composition of sine waves"""
@@ -111,13 +112,14 @@ class _PyCaptcha_SineWarp(_PyCaptcha_WarpBase):
(math.sin((y + o[0]) * p) * a + x, (math.sin((y + o[0]) * p) * a + x,
math.sin((x + o[1]) * p) * a + y)) math.sin((x + o[1]) * p) * a + y))
@view_config(route_name='captcha') @view_config(route_name='captcha')
def DoCaptcha(request): def DoCaptcha(request):
ImgSize = (230, 100) ImgSize = (230, 100)
WorkImg = Image.new( 'RGBA', ImgSize, (255, 255, 255, 0) ) work_img = Image.new('RGBA', ImgSize, (255, 255, 255, 0))
Xmax, Ymax = WorkImg.size Xmax, Ymax = work_img.size
# Write something on it # Write something on it
draw = ImageDraw.Draw(WorkImg) draw = ImageDraw.Draw(work_img)
# use a truetype font # use a truetype font
# font = ImageFont.truetype("/var/lib/defoma/gs.d/dirs/fonts/LiberationMono-Regular.ttf", 40) # font = ImageFont.truetype("/var/lib/defoma/gs.d/dirs/fonts/LiberationMono-Regular.ttf", 40)
@@ -130,25 +132,25 @@ def DoCaptcha(request):
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") draw.text((OrX, OrY), text, font=font, fill="#000000")
# Apply a Blur # Apply a Blur
# WorkImg=WorkImg.filter(ImageFilter.BLUR) # work_img=work_img.filter(ImageFilter.BLUR)
# Apply a DETAIL # Apply a DETAIL
WorkImg=WorkImg.filter(ImageFilter.DETAIL) work_img = work_img.filter(ImageFilter.DETAIL)
# randomize parameters for perspective # randomize parameters for perspective
ax, ay = (random.uniform(0.9, 1.2), random.uniform(0.9, 1.2)) ax, ay = (random.uniform(0.9, 1.2), random.uniform(0.9, 1.2))
tx, ty = (random.uniform(0, 0.0003), random.uniform(0, 0.0003)) tx, ty = (random.uniform(0, 0.0003), random.uniform(0, 0.0003))
bx, by = (random.uniform(0.5, 0.8), random.uniform(0, 0.2)) bx, by = (random.uniform(0.5, 0.8), random.uniform(0, 0.2))
# Apply perspective to Captcha # Apply perspective to Captcha
WorkImg= WorkImg.transform(ImgSize, Image.PERSPECTIVE, (ax, bx, -25, by, ay, -10, tx, ty)) work_img = work_img.transform(ImgSize, Image.PERSPECTIVE, (ax, bx, -25, by, ay, -10, tx, ty))
# Apply SinWarp to Captcha # Apply SinWarp to Captcha
tr = Captcha_Img(Xmax, Ymax) tr = Captcha_Img(Xmax, Ymax)
tr._image = WorkImg tr._image = work_img
WorkImg = tr.render() work_img = tr.render()
# Apply a Smooth on it # Apply a Smooth on it
WorkImg=WorkImg.filter(random.choice([ImageFilter.SMOOTH, ImageFilter.SMOOTH_MORE])) work_img = work_img.filter(random.choice([ImageFilter.SMOOTH, ImageFilter.SMOOTH_MORE]))
# Save Result # Save Result
request.session['Captcha'] = text request.session['Captcha'] = text
# session.save() # session.save()
ImgHandle = StringIO.StringIO() ImgHandle = io.BytesIO()
WorkImg.save(ImgHandle,'png') work_img.save(ImgHandle, 'png')
ImgHandle.seek(0) ImgHandle.seek(0)
return Response(app_iter=ImgHandle, content_type='image/png') return Response(app_iter=ImgHandle, content_type='image/png')
+70 -12
View File
@@ -1,28 +1,45 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import random
import string
from wtforms import Form, BooleanField, StringField, TextAreaField, SelectField from wtforms import Form, BooleanField, StringField, TextAreaField, SelectField
from wtforms import SubmitField, validators, FieldList, PasswordField from wtforms import SubmitField, validators, FieldList, PasswordField
# import .ExtWforms # import .ExtWforms
from .ExtWtforms import MySelectField from .ExtWtforms import MySelectField
from wtforms import HiddenField, DecimalField, DateTimeField, FormField, DateField from wtforms import HiddenField, DecimalField, DateTimeField, FormField, DateField
from wtforms.validators import ValidationError from wtforms.validators import ValidationError
strip_filter = lambda x: x.strip() if x else None
from wtforms.csrf.session import SessionCSRF from wtforms.csrf.session import SessionCSRF
from datetime import timedelta from datetime import timedelta
from jm2l.const import CurrentYear from jm2l.const import CurrentYear
# What about an helper function
#def strip_filter(x)
# if x is no
strip_filter = lambda x: x.strip() if x else None
# get random string password with letters, digits, and symbols
def get_random_string(length):
csrf_characters = string.ascii_letters + string.digits + string.punctuation
csrf = ''.join(random.choice(password_characters) for i in range(length))
return csrf
class MyBaseForm(Form): class MyBaseForm(Form):
class Meta: class Meta:
csrf = True csrf = True
csrf_class = SessionCSRF csrf_class = SessionCSRF
csrf_secret = b'lJDQtOAMC2qe89doIn8u3Mch_DgeLSKO' # csrf_secret = b'lJDQtOAMC2qe89doIn8u3Mch_DgeLSKO'
csrf_secret = get_random_string(32)
csrf_time_limit = timedelta(minutes=60) csrf_time_limit = timedelta(minutes=60)
class BlogCreateForm(MyBaseForm): class BlogCreateForm(MyBaseForm):
title = StringField('Entry title', [validators.Length(min=1, max=255)], title = StringField('Entry title', [validators.Length(min=1, max=255)],
filters=[strip_filter]) filters=[strip_filter])
body = TextAreaField('Entry body', [validators.Length(min=1)], body = TextAreaField('Entry body', [validators.Length(min=1)],
filters=[strip_filter]) filters=[strip_filter])
class BlogUpdateForm(BlogCreateForm): class BlogUpdateForm(BlogCreateForm):
id = HiddenField() id = HiddenField()
@@ -56,9 +73,11 @@ class StaffArea(MyBaseForm):
) )
year_uid = HiddenField('year', default=str(CurrentYear)) year_uid = HiddenField('year', default=str(CurrentYear))
class EditStaffArea(StaffArea): class EditStaffArea(StaffArea):
uid = HiddenField() uid = HiddenField()
class StaffTasks(MyBaseForm): class StaffTasks(MyBaseForm):
name = StringField(u'Nom de la tâche', [validators.Required()]) name = StringField(u'Nom de la tâche', [validators.Required()])
area_uid = SelectField(u'Pôle concerné', coerce=int) area_uid = SelectField(u'Pôle concerné', coerce=int)
@@ -68,34 +87,42 @@ class StaffTasks(MyBaseForm):
filters=[strip_filter]) filters=[strip_filter])
year_uid = HiddenField('year', default=str(CurrentYear)) year_uid = HiddenField('year', default=str(CurrentYear))
class EditStaffTasks(StaffTasks): class EditStaffTasks(StaffTasks):
uid = HiddenField() uid = HiddenField()
class DossPresse(MyBaseForm): class DossPresse(MyBaseForm):
year_uid = HiddenField() year_uid = HiddenField()
doss_presse = TextAreaField('Dossier de Presse', [validators.optional(), validators.Length(max=1000000)], doss_presse = TextAreaField('Dossier de Presse', [validators.optional(), validators.Length(max=1000000)],
filters=[strip_filter]) filters=[strip_filter])
class IndexForm(MyBaseForm): class IndexForm(MyBaseForm):
year_uid = HiddenField() year_uid = HiddenField()
description = TextAreaField('Index', [validators.optional(), validators.Length(max=1000000)], description = TextAreaField('Index', [validators.optional(), validators.Length(max=1000000)],
filters=[strip_filter]) filters=[strip_filter])
class TiersMember(MyBaseForm): class TiersMember(MyBaseForm):
class Meta: class Meta:
csrf = False csrf = False
year_uid = SelectField(u'Année', coerce=int, choices=zip(range(2006,CurrentYear+1),range(2006,CurrentYear+1))) year_uid = SelectField(u'Année', coerce=int,
choices=zip(range(2006, CurrentYear + 1), range(2006, CurrentYear + 1)))
user_uid = StringField(u'user') user_uid = StringField(u'user')
role = StringField(u'Role') role = StringField(u'Role')
class TiersRole(MyBaseForm): class TiersRole(MyBaseForm):
class Meta: class Meta:
csrf = False csrf = False
year_uid = SelectField(u'Année', coerce=int, choices=zip(range(2006,CurrentYear+1),range(2006,CurrentYear+1))) year_uid = SelectField(u'Année', coerce=int,
choices=zip(range(2006, CurrentYear + 1), range(2006, CurrentYear + 1)))
tiers_role = SelectField(u'Role', choices=TIERS_ROLE) tiers_role = SelectField(u'Role', choices=TIERS_ROLE)
class TiersChoice(MyBaseForm): class TiersChoice(MyBaseForm):
class Meta: class Meta:
csrf = False csrf = False
@@ -105,6 +132,7 @@ class TiersChoice(MyBaseForm):
tiers_uid = StringField(u'Entité') tiers_uid = StringField(u'Entité')
role = StringField(u'Role') role = StringField(u'Role')
class AddIntervenant(MyBaseForm): class AddIntervenant(MyBaseForm):
class Meta: class Meta:
csrf = False csrf = False
@@ -112,6 +140,7 @@ class AddIntervenant(MyBaseForm):
event_uid = HiddenField() event_uid = HiddenField()
intervenant = SelectField(u'Intervenant', coerce=int) intervenant = SelectField(u'Intervenant', coerce=int)
class AddTiers(MyBaseForm): class AddTiers(MyBaseForm):
class Meta: class Meta:
csrf = False csrf = False
@@ -119,8 +148,8 @@ class AddTiers(MyBaseForm):
event_uid = HiddenField() event_uid = HiddenField()
tiers = SelectField(u'Entité', coerce=int) tiers = SelectField(u'Entité', coerce=int)
class ConfCreateForm(MyBaseForm):
class ConfCreateForm(MyBaseForm):
event_type = HiddenField() event_type = HiddenField()
for_year = HiddenField() for_year = HiddenField()
start_time = HiddenField() start_time = HiddenField()
@@ -153,23 +182,28 @@ class ConfCreateForm(MyBaseForm):
filters=[strip_filter] filters=[strip_filter]
) )
class ConfUpdateForm(ConfCreateForm): class ConfUpdateForm(ConfCreateForm):
uid = HiddenField() uid = HiddenField()
class SalleForm(MyBaseForm): class SalleForm(MyBaseForm):
year_uid = SelectField(u'Année', coerce=int) year_uid = SelectField(u'Année', coerce=int)
phy_salle_id = SelectField('Salle Physique', coerce=int) phy_salle_id = SelectField('Salle Physique', coerce=int)
place_type = SelectField('Type', choices=[('Conference', u'Conférence'), place_type = SelectField('Type', choices=[('Conference', u'Conférence'),
('Stand','Stand'), ('Atelier','Atelier'), ('Table ronde','Table ronde'), ('Stand', 'Stand'), ('Atelier', 'Atelier'),
('Table ronde', 'Table ronde'),
('MAO', 'MAO'), ('Repas', 'Repas / Snack'), ('Autres', 'Autres')]) ('MAO', 'MAO'), ('Repas', 'Repas / Snack'), ('Autres', 'Autres')])
name = StringField('Nom de la salle', [validators.Length(min=1, max=40)], name = StringField('Nom de la salle', [validators.Length(min=1, max=40)],
filters=[strip_filter]) filters=[strip_filter])
description = TextAreaField('Description', description = TextAreaField('Description',
filters=[strip_filter]) filters=[strip_filter])
class EditSalleForm(SalleForm): class EditSalleForm(SalleForm):
salle_id = HiddenField() salle_id = HiddenField()
class SallePhyForm(MyBaseForm): class SallePhyForm(MyBaseForm):
name = StringField('Nom de la salle', [validators.Length(min=1, max=40)], name = StringField('Nom de la salle', [validators.Length(min=1, max=40)],
filters=[strip_filter]) filters=[strip_filter])
@@ -177,11 +211,12 @@ class SallePhyForm(MyBaseForm):
description = TextAreaField('Description', description = TextAreaField('Description',
filters=[strip_filter]) filters=[strip_filter])
class EditSallePhyForm(SallePhyForm): class EditSallePhyForm(SallePhyForm):
uid = HiddenField() uid = HiddenField()
class PlaceCreateForm(MyBaseForm):
class PlaceCreateForm(MyBaseForm):
place_type = SelectField('Type', choices=PLACE_TYPE) place_type = SelectField('Type', choices=PLACE_TYPE)
display_name = StringField(u'Nom affiché', [validators.Length(min=1, max=20)], display_name = StringField(u'Nom affiché', [validators.Length(min=1, max=20)],
@@ -205,6 +240,7 @@ class PlaceCreateForm(MyBaseForm):
created_by = HiddenField() created_by = HiddenField()
class PlaceUpdateForm(PlaceCreateForm): class PlaceUpdateForm(PlaceCreateForm):
place_id = HiddenField() place_id = HiddenField()
@@ -213,6 +249,7 @@ def captcha_check(form, field):
if form.meta.csrf_context.get('Captcha') != field.data: if form.meta.csrf_context.get('Captcha') != field.data:
raise ValidationError(u"la vérification captcha est invalide.") raise ValidationError(u"la vérification captcha est invalide.")
class UserPasswordForm(MyBaseForm): class UserPasswordForm(MyBaseForm):
uid = HiddenField() uid = HiddenField()
password = PasswordField("Mot de passe", [ password = PasswordField("Mot de passe", [
@@ -223,8 +260,8 @@ class UserPasswordForm(MyBaseForm):
) )
confirm = PasswordField('Confirmez') confirm = PasswordField('Confirmez')
class UserRegisterForm(MyBaseForm):
class UserRegisterForm(MyBaseForm):
nom = StringField(u'Nom', [ nom = StringField(u'Nom', [
validators.Length(max=80, message=u"80 car. maximum"), validators.Length(max=80, message=u"80 car. maximum"),
validators.required(message=u"Ce champ est obligatoire")], validators.required(message=u"Ce champ est obligatoire")],
@@ -248,6 +285,7 @@ class UserRegisterForm(MyBaseForm):
filters=[strip_filter] filters=[strip_filter]
) )
class ProfilForm(MyBaseForm): class ProfilForm(MyBaseForm):
id = HiddenField() id = HiddenField()
user_id = HiddenField() user_id = HiddenField()
@@ -276,7 +314,8 @@ class ProfilForm(MyBaseForm):
) )
phone = StringField(u'Mobile', [validators.optional(), validators.Length(max=10), phone = StringField(u'Mobile', [validators.optional(), validators.Length(max=10),
validators.Regexp("\d+", message=u"Le numéro de téléphone mobile ne doit contenir que des chiffres")], validators.Regexp("\d+",
message=u"Le numéro de téléphone mobile ne doit contenir que des chiffres")],
filters=[strip_filter], filters=[strip_filter],
description=u"Un numéro de mobile valide. Afin de pouvoir rester en" + description=u"Un numéro de mobile valide. Afin de pouvoir rester en" +
u"contact avec les personne de l'organisation, et pour vos échanges. " + u"contact avec les personne de l'organisation, et pour vos échanges. " +
@@ -359,13 +398,14 @@ class DateStartConfidenceForm(MyBaseForm):
filters=[strip_filter]) filters=[strip_filter])
start_time = HiddenField() start_time = HiddenField()
class ItineraireForm(Form): class ItineraireForm(Form):
start_place = SelectField(u'En partant de', coerce=int) start_place = SelectField(u'En partant de', coerce=int)
arrival_place = SelectField(u'et à destination de', coerce=int) arrival_place = SelectField(u'et à destination de', coerce=int)
itin_id = HiddenField() itin_id = HiddenField()
class AddItineraireForm(Form):
class AddItineraireForm(Form):
itin = FormField(ItineraireForm) itin = FormField(ItineraireForm)
distance = DecimalField(u'Distance', [validators.Length(min=1, max=4)], distance = DecimalField(u'Distance', [validators.Length(min=1, max=4)],
filters=[strip_filter]) filters=[strip_filter])
@@ -382,6 +422,7 @@ class AddItineraireForm(Form):
tr_avion = BooleanField(u'en avion') tr_avion = BooleanField(u'en avion')
description = TextAreaField(u'Description de l\'itinéraire') description = TextAreaField(u'Description de l\'itinéraire')
class AddMember(MyBaseForm): class AddMember(MyBaseForm):
tiers_uid = HiddenField() tiers_uid = HiddenField()
nom = StringField(u'Nom', [validators.Length(max=80)], nom = StringField(u'Nom', [validators.Length(max=80)],
@@ -404,6 +445,7 @@ class AddMember(MyBaseForm):
u"son inscription sur le site.") u"son inscription sur le site.")
add = SubmitField('Ajouter des membres') add = SubmitField('Ajouter des membres')
class TiersForm(MyBaseForm): class TiersForm(MyBaseForm):
name = StringField(u'Nom', [validators.Length(max=100)], name = StringField(u'Nom', [validators.Length(max=100)],
filters=[strip_filter], filters=[strip_filter],
@@ -429,6 +471,7 @@ class TiersForm(MyBaseForm):
roles = FieldList(FormField(TiersRole)) roles = FieldList(FormField(TiersRole))
class UpdateTiersForm(TiersForm): class UpdateTiersForm(TiersForm):
uid = HiddenField() uid = HiddenField()
tiers_id = HiddenField() tiers_id = HiddenField()
@@ -443,9 +486,11 @@ class ExchCateg(MyBaseForm):
description = TextAreaField('Description', description = TextAreaField('Description',
filters=[strip_filter]) filters=[strip_filter])
class UpdateExchangeForm(MyBaseForm): class UpdateExchangeForm(MyBaseForm):
exch_id = HiddenField() exch_id = HiddenField()
class AskCForm(ItineraireForm): class AskCForm(ItineraireForm):
ConfidenceLevel = [ ConfidenceLevel = [
("0", u"exactement à"), ("0", u"exactement à"),
@@ -466,8 +511,10 @@ class AskCForm(ItineraireForm):
arrival_place = SelectField(u'et à destination de', coerce=int) arrival_place = SelectField(u'et à destination de', coerce=int)
itin_id = HiddenField() itin_id = HiddenField()
class AskHForm(MyBaseForm): class AskHForm(MyBaseForm):
DayChoice = [("4",u"Jeudi à Vendredi"), ("5",u"Vendredi à Samedi"), ("6",u"Samedi à Dimanche"), ("0",u"Dimanche à Lundi")] DayChoice = [("4", u"Jeudi à Vendredi"), ("5", u"Vendredi à Samedi"), ("6", u"Samedi à Dimanche"),
("0", u"Dimanche à Lundi")]
Day_start = SelectField(u'Pour la nuit de', choices=DayChoice) Day_start = SelectField(u'Pour la nuit de', choices=DayChoice)
start_time = HiddenField() start_time = HiddenField()
description = TextAreaField(u'Description de vos contraintes éventuelles', filters=[strip_filter], description = TextAreaField(u'Description de vos contraintes éventuelles', filters=[strip_filter],
@@ -475,6 +522,7 @@ class AskHForm(MyBaseForm):
+ u"les contraintes à prendre en compte. N'hésitez pas à donner des détails." + u"les contraintes à prendre en compte. N'hésitez pas à donner des détails."
) )
class AskMForm(MyBaseForm): class AskMForm(MyBaseForm):
DayChoice = [("4", "Jeudi"), ("5", "Vendredi"), ("6", "Samedi"), ("0", "Dimanche"), ("1", "Lundi")] DayChoice = [("4", "Jeudi"), ("5", "Vendredi"), ("6", "Samedi"), ("0", "Dimanche"), ("1", "Lundi")]
Day_start = SelectField(u"à partir de", choices=DayChoice) Day_start = SelectField(u"à partir de", choices=DayChoice)
@@ -499,6 +547,7 @@ class AskMForm(MyBaseForm):
+ u"échanger. N'hésitez pas à donner des détails." + u"échanger. N'hésitez pas à donner des détails."
) )
class PropCForm(ItineraireForm): class PropCForm(ItineraireForm):
ConfidenceLevel = [ ConfidenceLevel = [
("0", u"exactement à"), ("0", u"exactement à"),
@@ -519,8 +568,10 @@ class PropCForm(ItineraireForm):
arrival_place = SelectField(u'et à destination de', coerce=int) arrival_place = SelectField(u'et à destination de', coerce=int)
itin_id = HiddenField() itin_id = HiddenField()
class PropHForm(MyBaseForm): class PropHForm(MyBaseForm):
DayChoice = [("4",u"Jeudi à Vendredi"), ("5",u"Vendredi à Samedi"), ("6",u"Samedi à Dimanche"), ("0",u"Dimanche à Lundi")] DayChoice = [("4", u"Jeudi à Vendredi"), ("5", u"Vendredi à Samedi"), ("6", u"Samedi à Dimanche"),
("0", u"Dimanche à Lundi")]
Day_start = SelectField(u'Pour la nuit de', choices=DayChoice) Day_start = SelectField(u'Pour la nuit de', choices=DayChoice)
start_time = HiddenField() start_time = HiddenField()
exch_categ = SelectField(u'Type de couchage', coerce=int, exch_categ = SelectField(u'Type de couchage', coerce=int,
@@ -532,6 +583,7 @@ class PropHForm(MyBaseForm):
place_id = SelectField(u'Emplacement', coerce=int, place_id = SelectField(u'Emplacement', coerce=int,
description=u"Indiquez ici une des adresses que vous avez proposé") description=u"Indiquez ici une des adresses que vous avez proposé")
class PropMForm(MyBaseForm): class PropMForm(MyBaseForm):
DayChoice = [("4", "Jeudi"), ("5", "Vendredi"), ("6", "Samedi"), ("0", "Dimanche"), ("1", "Lundi")] DayChoice = [("4", "Jeudi"), ("5", "Vendredi"), ("6", "Samedi"), ("0", "Dimanche"), ("1", "Lundi")]
Day_start = SelectField(u"à partir de", choices=DayChoice) Day_start = SelectField(u"à partir de", choices=DayChoice)
@@ -556,20 +608,26 @@ class PropMForm(MyBaseForm):
+ u"proposer. N'hésitez pas à donner des détails." + u"proposer. N'hésitez pas à donner des détails."
) )
class UpdateAskCForm(AskCForm, UpdateExchangeForm): class UpdateAskCForm(AskCForm, UpdateExchangeForm):
pass pass
class UpdateAskHForm(AskHForm, UpdateExchangeForm): class UpdateAskHForm(AskHForm, UpdateExchangeForm):
pass pass
class UpdateAskMForm(AskMForm, UpdateExchangeForm): class UpdateAskMForm(AskMForm, UpdateExchangeForm):
pass pass
class UpdatePropCForm(PropCForm, UpdateExchangeForm): class UpdatePropCForm(PropCForm, UpdateExchangeForm):
pass pass
class UpdatePropHForm(PropHForm, UpdateExchangeForm): class UpdatePropHForm(PropHForm, UpdateExchangeForm):
pass pass
class UpdatePropMForm(PropMForm, UpdateExchangeForm): class UpdatePropMForm(PropMForm, UpdateExchangeForm):
pass pass
+2 -1
View File
@@ -35,7 +35,8 @@ requires = [
'reportlab', 'reportlab',
'passlib', 'passlib',
'argon2_cffi', 'argon2_cffi',
'paginate' 'paginate',
'markupsafe'
] ]
setup(name='JM2L', setup(name='JM2L',