2013-02-16 16:19:20 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from django.forms import ModelForm
|
|
|
|
|
|
|
|
from openslides.utils.forms import CssClassMixin
|
|
|
|
|
|
|
|
from .models import Mediafile
|
|
|
|
|
|
|
|
|
|
|
|
class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
|
2013-03-19 00:51:52 +01:00
|
|
|
"""
|
|
|
|
Form to create a media file. This form is only used by normal users,
|
|
|
|
not by managers.
|
2013-02-16 16:19:20 +01:00
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Mediafile
|
|
|
|
exclude = ('uploader',)
|
|
|
|
|
|
|
|
|
|
|
|
class MediafileUpdateForm(CssClassMixin, ModelForm):
|
2013-03-19 00:51:52 +01:00
|
|
|
"""
|
|
|
|
Form to edit mediafile entries. This form is only for managers to update
|
|
|
|
the mediafile entry.
|
2013-02-16 16:19:20 +01:00
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Mediafile
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
2013-03-19 00:51:52 +01:00
|
|
|
"""
|
|
|
|
Method to save the form. Here the overwrite is to delete old files.
|
2013-02-16 16:19:20 +01:00
|
|
|
"""
|
|
|
|
if not self.instance.pk is None:
|
|
|
|
old_file = Mediafile.objects.get(pk=self.instance.pk).mediafile
|
|
|
|
if not old_file == self.instance.mediafile:
|
|
|
|
old_file.delete()
|
|
|
|
return super(MediafileUpdateForm, self).save(*args, **kwargs)
|