diff --git a/jm2l/__init__.py b/jm2l/__init__.py
index 1f23a02..54cb251 100644
--- a/jm2l/__init__.py
+++ b/jm2l/__init__.py
@@ -26,6 +26,7 @@ import logging
def add_renderer_globals(event):
event['mytrip'] = Sejour_helpers(event)
event['myorga'] = Orga_helpers(event)
+ event['SelectedYear'] = CurrentYear
event['CurrentYear'] = CurrentYear
#@sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=07)
@@ -62,7 +63,8 @@ def mailer_tasks(config):
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
- locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
+ #locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
+ locale.setlocale(locale.LC_ALL, "fr_FR.utf8")
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
# Extract secrets from configuration file if any
diff --git a/jm2l/const.py b/jm2l/const.py
index 01b0230..c264c9f 100644
--- a/jm2l/const.py
+++ b/jm2l/const.py
@@ -1 +1 @@
-CurrentYear = 2017
\ No newline at end of file
+CurrentYear = 2018
diff --git a/jm2l/forms.py b/jm2l/forms.py
index 93ba72d..f2441f7 100644
--- a/jm2l/forms.py
+++ b/jm2l/forms.py
@@ -189,7 +189,7 @@ class PlaceCreateForm(MyBaseForm):
name = StringField('Nom Complet', [validators.Length(min=1, max=80)],
filters=[strip_filter])
gps_coord = StringField(u'Coordonnées GPS', [validators.Length(max=30),
- validators.Regexp( "^[0-9]*\.?[0-9],[0-9]*\.?[0-9]+",
+ validators.Regexp( "^[0-9]+\.?[0-9]+,[0-9]+\.?[0-9]+$",
message=u"Le GPS devrait être sous la forme 43.6158372,7.0723401")],
filters=[strip_filter])
adresse = TextAreaField('Adresse', [validators.Length(max=100)],
diff --git a/jm2l/helpers.py b/jm2l/helpers.py
index 0391e47..2a0aa6f 100644
--- a/jm2l/helpers.py
+++ b/jm2l/helpers.py
@@ -42,11 +42,11 @@ class Sejour_helpers(DummySejour):
return TabResult
if self.Sejour:
- ArrDate = datetime.strftime(self.Sejour.arrival_time,"%d %B %Y")
- DepDate = datetime.strftime(self.Sejour.depart_time,"%d %B %Y")
+ ArrDate = datetime.strftime(self.Sejour.arrival_time,"%d %B %Y").decode('utf-8')
+ DepDate = datetime.strftime(self.Sejour.depart_time,"%d %B %Y").decode('utf-8')
else:
- ArrDate = datetime.strftime( self.CurrentEventYear.start_time,"%d %B %Y" )
- DepDate = datetime.strftime( self.CurrentEventYear.end_time,"%d %B %Y" )
+ ArrDate = datetime.strftime( self.CurrentEventYear.start_time,"%d %B %Y" ).decode('utf-8')
+ DepDate = datetime.strftime( self.CurrentEventYear.end_time,"%d %B %Y" ).decode('utf-8')
for oneday in myDayRange:
if arrival:
@@ -55,7 +55,7 @@ class Sejour_helpers(DummySejour):
TmpDay = self.CurrentEventYear.start_time + timedelta(days=oneday)
DayName = datetime.strftime(TmpDay,"%A")
DayNum = datetime.strftime(TmpDay,"%d/%m/%y")
- DayString = datetime.strftime(TmpDay,"%d %B %Y")
+ DayString = datetime.strftime(TmpDay,"%d %B %Y").decode('utf-8')
if arrival and ArrDate==DayString:
TabResult.append((DayNum, DayName, 'selected="selected"'))
elif departure and DepDate==DayString:
diff --git a/jm2l/models.py b/jm2l/models.py
index b4b3067..af46e2b 100644
--- a/jm2l/models.py
+++ b/jm2l/models.py
@@ -102,7 +102,7 @@ class JM2L_Year(Base):
.filter(JM2L_Year.start_time ==
DBSession.query(func.max(JM2L_Year.start_time))
).one()
- return last_record.start_time.strftime("%A %d %b %Y")
+ return last_record.start_time.strftime("%A %d %b %Y").decode('utf-8')
@property
def AvailableTimeSlots(self, TimeStep=30):
diff --git a/jm2l/scripts/initializedb.py b/jm2l/scripts/initializedb.py
index 314e66b..cda8d2e 100644
--- a/jm2l/scripts/initializedb.py
+++ b/jm2l/scripts/initializedb.py
@@ -6,12 +6,13 @@ import time
import lxml.etree as ET
from sqlalchemy import engine_from_config
-from sqlalchemy import create_engine
+from sqlalchemy import create_engine, MetaData, Table
import unicodedata
import urllib
# Usefull tools
from slugify import slugify
from sqlite3 import dbapi2 as sqlite
+import sqlite3
from os import path
from pyramid.paster import (
get_appsettings,
@@ -19,7 +20,7 @@ from pyramid.paster import (
)
from string import printable
from random import choice
-
+from sqlalchemy import orm, or_
from jm2l.models import *
from datetime import datetime
@@ -30,8 +31,139 @@ def usage(argv):
'(example: "%s development.ini")' % (cmd, cmd))
sys.exit(1)
+def make_session(connection_string):
+ engine = create_engine(connection_string, echo=False, convert_unicode=True)
+ Session = sessionmaker(bind=engine)
+ return Session(), engine
+
+def quick_mapper(table):
+ Base = declarative_base()
+ class GenericMapper(Base):
+ __table__ = table
+ return GenericMapper
+
+def pull_data(from_db, to_db, tables):
+ source, sengine = make_session(from_db)
+ smeta = MetaData(bind=sengine)
+ destination, dengine = make_session(to_db)
+
+ for table_name in tables:
+ print 'Processing', table_name
+ print 'Pulling schema from source server'
+ table = Table(table_name, smeta, autoload=True)
+ print 'Creating table on destination server'
+ table.metadata.create_all(dengine)
+ NewRecord = quick_mapper(table)
+ columns = table.columns.keys()
+ print 'Transferring records'
+ for record in source.query(table).all():
+ data = dict(
+ [(str(column), getattr(record, column)) for column in columns]
+ )
+ if table_name=='salle':
+ if data['place_type']=='Ateliers':
+ data['place_type']='Atelier'
+ if table_name=='events':
+ if data['event_type']=='Concert':
+ data['event_type']='MAO'
+ try:
+ destination.merge(NewRecord(**data))
+ except:
+ print data
+ pass
+ print 'Committing changes'
+ destination.commit()
+
def main(argv=sys.argv):
+ connection_string = "sqlite:////home/tr4ck3ur/Dev/jm2l/JM2L.sqlite"
+ engine = create_engine(connection_string, echo=False, convert_unicode=True)
+ DBSession.configure(bind=engine)
+ Users = DBSession.query(User)
+ ListUser = filter(lambda x: x.is_Intervenant, Users)
+ for i in ListUser:
+ print i.mail
+
+def main4(argv=sys.argv):
+ import csv
+ from sqlalchemy import func
+
+ connection_string = "sqlite:////home/tr4ck3ur/Dev/jm2l/JM2L.sqlite"
+
+ if 1:
+ conn = sqlite3.connect("/home/tr4ck3ur/Dev/jm2l/JM2L.sqlite")
+ c = conn.cursor()
+ try:
+ c.execute("ALTER TABLE users ADD COLUMN wifi_user VARCHAR(80);")
+ c.execute("ALTER TABLE users ADD COLUMN wifi_pass VARCHAR(80);")
+ except:
+ pass # handle the error
+ c.close()
+
+ engine = create_engine(connection_string, echo=False, convert_unicode=True)
+ DBSession.configure(bind=engine)
+
+ with transaction.manager:
+ f = open("/home/tr4ck3ur/Dev/jm2l/wifi-11-11-pass.csv", 'rt')
+ try:
+ reader = csv.reader(f)
+ for row in reader:
+ prenom, nom, w_user, w_pass = row
+ slug = unicode( slugify(prenom +" "+nom) )
+ u = DBSession.query(User)\
+ .filter(User.slug==slug).first()
+ if u:
+ u.wifi_user = w_user
+ u.wifi_pass = w_pass
+ DBSession.merge(u)
+ print row, u
+ finally:
+ f.close()
+
+ if 0:
+
+ p0, p1 = orm.aliased(User,name="p0"), orm.aliased(User ,name="p1")
+ import pprint
+
+
+def main_3(argv=sys.argv):
+ connection_string = "sqlite:////home/tr4ck3ur/Dev/jm2l/JM2L.sqlite"
+ engine = create_engine(connection_string, echo=True, convert_unicode=True)
+ DBSession.configure(bind=engine)
+ p0, p1 = orm.aliased(User,name="p0"), orm.aliased(User ,name="p1")
+ import pprint
+
+ ## permtation
+ with transaction.manager:
+ Datas = DBSession.query(p0, p1)\
+ .filter(p0.slug==p1.slug)\
+ .filter(p0.uid!=p1.uid)\
+ .filter(p0.last_logged
Vous n'êtes pas authentifié, ou n'avez pas les autorisations nécessaires.
+Vous n'êtes pas authentifié, ou n'avez pas les authorisations nécessaires.
% endif