def test_sanitize_filename(self): self.assertEqual(sanitize_filename('foo.dat'), 'foo.dat') self.assertEqual(sanitize_filename('foo.bar.dat'), 'foobar.dat') self.assertEqual(sanitize_filename('foo bar.dat'), 'foo-bar.dat') self.assertEqual(sanitize_filename('ěščřž.dat'), 'escrz.dat') self.assertEqual(sanitize_filename(u'ěščřž.dat'), 'escrz.dat') self.assertEqual(sanitize_filename('.dat'), 'dat') self.assertEqual(sanitize_filename('foo.dať'), 'foo.dat')
def attachment_filename(instance, filename): return sanitize_filename(filename, 'files/courses')
def thesis_filename(instance, filename): return sanitize_filename(filename, 'thesis')
def test_path(self): self.assertEqual(sanitize_filename('foo.dat'), 'foo.dat') self.assertEqual(sanitize_filename('foo.dat', ''), 'foo.dat') self.assertEqual(sanitize_filename('foo.dat', 'files/courses/'), 'files/courses/foo.dat') self.assertEqual(sanitize_filename('foo.dat', 'files/courses'), 'files/courses/foo.dat')
def cv_filename(instance, filename): return sanitize_filename(filename, 'cv')
def image_filename(instance, filename): return sanitize_filename(filename, 'img/person')