|
@@ -276,6 +276,20 @@ def list_view(request): |
|
|
@view_config(route_name='handle_task', renderer='jm2l:templates/Staff/tasks.mako') |
|
|
@view_config(route_name='handle_task', renderer='jm2l:templates/Staff/tasks.mako') |
|
|
def tasks(request): |
|
|
def tasks(request): |
|
|
task_id = request.matchdict.get('task_id') |
|
|
task_id = request.matchdict.get('task_id') |
|
|
|
|
|
# Convert the pole_id GET parameter to int or 0 |
|
|
|
|
|
try: |
|
|
|
|
|
pole_id = int(request.params.get('pole_id')) |
|
|
|
|
|
except (ValueError, TypeError): |
|
|
|
|
|
pole_id = 0 |
|
|
|
|
|
|
|
|
|
|
|
# Get areas from db |
|
|
|
|
|
Areas = DBSession.query(TasksArea.uid, TasksArea.name)\ |
|
|
|
|
|
.order_by('name').all() |
|
|
|
|
|
# Get users from db |
|
|
|
|
|
Users = DBSession.query(User)\ |
|
|
|
|
|
.filter(User.Staff==1)\ |
|
|
|
|
|
.order_by('nom').all() |
|
|
|
|
|
|
|
|
if task_id: |
|
|
if task_id: |
|
|
Task = Tasks.by_id(int(task_id)) |
|
|
Task = Tasks.by_id(int(task_id)) |
|
|
if not Task: |
|
|
if not Task: |
|
@@ -283,17 +297,16 @@ def tasks(request): |
|
|
form = EditStaffTasks(request.POST, Task, meta={'csrf_context': request.session}) |
|
|
form = EditStaffTasks(request.POST, Task, meta={'csrf_context': request.session}) |
|
|
else: |
|
|
else: |
|
|
Task = Tasks() |
|
|
Task = Tasks() |
|
|
|
|
|
# Check if the supplied pole_id is in the Areas' range |
|
|
|
|
|
Task.area_uid = pole_id if 1 < pole_id <= len(Areas) else 1 |
|
|
form = StaffTasks(request.POST, Task, meta={'csrf_context': request.session}) |
|
|
form = StaffTasks(request.POST, Task, meta={'csrf_context': request.session}) |
|
|
|
|
|
|
|
|
# Put some areas on form |
|
|
# Put some areas on form |
|
|
Areas = DBSession.query(TasksArea.uid, TasksArea.name)\ |
|
|
|
|
|
.order_by('name').all() |
|
|
|
|
|
form.area_uid.choices = Areas |
|
|
form.area_uid.choices = Areas |
|
|
# Put some users on form |
|
|
# Put some users on form |
|
|
Users = DBSession.query(User)\ |
|
|
|
|
|
.filter(User.Staff==1)\ |
|
|
|
|
|
.order_by('nom').all() |
|
|
|
|
|
form.closed_by.choices = [(u.uid, "%s %s" % (u.nom, u.prenom)) |
|
|
form.closed_by.choices = [(u.uid, "%s %s" % (u.nom, u.prenom)) |
|
|
for u in Users] |
|
|
for u in Users] |
|
|
|
|
|
|
|
|
form.due_date.type = "date" |
|
|
form.due_date.type = "date" |
|
|
if request.method == 'POST' and form.validate(): |
|
|
if request.method == 'POST' and form.validate(): |
|
|
form.populate_obj(Task) |
|
|
form.populate_obj(Task) |
|
@@ -304,7 +317,7 @@ def tasks(request): |
|
|
DBSession.add(Task) |
|
|
DBSession.add(Task) |
|
|
DBSession.flush() |
|
|
DBSession.flush() |
|
|
return HTTPFound(location=request.route_url('list_task')+"#"+slugify(Task.area.name)) |
|
|
return HTTPFound(location=request.route_url('list_task')+"#"+slugify(Task.area.name)) |
|
|
return {'form':form } |
|
|
|
|
|
|
|
|
return {'form':form, 'area':slugify(Areas[Task.area_uid-1].name)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name='handle_pole', renderer='jm2l:templates/Staff/pole.mako') |
|
|
@view_config(route_name='handle_pole', renderer='jm2l:templates/Staff/pole.mako') |
|
|