def record_attendances_view(context, request): """ Record attendances for the given context (workshop) Special Note : Since we need a special layout in the form (with tabs and lines with the username as header, we can't render it with deform. We use peppercorn's parser and we build an appropriate form in the template """ schema = AttendanceSchema().bind(request=request) if 'submit' in request.params: controls = request.params.items() values = peppercorn.parse(controls) try: appstruct = schema.deserialize(values) except colander.Invalid as e: log.error(u"Error while validating workshop attendance") log.error(e) else: for datas in appstruct['attendances']: account_id = datas['account_id'] timeslot_id = datas['timeslot_id'] obj = Attendance.get((account_id, timeslot_id)) obj.status = datas['status'] request.dbsession.merge(obj) request.session.flash(u"L'émargement a bien été enregistré") url = request.route_path( 'workshop', id=context.id, _query=dict(action="edit"), ) return HTTPFound(url)