Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
USEFUL_LINKS_SCHEMA, PHOTOS_SCHEMA, THEME_SCHEMA, RECOMMENDATION_LIST_CONTENT_SCHEMA, )
# Format checker to use with jsonschemas to make sure errors are thrown
""" Class to hold the similar logic between the classes that are used validate JSON """
# Value to override
self.schema, resolver=DEFINITIONS_RESOLVER, format_checker=FORMAT_CHECKER )
""" Perform validation
:param value: Value to validate :type value: list, dict :raises: ValidationErrort """
""" Validator to be used on a JSON field that is supposed to store Useful links """
""" Validator to be used on a JSON field that is supposed to store photos """
""" Validator to be used on a JSON field that is supposed to store the theme data """
""" Validator to be used on a JSON field that is supposed to store recommendation list content """
""" Validator to check that all the universities exist in the json of recommendation list """
def get_universities_ids_from_content(content): univ_ids = set() for block in content: if block["type"] == "univ-block": univ_ids.add(block["content"]["university"]) return univ_ids
univ_ids_in_content = self.get_universities_ids_from_content(value) all_universities_ids = set( map(lambda univ: univ.pk, self.University.objects.all()) )
for univ_id in univ_ids_in_content: if univ_id not in all_universities_ids: raise ValidationError("Unrecognized university id {}".format(univ_id))
""" Validator to be used to check if a string ends with .(ext) from a list of allowed extensions. """
""" :param allowed_extensions: :type allowed_extensions: iterable """
""" Perform validation
:param string: Value to validate :type string: str :raises: ValidationError """ "The file you submitted has an unauthorized extension" ) raise ValidationError("File extension not recognized")
""" Validator to be check that a file is a valid image. Can't be tricked, definitely bulletproof. """
# Plus svg
else:
def is_svg(f): """ Check if the provided file is svg """ |