server/general: report bad field names to user

This commit is contained in:
rr- 2016-06-11 11:15:47 +02:00
parent b13f9dcb68
commit 8c952c08d0
1 changed files with 5 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import hashlib
import re import re
import tempfile import tempfile
from contextlib import contextmanager from contextlib import contextmanager
from szurubooru.errors import ValidationError from szurubooru import errors
def get_serialization_options(ctx): def get_serialization_options(ctx):
return ctx.get_param_as_list('_fields', required=False, default=None) return ctx.get_param_as_list('_fields', required=False, default=None)
@ -20,7 +20,8 @@ def serialize_entity(entity, field_factories, options):
factory = field_factories[key] factory = field_factories[key]
ret[key] = factory() ret[key] = factory()
except KeyError: except KeyError:
pass raise errors.ValidationError('Invalid key: %r. Valid keys: %r.' % (
key, list(sorted(field_factories.keys()))))
return ret return ret
@contextmanager @contextmanager
@ -70,7 +71,7 @@ def parse_time_range(value, timezone=datetime.timezone(datetime.timedelta())):
value = value.lower() value = value.lower()
if not value: if not value:
raise ValidationError('Empty date format.') raise errors.ValidationError('Empty date format.')
if value == 'today': if value == 'today':
now = datetime.datetime.now(tz=timezone) now = datetime.datetime.now(tz=timezone)
@ -110,7 +111,7 @@ def parse_time_range(value, timezone=datetime.timezone(datetime.timedelta())):
datetime.datetime(year, month, day), datetime.datetime(year, month, day),
datetime.datetime(year, month, day + 1) - one_second) datetime.datetime(year, month, day + 1) - one_second)
raise ValidationError('Invalid date format: %r.' % value) raise errors.ValidationError('Invalid date format: %r.' % value)
def icase_unique(source): def icase_unique(source):
target = [] target = []