Esempio n. 1
0
    def test_extra_methodes(self):
        default_storage.mkdir('test_directory')
        self.assertTrue(default_storage.exists('test_directory'))

        default_storage.mv('test_directory', 'moved_directory')
        self.assertTrue(default_storage.exists('moved_directory'))

        default_storage.delete('moved_directory')
        self.assertFalse(default_storage.exists('moved_directory'))
Esempio n. 2
0
    def test_extra_methodes(self):
        default_storage.mkdir('test_directory')
        self.assertTrue(default_storage.exists('test_directory'))

        default_storage.mv('test_directory', 'moved_directory')
        self.assertTrue(default_storage.exists('moved_directory'))

        default_storage.delete('moved_directory')
        self.assertFalse(default_storage.exists('moved_directory'))
Esempio n. 3
0
    def formset_valid(self, formset):
        path = self.get_path()
        for form in formset:
            old_path = os.path.join(path, form.cleaned_data['old_name'])
            if form.cleaned_data['DELETE']:
                default_storage.delete(old_path)
            else:
                new_path = os.path.join(path, form.cleaned_data['new_name'])
                if old_path != new_path:
                    try:
                        default_storage.mv(old_path, new_path)
                    except (SuspiciousOperation, OSError) as e:
                        messages.error(self.request,
                                       _('Error in "%(path)s": %(error)s')
                                       % {'path': old_path, 'error': e})

        return super(UpdateDirectoryView, self).formset_valid(formset)
Esempio n. 4
0
 def test_update_directory(self):
     default_storage.save('test_file2', 'content\n')
     default_storage.mkdir('test_dir')
     response = self.c.post('/edit/',
                            {'form-TOTAL_FORMS': 3,
                             'form-INITIAL_FORMS': 3,
                             'form-0-old_name': 'test_file1.txt',
                             'form-0-new_name': 'test_file1.renamed',
                             'form-1-old_name': 'test_file2',
                             'form-1-new_name': 'test_file2',
                             'form-1-DELETE': True,
                             'form-2-old_name': 'test_dir',
                             'form-2-new_name': 'test_dir',
                             'form-2-DELETE': True})
     self.assertEqual(response.status_code, 302)
     self.assertFalse(default_storage.exists('test_file2'))
     self.assertFalse(default_storage.exists('test_file1.txt'))
     self.assertFalse(default_storage.exists('test_dir'))
     self.assertTrue(default_storage.exists('test_file1.renamed'))
     default_storage.mv('test_file1.renamed', 'test_file1.txt')
Esempio n. 5
0
    def formset_valid(self, formset):
        path = self.get_path()
        for form in formset:
            old_path = os.path.join(path, form.cleaned_data['old_name'])
            if form.cleaned_data['DELETE']:
                default_storage.delete(old_path)
            else:
                new_path = os.path.join(path, form.cleaned_data['new_name'])
                if old_path != new_path:
                    try:
                        default_storage.mv(old_path, new_path)
                    except (SuspiciousOperation, OSError) as e:
                        messages.error(
                            self.request,
                            _('Error in "%(path)s": %(error)s') % {
                                'path': old_path,
                                'error': e
                            })

        return super(UpdateDirectoryView, self).formset_valid(formset)