Beispiel #1
0
    def clean(self):
        """
        Selected destination folder:
        - May only be '..' if subdir is not the top level
        - Must not be one of the items selected to be moved
        """
        cleaned_data = super(MoveItemsForm, self).clean()

        destination_folder = cleaned_data['destination_folder']
        selected_items = cleaned_data['items']
        subdir = cleaned_data['subdir']

        if subdir:
            validators.validate_filename_or_parent(destination_folder)
        else:
            validators.validate_filename(destination_folder)

        if destination_folder in selected_items:
            raise forms.ValidationError(
                format_html('Cannot move folder <i>{}</i> into itself',
                            destination_folder))

        self.dest_dir = os.path.join(self.file_dir, destination_folder)
        if not os.path.isdir(self.dest_dir):
            raise forms.ValidationError(
                format_html('Destination folder <i>{}</i> does not exist',
                            destination_folder))

        return cleaned_data
Beispiel #2
0
    def clean_file_field(self):
        """
        Check for file name, size limits and whether they are readable
        """
        files = self.files.getlist('file_field')

        for file in files:
            validators.validate_filename(file.name)

            # Special error
            if not file:
                raise forms.ValidationError(
                    'Could not read file: %(file_name)s',
                    params={'file_name': file.name})

        for file in files:
            if file.size > ActiveProject.INDIVIDUAL_FILE_SIZE_LIMIT:
                raise forms.ValidationError(
                    'File %(file_name)s is larger than the individual size limit: %(individual_size_limit)s',
                    code='exceed_individual_limit',
                    params={
                        'file_name':
                        file.name,
                        'individual_size_limit':
                        utility.readable_size(
                            ActiveProject.INDIVIDUAL_FILE_SIZE_LIMIT)
                    })

        if sum(
                f.size for f in files
        ) > self.project.core_project.storage_allowance - self.project.storage_used(
        ):
            raise forms.ValidationError(
                'Total upload volume exceeds remaining quota',
                code='exceed_remaining_quota',
            )
        return files