def get_tariff_viewing_contexts(self, data, session, curs=None): ordering_params = data.get('ordering_params', ['view_order']) t_f = TariffViewingContextFilter(session, data['filter_params'], data['paging_params'], ordering_params) ts, total = t_f.filter_counted(curs) def viewer(t_v_ctx): res = t_v_ctx.to_dict() res = mapping.objects.deserialize_field(res, 'serialized_context', 'context') res['context'] = self._expand_context(res['context']) res.pop('environment_id') return res return response_ok(tariff_contexts=self.objects_info(ts, viewer), total=total)
def modify_tariff_viewing_context(self, data, session, curs=None): f = TariffViewingContextFilter(session, {'id': data.get('id')}, {}, None) loader = partial(f.filter_one_obj, curs, for_update=True) if 'new_tariff_id' in data: t_id = data.get('new_tariff_id') t_f = TariffFilter(session, {'id': t_id}, {}, None) t_f.filter_one_obj(curs) if 'new_context' in data: data['new_context'] = self._collapse_context(data['new_context']) data = mapping.objects.serialize_field(data, 'new_context', 'new_serialized_context') self.update_obj(curs, data, loader) return response_ok()
def delete_tariff_viewing_context(self, data, session, curs=None): f = TariffViewingContextFilter(session, {'id': data['id']}, {}, None) mapping.delete(curs, f.filter_one_obj(curs)) return response_ok()