def _sort_items(self): section = SurveySection.find_one(survey=self.survey, id=request.form['section_id'], _eager=SurveySection.children) section_items = {x.id: x for x in section.children} item_ids = map(int, request.form.getlist('item_ids')) changed_section = None for position, item_id in enumerate(item_ids, 1): try: section_items[item_id].position = position except KeyError: # item is not in section, was probably moved item = SurveyItem.find_one( SurveyItem.survey == self.survey, SurveyItem.id == item_id, SurveyItem.type != SurveyItemType.section, _eager=SurveyItem.parent) changed_section = item.parent item.position = position item.parent = section logger.info('Item %s moved to section %s by %s', item, section, session.user) logger.info('Items in %s reordered by %s', section, session.user) if changed_section is not None: for position, item in enumerate(changed_section.children, 1): item.position = position
def _process_args(self): RHManageSurveysBase._process_args(self) self.section = SurveySection.find_one( SurveySection.id == request.view_args['section_id'], ~Survey.is_deleted, _join=SurveySection.survey, _eager=SurveySection.survey) self.survey = self.section.survey
def _checkParams(self, params): RHManageSurveysBase._checkParams(self, params) self.section = SurveySection.find_one( SurveySection.id == request.view_args['section_id'], ~Survey.is_deleted, _join=SurveySection.survey, _eager=SurveySection.survey) self.survey = self.section.survey
def _sort_items(self): section = SurveySection.find_one(survey=self.survey, id=request.form['section_id'], _eager=SurveySection.children) section_items = {x.id: x for x in section.children} item_ids = map(int, request.form.getlist('item_ids')) changed_section = None for position, item_id in enumerate(item_ids, 1): try: section_items[item_id].position = position except KeyError: # item is not in section, was probably moved item = SurveyItem.find_one(SurveyItem.survey == self.survey, SurveyItem.id == item_id, SurveyItem.type != SurveyItemType.section, _eager=SurveyItem.parent) changed_section = item.parent item.position = position item.parent = section logger.info('Item {} moved to section {} by {}'.format(item, section, session.user)) logger.info('Items in {} reordered by {}'.format(section, session.user)) if changed_section is not None: for position, item in enumerate(changed_section.children, 1): item.position = position
def _checkParams(self, params): RHManageSurveysBase._checkParams(self, params) self.section = SurveySection.find_one(SurveySection.id == request.view_args['section_id'], ~Survey.is_deleted, _join=SurveySection.survey, _eager=SurveySection.survey) self.survey = self.section.survey
def _process_args(self): RHManageSurveysBase._process_args(self) self.section = SurveySection.find_one(SurveySection.id == request.view_args['section_id'], ~Survey.is_deleted, _join=SurveySection.survey, _eager=SurveySection.survey) self.survey = self.section.survey