def read_boolean(self, boolean_input): if boolean_input.lower() == 'true': return True if boolean_input.lower() == 'false': return False raise exceptions.BadRequest('Invalid input for boolean: %r' % boolean_input)
def update(self, input_dict): if 'aborted' in input_dict: if input_dict['aborted'] != True: raise exceptions.BadRequest('"aborted" can only be set to true') query = models.HostQueueEntry.objects.filter(pk=self.instance.pk) models.AclGroup.check_abort_permissions(query) rpc_utils.check_abort_synchronous_jobs(query) self.instance.abort(thread_local.get_user())
def apply_selector(self, queryset, selector_name, value, comparison_type=None, is_inverse=False): if comparison_type is None: comparison_type = 'equals' _, constraint = self._selectors[selector_name] try: return constraint.apply_constraint(queryset, value, comparison_type, is_inverse) except ConstraintError as exc: raise exceptions.BadRequest('Selector %s: %s' % (selector_name, exc))
def update(self, input_dict): data = {'locked': input_dict.get('locked'), 'protection': input_dict.get('protection_level')} data = input_dict.remove_unspecified_fields(data) if 'protection' in data: data['protection'] = self._read_protection(data['protection']) self.instance.update_object(**data) if 'platform' in input_dict: label = self.resolve_link(input_dict['platform']) .instance if not label.platform: raise exceptions.BadRequest('Label %s is not a platform' % label.name) for label in self.instance.labels.filter(platform=True): self.instance.labels.remove(label) self.instance.labels.add(label)