Browse Source

[CLEAN] Don't need to be that strict with 80 char per line it doesn't make the code more readable, 120 is perfectly fine nowdays.

[CLEAN] use anonymous variable _ when unpacking tuple.
[CLEAN] use free_space instead of len(s)
pull/28/head
Thibault Francois 7 years ago
parent
commit
07d255b4f1
  1. 19
      beesdoo_website_shift/controllers/main.py

19
beesdoo_website_shift/controllers/main.py

@ -20,26 +20,23 @@ class ShiftPortalController(http.Controller):
# Grouby task_template_id, if no task_template_id is specified # Grouby task_template_id, if no task_template_id is specified
# then group by start_time # then group by start_time
groupby_func = lambda s: (s.task_template_id,
s.start_time,
s.task_type_id)
groupby_func = lambda s: (s.task_template_id, s.start_time, s.task_type_id)
groupby_iter = groupby(shifts, groupby_func) groupby_iter = groupby(shifts, groupby_func)
shifts_and_count = [] shifts_and_count = []
for (keys, grouped_shifts) in groupby_iter: for (keys, grouped_shifts) in groupby_iter:
(task_template, start_time, task_type) = keys
(task_template, _, _) = keys
s = list(grouped_shifts) s = list(grouped_shifts)
free_space = len(s) free_space = len(s)
# Among shifts with at least 5 worker max, shows only shifts # Among shifts with at least 5 worker max, shows only shifts
# where there is at least two free spaces # where there is at least two free spaces
if task_template.worker_nb > 5 and len(s) >= 2:
if task_template.worker_nb > 5 and free_space >= 2:
shifts_and_count.append([free_space, s[0]]) shifts_and_count.append([free_space, s[0]])
# Show available shifts if there is less than 5 worker max # Show available shifts if there is less than 5 worker max
if task_template.worker_nb <= 5: if task_template.worker_nb <= 5:
shifts_and_count.append([free_space, s[0]]) shifts_and_count.append([free_space, s[0]])
return request.render(
'beesdoo_website_shift.shift_template',
return request.render('beesdoo_website_shift.shift_template',
{ {
'shift_templates': shifts_and_count 'shift_templates': shifts_and_count
} }
@ -49,13 +46,9 @@ class ShiftPortalController(http.Controller):
def shift_template_regular_worker(self, **kwargs): def shift_template_regular_worker(self, **kwargs):
# Get all the task template # Get all the task template
template = request.env['beesdoo.shift.template'] template = request.env['beesdoo.shift.template']
task_templates = template.sudo().search(
[],
order="planning_id, day_nb_id, start_time"
)
task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time")
return request.render(
'beesdoo_website_shift.task_template',
return request.render('beesdoo_website_shift.task_template',
{ {
'task_templates': task_templates, 'task_templates': task_templates,
'float_to_time': float_to_time 'float_to_time': float_to_time

Loading…
Cancel
Save