Пример #1
0
 def clean_File(self):
     file = clean_file_default(self)
     if get_ext(file.name) not in self.filetype.get_allowed_extensions():
         raise ValidationError(
             'This file extension is not allowed. Allowed extensions: ' +
             print_list(self.filetype.get_allowed_extensions()))
     return file
Пример #2
0
def clean_publicfile_default(self):
    file = clean_file_default(self)
    if get_ext(file.name) not in settings.ALLOWED_PUBLIC_FILES:
        raise ValidationError(
            'This file type is not allowed. Allowed types: ' +
            print_list(settings.ALLOWED_PUBLIC_FILES))
    return file
Пример #3
0
def clean_attachment_default(self):
    """
    Check whether an attachment is valid

    :param self:
    :return:
    """
    file = clean_file_default(self)
    # this check is done both here and in the model
    if get_ext(file.name) not in settings.ALLOWED_PROJECT_ATTACHMENTS:
        raise ValidationError(
            'This file type is not allowed. Allowed types: ' +
            print_list(settings.ALLOWED_PROJECT_ATTACHMENTS))
    return file
Пример #4
0
def clean_studentfile_default(self):
    """
    Clean function for studentfile form. Checks if the extension is in the allowed extensions for this type file.

    :param self:
    :return:
    """
    try:
        ftype = get_object_or_404(FileType, pk=self.data['Type'])
    except:
        raise ValidationError(
            'Please select a file type from the drop-down list.')
    file = clean_file_default(self)
    if get_ext(file.name) not in ftype.get_allowed_extensions():
        raise ValidationError(
            'This file extension is not allowed. Allowed extensions: ' +
            print_list(ftype.get_allowed_extensions()))
    return file
Пример #5
0
def clean_image_default(self):
    """
    Check whether an uploaded image is valid and has right dimensions

    :param self:
    :return:
    """
    picture = clean_file_default(self)

    # this check is done both here and in the model, needed to prevent wrong files entering get_image_dimensions()
    if get_ext(picture.name) not in settings.ALLOWED_PROJECT_IMAGES:
        raise ValidationError(
            'This file type is not allowed. Allowed types: ' +
            print_list(settings.ALLOWED_PROJECT_IMAGES))

    w, h = get_image_dimensions(picture)
    if w < minw or h < minh:
        raise ValidationError(
            "The image is too small, it has to be at least " + str(minw) +
            "px by " + str(minh) + "px and is only " + str(w) + "px by " +
            str(h) + "px.")

    return picture