瀏覽代碼

Latest Fixes

feature/python-3-migration
tr4ck3ur des JM2L 4 年之前
父節點
當前提交
be2441096d
共有 4 個檔案被更改,包括 75 行新增65 行删除
  1. +5
    -5
      jm2l/models.py
  2. +1
    -1
      jm2l/templates/helpers.mako
  3. +2
    -2
      jm2l/templates/layout.mako
  4. +67
    -57
      jm2l/views.py

+ 5
- 5
jm2l/models.py 查看文件

@@ -119,11 +119,11 @@ class JM2L_Year(Base):

@property
def AvailableTimeSlots(self, TimeStep=30):
Available = self.end_time - self.start_time
NbMinutes = Available.total_seconds() / 60
NbSteps = NbMinutes / TimeStep
available = self.end_time - self.start_time
nb_minutes = available.total_seconds() / 60
nb_steps = nb_minutes / TimeStep
# Create the range of date each 30min
date_list = [self.start_time + datetime.timedelta(minutes=TimeStep * x) for x in range(0, int(NbSteps))]
date_list = [self.start_time + datetime.timedelta(minutes=TimeStep * x) for x in range(0, int(nb_steps))]
# Remove out of range datetime
# Remove hours > 19h
date_list = filter(lambda x: x.hour < 19, date_list)
@@ -131,7 +131,7 @@ class JM2L_Year(Base):
date_list = filter(lambda x: x.hour >= 10, date_list)
# Remove 12h < hours < 13h
date_list = filter(lambda x: x.hour < 12 or x.hour >= 13, date_list)
return date_list
return list(date_list)

@property
def DocLinks(self):


+ 1
- 1
jm2l/templates/helpers.mako 查看文件

@@ -105,7 +105,7 @@ TabJs = {'select':[], 'desc':[]}
<%
PlaceHolder = DicFormat[Field.name].get("PlaceHolder")
FieldStyle = DicFormat[Field.name].get("FieldStyle")
Class = [False,"ckeditor"][ "ckeditor" in DicFormat[Field.name] ]
Class = [False, "ckeditor"][ "ckeditor" in DicFormat[Field.name] ]
%>
% if Field.type == "date":
${Field(placeholder=PlaceHolder or False, style=FieldStyle, class_="datepicker" )}


+ 2
- 2
jm2l/templates/layout.mako 查看文件

@@ -222,7 +222,7 @@ ${jsitem | n}
HandleControls();
</script>

<!-- Piwik -->
<!-- Piwik
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
@@ -237,7 +237,7 @@ HandleControls();
})();
</script>
<noscript><p><img src="//stats.style-python.fr/piwik.php?idsite=4" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
End Piwik Code -->
% if request.user:
<script>
function handlevote() {


+ 67
- 57
jm2l/views.py 查看文件

@@ -196,6 +196,15 @@ def JSON_User_Request(request):
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)



@view_config(route_name='tiers_json', renderer="json")
def JSON_Tiers_Request(request):
@@ -216,6 +225,7 @@ 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)
ListMatchTiers = map(lambda t: {"id": t.uid, "text": t.name}, records)
@@ -739,9 +749,9 @@ def handle_salle(request):
else:
Salle = Salles()
form = SalleForm(request.POST, Salle, meta={'csrf_context': request.session})
form.year_uid.choices = map(tuple, DBSession.query(JM2L_Year.year_uid, JM2L_Year.year_uid).order_by(
form.year_uid.choices = tuple(DBSession.query(JM2L_Year.year_uid, JM2L_Year.year_uid).order_by(
sa.desc(JM2L_Year.year_uid)).all())
form.phy_salle_id.choices = map(tuple, DBSession.query(SallePhy.uid, SallePhy.name).all())
form.phy_salle_id.choices = tuple(DBSession.query(SallePhy.uid, SallePhy.name).all())
if request.method == 'POST' and form.validate():
form.populate_obj(Salle)
if 'uid' in form._fields.keys():
@@ -1275,23 +1285,23 @@ 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"):
TargetTime = datetime.datetime.strptime('%d %d %d %s' % (year, int(Week), \
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"):
TargetTime = datetime.datetime.strptime('%d %d %d' % (year, int(Week), \
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"):
TargetTime = datetime.datetime.strptime('%d %d %d %s' % (year, int(Week), \
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"):
TargetTime = datetime.datetime.strptime('%d %d %d' % (year, int(Week), \
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

@@ -1618,7 +1628,7 @@ def edit_event(request):
if not TheYear:
raise HTTPNotFound(u"Cette année n'est pas pris en charge")
#  Generate Timeslots for current year
TimeSlots = list(enumerate([x.strftime('%a %d %b %H:%M').decode('utf-8') for x in
TimeSlots = list(enumerate([x.strftime('%a %d %b %H:%M') for x in
TheYear.AvailableTimeSlots]))

if event_id:
@@ -1683,7 +1693,7 @@ def edit_event(request):
formAdd = None
formAddT = None

SalleDispo = DBSession.query(Salles) \
salle_dispo = DBSession.query(Salles) \
.filter(Salles.year_uid == year) \
.order_by('name')

@@ -1696,37 +1706,37 @@ 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
SalleDispo = SalleDispo.filter(Salles.place_type.in_(['Conference', 'MAO', 'Atelier']))
salle_dispo = salle_dispo.filter(Salles.place_type.in_(['Conference', 'MAO', 'Atelier']))
elif intervention == "Stand":
form.duration.choices = [
(8 * 60, u'Toute la journée'),
(4 * 60, u'une demi-journée')
]
SalleDispo = SalleDispo.filter(Salles.place_type == 'Stand')
salle_dispo = salle_dispo.filter(Salles.place_type == 'Stand')
elif intervention == "Atelier":
form.duration.choices = map(lambda d: (d, u'Atelier (%dh%.2d)' % (d / 60, d % 60)), \
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):
form.duration.choices.append((duration, u'Atelier (%dh%.2d)' % (duration / 60, duration % 60)))
SalleDispo = SalleDispo.filter(Salles.place_type.in_(['Atelier', 'MAO']))
salle_dispo = salle_dispo.filter(Salles.place_type.in_(['Atelier', 'MAO']))
elif intervention == "Table_ronde":
form.duration.choices = map(lambda d: (d, u'Table ronde (%dh%.2d)' % (d / 60, d % 60)), \
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):
form.duration.choices.append((duration, u'Table ronde (%dh%.2d)' % (duration / 60, duration % 60)))
SalleDispo = SalleDispo.filter(Salles.place_type == 'Table ronde')
salle_dispo = salle_dispo.filter(Salles.place_type == 'Table ronde')
elif intervention == "Concert":
form.duration.choices = map(lambda d: (d, u'Concert (%dh%.2d)' % (d / 60, d % 60)), \
form.duration.choices = map(lambda d: (d, u'Concert (%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):
form.duration.choices.append((duration, u'Concert (%dh%.2d)' % (duration / 60, duration % 60)))
SalleDispo = SalleDispo.filter(Salles.place_type.in_(['Stand', 'MAO']))
salle_dispo = salle_dispo.filter(Salles.place_type.in_(['Stand', 'MAO']))
else:
raise HTTPForbidden(u"Pas encore disponible.")

form.salle_uid.choices = [(s.salle_id, s.name) for s in SalleDispo]
form.salle_uid.choices = [(s.salle_id, s.name) for s in salle_dispo]
form.start_sel.choices = TimeSlots

if request.method == 'POST' and form.validate():
@@ -1734,8 +1744,8 @@ def edit_event(request):
TheEvent.start_time = TheYear.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"):
TheEvent.slug = unicode(slugify(TheEvent.name))
if not "uid" in form._fields:
TheEvent.slug = slugify(TheEvent.name)
if intervention == u"Table_ronde":
TheEvent.event_type = "Table ronde"
DBSession.add(TheEvent)
@@ -1925,7 +1935,7 @@ def edit_tiers(request):
form.populate_obj(TheTiers)
# Handle Remove of accents
OriginalSlug = TheTiers.slug
if not form._fields.has_key('uid'):
if not "uid" in form._fields:
TheTiers.slug = slugify(form.name.data)
TheTiers.creator_id = request.user.uid
DBSession.add(TheTiers)
@@ -1970,71 +1980,71 @@ def edit_tiers_category(request):
if request.user is None:
# Don't answer to users that aren't logged
raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
DicResult = dict()
ListChanges = list()
dic_result = dict()
list_changes = list()
if request.method == 'POST':
#  Reformat data
RegExist = re.compile('collection\[(?P<slug>[\w-]+)\]\[(?P<num>\d+)\]\[(?P<id>\d+)\]')
RegTitle = re.compile('collection\[(?P<slug>[\w-]+)\]\[title]')
RegNew = re.compile('collection\[(?P<slug>[\w-]+)\]\[(?P<num>\d+)\]\[id\]')
reg_exist = re.compile(r'collection\[(?P<slug>[\w-]+)\]\[(?P<num>\d+)\]\[(?P<id>\d+)\]')
reg_title = re.compile(r'collection\[(?P<slug>[\w-]+)\]\[title]')
reg_new = re.compile(r'collection\[(?P<slug>[\w-]+)\]\[(?P<num>\d+)\]\[id\]')
for key, value in request.POST.items():
regN = RegNew.match(key)
regT = RegTitle.match(key)
reg = RegExist.match(key)
regN = reg_new.match(key)
regT = reg_title.match(key)
reg = reg_exist.match(key)
if reg:
if not reg.group('slug') in DicResult:
DicResult[reg.group('slug')] = dict()
if not reg.group('slug') in dic_result:
dic_result[reg.group('slug')] = dict()

if 'items' in DicResult[reg.group('slug')]:
DicResult[reg.group('slug')]['items'].append((int(reg.group('id')), value))
if 'items' in dic_result[reg.group('slug')]:
dic_result[reg.group('slug')]['items'].append((int(reg.group('id')), value))
else:
DicResult[reg.group('slug')]['items'] = [(int(reg.group('id')), value)]
dic_result[reg.group('slug')]['items'] = [(int(reg.group('id')), value)]
elif regN:
if not DicResult.has_key(regN.group('slug')):
DicResult[regN.group('slug')] = dict()
if not regN.group('slug') in dic_result:
dic_result[regN.group('slug')] = dict()

if DicResult[regN.group('slug')].has_key('items'):
DicResult[regN.group('slug')]['items'].append(('id', value))
if 'items' in dic_result[regN.group('slug')]:
dic_result[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))
dic_result[regN.group('slug')]['items'] = [('id', value)]
list_changes.append(('add', 0, dic_result[regN.group('slug')]['title'], value))
elif regT:
if not DicResult.has_key(regT.group('slug')):
DicResult[regT.group('slug')] = dict()
DicResult[regT.group('slug')]['title'] = value
if not regT.group('slug') in dic_result:
dic_result[regT.group('slug')] = dict()
dic_result[regT.group('slug')]['title'] = value
else:
raise

for opt in DBSession.query(TiersOpt).all():
if opt.slug_entity_type in DicResult:
if opt.slug_entity_type in dic_result:
found = filter(lambda x, y: opt.uid == x,
DicResult[opt.slug_entity_type].get('items', []))
dic_result[opt.slug_entity_type].get('items', []))
if not found:
ListChanges.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype))
list_changes.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype))
else:
for tst in found:
# Check changes on Cat Name
if DicResult[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:
ListChanges.append(('changed', opt.uid,
DicResult[opt.slug_entity_type]['title'],
list_changes.append(('changed', opt.uid,
dic_result[opt.slug_entity_type]['title'],
tst[1]))
else:
ListChanges.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype))
list_changes.append(('remove', opt.uid, opt.entity_type, opt.entity_subtype))

# Do The change
for action, uid, entity, subentity in ListChanges:
for action, uid, entity, sub_entity in list_changes:
if action == "changed":
opt = TiersOpt.by_id(uid)
opt.entity_type = entity
opt.entity_subtype = subentity
opt.entity_subtype = sub_entity
elif action == "remove":
opt = TiersOpt.by_id(uid)
DBSession.delete(opt)
elif action == "add":
opt = TiersOpt()
opt.entity_type = entity
opt.entity_subtype = subentity
opt.entity_subtype = sub_entity
DBSession.add(opt)

MainTab = {'programme': '', 'presse': '', 'plan': '', 'participer': '',


Loading…
取消
儲存