Insert whitespace. Fix docstrings.
This commit is contained in:
parent
d81c3bb1f8
commit
156acc451f
@ -18,10 +18,9 @@ from .models import Mediafile
|
|||||||
|
|
||||||
|
|
||||||
class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
|
class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
|
||||||
"""Form to create a media file.
|
"""
|
||||||
|
Form to create a media file. This form is only used by normal users,
|
||||||
This form is only used by normal users, not by managers.
|
not by managers.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
@ -29,19 +28,16 @@ class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class MediafileUpdateForm(CssClassMixin, ModelForm):
|
class MediafileUpdateForm(CssClassMixin, ModelForm):
|
||||||
"""Form to edit mediafile entries.
|
"""
|
||||||
|
Form to edit mediafile entries. This form is only for managers to update
|
||||||
This form is only for managers to update the mediafile entry.
|
the mediafile entry.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Method to save the form.
|
"""
|
||||||
|
Method to save the form. Here the overwrite is to delete old files.
|
||||||
Here the overwrite is to delete old files.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.instance.pk is None:
|
if not self.instance.pk is None:
|
||||||
old_file = Mediafile.objects.get(pk=self.instance.pk).mediafile
|
old_file = Mediafile.objects.get(pk=self.instance.pk).mediafile
|
||||||
|
@ -19,18 +19,16 @@ from openslides.utils.person.models import PersonField
|
|||||||
|
|
||||||
|
|
||||||
class Mediafile(models.Model):
|
class Mediafile(models.Model):
|
||||||
"""The Mediafile class
|
|
||||||
|
|
||||||
Class for uploaded files which can be delivered under a certain url.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
mediafile = models.FileField(upload_to='file')
|
Class for uploaded files which can be delivered under a certain url.
|
||||||
"""A FileField
|
"""
|
||||||
|
|
||||||
|
mediafile = models.FileField(upload_to='file')
|
||||||
|
"""
|
||||||
See https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
|
See https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
|
||||||
for more information.
|
for more information.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
title = models.CharField(max_length=255, unique=True)
|
title = models.CharField(max_length=255, unique=True)
|
||||||
"""A string representing the title of the file."""
|
"""A string representing the title of the file."""
|
||||||
|
|
||||||
@ -44,7 +42,9 @@ class Mediafile(models.Model):
|
|||||||
"""A string used to show the type of the file."""
|
"""A string used to show the type of the file."""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class for the mediafile model."""
|
"""
|
||||||
|
Meta class for the mediafile model.
|
||||||
|
"""
|
||||||
ordering = ['title']
|
ordering = ['title']
|
||||||
permissions = (
|
permissions = (
|
||||||
('can_see', ugettext_noop('Can see the list of files')),
|
('can_see', ugettext_noop('Can see the list of files')),
|
||||||
@ -52,11 +52,15 @@ class Mediafile(models.Model):
|
|||||||
('can_manage', ugettext_noop('Can manage files')),)
|
('can_manage', ugettext_noop('Can manage files')),)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""Method for representation."""
|
"""
|
||||||
|
Method for representation.
|
||||||
|
"""
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Method to read filetype and then save to the database."""
|
"""
|
||||||
|
Method to read filetype and then save to the database.
|
||||||
|
"""
|
||||||
if self.mediafile:
|
if self.mediafile:
|
||||||
self.filetype = mimetypes.guess_type(self.mediafile.path)[0] or ugettext_noop('unknown')
|
self.filetype = mimetypes.guess_type(self.mediafile.path)[0] or ugettext_noop('unknown')
|
||||||
else:
|
else:
|
||||||
@ -65,14 +69,19 @@ class Mediafile(models.Model):
|
|||||||
|
|
||||||
@models.permalink
|
@models.permalink
|
||||||
def get_absolute_url(self, link='update'):
|
def get_absolute_url(self, link='update'):
|
||||||
"""Returns the URL to a mediafile. The link can be 'update' or 'delete'."""
|
"""
|
||||||
|
Returns the URL to a mediafile. The link can be 'update' or 'delete'.
|
||||||
|
"""
|
||||||
if link == 'update' or link == 'edit': # 'edit' ist only used until utils/views.py is fixed
|
if link == 'update' or link == 'edit': # 'edit' ist only used until utils/views.py is fixed
|
||||||
return ('mediafile_update', [str(self.id)])
|
return ('mediafile_update', [str(self.id)])
|
||||||
if link == 'delete':
|
if link == 'delete':
|
||||||
return ('mediafile_delete', [str(self.id)])
|
return ('mediafile_delete', [str(self.id)])
|
||||||
|
|
||||||
def get_filesize(self):
|
def get_filesize(self):
|
||||||
"""Transforms Bytes to Kilobytes or Megabytes. Returns the size as string."""
|
"""
|
||||||
|
Transforms Bytes to Kilobytes or Megabytes. Returns the size as string.
|
||||||
|
"""
|
||||||
|
# TODO: Read http://stackoverflow.com/a/1094933 and think about it.
|
||||||
size = self.mediafile.size
|
size = self.mediafile.size
|
||||||
if size < 1024:
|
if size < 1024:
|
||||||
return '< 1 kB'
|
return '< 1 kB'
|
||||||
@ -82,4 +91,3 @@ class Mediafile(models.Model):
|
|||||||
else:
|
else:
|
||||||
kB = size / 1024
|
kB = size / 1024
|
||||||
return '%d kB' % kB
|
return '%d kB' % kB
|
||||||
# TODO: Read http://stackoverflow.com/a/1094933 and think about it.
|
|
||||||
|
@ -21,7 +21,9 @@ from .forms import MediafileNormalUserCreateForm, MediafileUpdateForm
|
|||||||
|
|
||||||
|
|
||||||
class MediafileListView(ListView):
|
class MediafileListView(ListView):
|
||||||
"""View to see a table of all uploaded files."""
|
"""
|
||||||
|
View to see a table of all uploaded files.
|
||||||
|
"""
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
|
|
||||||
def has_permission(self, request, *args, **kwargs):
|
def has_permission(self, request, *args, **kwargs):
|
||||||
@ -31,10 +33,9 @@ class MediafileListView(ListView):
|
|||||||
|
|
||||||
|
|
||||||
class MediafileCreateView(CreateView):
|
class MediafileCreateView(CreateView):
|
||||||
"""View to upload a new file
|
"""
|
||||||
|
View to upload a new file. A manager can also set the uploader, else
|
||||||
A manager can also set the uploader, else the request user is set as uploader.
|
the request user is set as uploader.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
permission_required = 'mediafile.can_upload'
|
permission_required = 'mediafile.can_upload'
|
||||||
@ -45,19 +46,17 @@ class MediafileCreateView(CreateView):
|
|||||||
if self.request.method == 'GET':
|
if self.request.method == 'GET':
|
||||||
form_kwargs['initial'].update({'uploader': self.request.user.person_id})
|
form_kwargs['initial'].update({'uploader': self.request.user.person_id})
|
||||||
if not self.request.user.has_perm('mediafile.can_manage'):
|
if not self.request.user.has_perm('mediafile.can_manage'):
|
||||||
# Return our own ModelForm
|
# Returns our own ModelForm from .forms
|
||||||
return MediafileNormalUserCreateForm(**form_kwargs)
|
return MediafileNormalUserCreateForm(**form_kwargs)
|
||||||
else:
|
else:
|
||||||
# Return a ModelForm created by Django.
|
# Returns a ModelForm created by Django.
|
||||||
return form_class(**form_kwargs)
|
return form_class(**form_kwargs)
|
||||||
|
|
||||||
def manipulate_object(self, *args, **kwargs):
|
def manipulate_object(self, *args, **kwargs):
|
||||||
"""Method to handle the uploader
|
"""
|
||||||
|
Method to handle the uploader. If a user has manager permissions,
|
||||||
If a user has manager permissions, he has to set the uploader
|
he has to set the uploader in the given form field. Then this
|
||||||
in the given form field. Then this method only calls super.
|
method only calls super. Else it sets the requesting user as uploader.
|
||||||
Else it sets the requesting user as uploader.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.request.user.has_perm('mediafile.can_manage'):
|
if not self.request.user.has_perm('mediafile.can_manage'):
|
||||||
self.object.uploader = self.request.user
|
self.object.uploader = self.request.user
|
||||||
@ -65,7 +64,9 @@ class MediafileCreateView(CreateView):
|
|||||||
|
|
||||||
|
|
||||||
class MediafileUpdateView(UpdateView):
|
class MediafileUpdateView(UpdateView):
|
||||||
"""View to edit the entry of an uploaded file."""
|
"""
|
||||||
|
View to edit the entry of an uploaded file.
|
||||||
|
"""
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
permission_required = 'mediafile.can_manage'
|
permission_required = 'mediafile.can_manage'
|
||||||
form_class = MediafileUpdateForm
|
form_class = MediafileUpdateForm
|
||||||
@ -78,7 +79,9 @@ class MediafileUpdateView(UpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class MediafileDeleteView(DeleteView):
|
class MediafileDeleteView(DeleteView):
|
||||||
"""View to delete the entry of an uploaded file and the file itself."""
|
"""
|
||||||
|
View to delete the entry of an uploaded file and the file itself.
|
||||||
|
"""
|
||||||
model = Mediafile
|
model = Mediafile
|
||||||
permission_required = 'mediafile.can_manage'
|
permission_required = 'mediafile.can_manage'
|
||||||
success_url_name = 'mediafile_list'
|
success_url_name = 'mediafile_list'
|
||||||
@ -90,7 +93,9 @@ class MediafileDeleteView(DeleteView):
|
|||||||
|
|
||||||
|
|
||||||
def register_tab(request):
|
def register_tab(request):
|
||||||
"""Inserts a new Tab to the views for files."""
|
"""
|
||||||
|
Inserts a new Tab to the views for files.
|
||||||
|
"""
|
||||||
selected = request.path.startswith('/mediafile/')
|
selected = request.path.startswith('/mediafile/')
|
||||||
return Tab(
|
return Tab(
|
||||||
title=_('Media'),
|
title=_('Media'),
|
||||||
|
Loading…
Reference in New Issue
Block a user