def post(self, request): bug_ids = request.POST.get('bug_ids') if bug_ids: try: validate_comma_separated_integer_list(bug_ids) except ValidationError: return HttpResponseBadRequest() bug_ids = bug_ids.strip().split(',') bug_keys = ['bug:updated:' + bid for bid in bug_ids] updated = cache.get_many(bug_keys) if updated: return HttpResponse() return HttpResponse(status=204) # no content
def validate_checklist(value): err = None try: validate_comma_separated_integer_list(value) # Check all for item in value.split(","): obj = Game.objects.get(pk=item) except Game.DoesNotExist: raise ValidationError(str(item) + ' Not found in games') except ValidationError as exc: err = exc # Value match nothing, raise error if not err is None: raise err
def update_group(group, name): current = set(group.user_set.values_list("id", flat=True)) selected = request.POST[name] new = set() if selected: try: # TODO: Use ModelMultipleChoiceField validate_comma_separated_integer_list(selected) new = set(map(int, selected.split(','))) except ValidationError as e: log.error(e) return HttpResponseBadRequest(e) if current != new: group.user_set = User.objects.filter(pk__in=new) group.save()
def validate_hosts_ids(hosts_ids): validators.validate_comma_separated_integer_list(hosts_ids) hosts_ids = [int(x) for x in hosts_ids.split(',')] hosts_ids_set = Counter(set(hosts_ids)) hosts_ids = Counter(hosts_ids) if hosts_ids_set != hosts_ids: raise ValidationError(u'Some ids are repeated') real_hosts = Counter(models.Host.objects.filter(id__in=hosts_ids, ).values_list('id', flat=True)) diff = real_hosts - hosts_ids diff2 = hosts_ids - real_hosts if diff or diff2: f_diff = diff|diff2 raise ValidationError(u'Some ids do not exist: {}'.format(f_diff.keys()))
def validate_hosts_ids(hosts_ids): validators.validate_comma_separated_integer_list(hosts_ids) hosts_ids = [int(x) for x in hosts_ids.split(',')] hosts_ids_set = Counter(set(hosts_ids)) hosts_ids = Counter(hosts_ids) if hosts_ids_set != hosts_ids: raise ValidationError(u'Some ids are repeated') real_hosts = Counter( models.Host.objects.filter(id__in=hosts_ids, ).values_list('id', flat=True)) diff = real_hosts - hosts_ids diff2 = hosts_ids - real_hosts if diff or diff2: f_diff = diff | diff2 raise ValidationError(u'Some ids do not exist: {}'.format( f_diff.keys()))
def validate(self, value): if value == "": return validate_comma_separated_integer_list(value)
def validate(self, value): super().validate(value) validate_comma_separated_integer_list(value)