OpenSlides/openslides/mediafile/forms.py

37 lines
1020 B
Python
Raw Normal View History

# -*- 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.
"""
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.
"""
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.
"""
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)