Insert whitespace. Fix docstrings.

This commit is contained in:
Norman Jäckel 2013-03-19 00:51:52 +01:00
parent d81c3bb1f8
commit 156acc451f
4 changed files with 51 additions and 42 deletions

View File

@ -18,10 +18,9 @@ from .models import Mediafile
class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
"""Form to create a media file.
This form is only used by normal users, not by managers.
"""
Form to create a media file. This form is only used by normal users,
not by managers.
"""
class Meta:
model = Mediafile
@ -29,19 +28,16 @@ class MediafileNormalUserCreateForm(CssClassMixin, ModelForm):
class MediafileUpdateForm(CssClassMixin, ModelForm):
"""Form to edit mediafile entries.
This form is only for managers to update the mediafile entry.
"""
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):
"""Method to save the form.
Here the overwrite is to delete old files.
"""
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

View File

@ -19,18 +19,16 @@ from openslides.utils.person.models import PersonField
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')
"""A FileField
Class for uploaded files which can be delivered under a certain url.
"""
mediafile = models.FileField(upload_to='file')
"""
See https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
for more information.
"""
title = models.CharField(max_length=255, unique=True)
"""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."""
class Meta:
"""Meta class for the mediafile model."""
"""
Meta class for the mediafile model.
"""
ordering = ['title']
permissions = (
('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')),)
def __unicode__(self):
"""Method for representation."""
"""
Method for representation.
"""
return self.title
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:
self.filetype = mimetypes.guess_type(self.mediafile.path)[0] or ugettext_noop('unknown')
else:
@ -65,14 +69,19 @@ class Mediafile(models.Model):
@models.permalink
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
return ('mediafile_update', [str(self.id)])
if link == 'delete':
return ('mediafile_delete', [str(self.id)])
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
if size < 1024:
return '< 1 kB'
@ -82,4 +91,3 @@ class Mediafile(models.Model):
else:
kB = size / 1024
return '%d kB' % kB
# TODO: Read http://stackoverflow.com/a/1094933 and think about it.

View File

@ -14,7 +14,7 @@ from django.conf.urls import url, patterns
from .models import Mediafile
from .views import (MediafileListView, MediafileCreateView,
MediafileUpdateView, MediafileDeleteView)
MediafileUpdateView, MediafileDeleteView)
urlpatterns = patterns('',

View File

@ -21,7 +21,9 @@ from .forms import MediafileNormalUserCreateForm, MediafileUpdateForm
class MediafileListView(ListView):
"""View to see a table of all uploaded files."""
"""
View to see a table of all uploaded files.
"""
model = Mediafile
def has_permission(self, request, *args, **kwargs):
@ -31,10 +33,9 @@ class MediafileListView(ListView):
class MediafileCreateView(CreateView):
"""View to upload a new file
A manager can also set the uploader, else the request user is set as uploader.
"""
View to upload a new file. A manager can also set the uploader, else
the request user is set as uploader.
"""
model = Mediafile
permission_required = 'mediafile.can_upload'
@ -45,19 +46,17 @@ class MediafileCreateView(CreateView):
if self.request.method == 'GET':
form_kwargs['initial'].update({'uploader': self.request.user.person_id})
if not self.request.user.has_perm('mediafile.can_manage'):
# Return our own ModelForm
# Returns our own ModelForm from .forms
return MediafileNormalUserCreateForm(**form_kwargs)
else:
# Return a ModelForm created by Django.
# Returns a ModelForm created by Django.
return form_class(**form_kwargs)
def manipulate_object(self, *args, **kwargs):
"""Method to handle the uploader
If a user has manager permissions, he has to set the uploader
in the given form field. Then this method only calls super.
Else it sets the requesting user as uploader.
"""
Method to handle the uploader. If a user has manager permissions,
he has to set the uploader in the given form field. Then this
method only calls super. Else it sets the requesting user as uploader.
"""
if not self.request.user.has_perm('mediafile.can_manage'):
self.object.uploader = self.request.user
@ -65,7 +64,9 @@ class MediafileCreateView(CreateView):
class MediafileUpdateView(UpdateView):
"""View to edit the entry of an uploaded file."""
"""
View to edit the entry of an uploaded file.
"""
model = Mediafile
permission_required = 'mediafile.can_manage'
form_class = MediafileUpdateForm
@ -78,7 +79,9 @@ class MediafileUpdateView(UpdateView):
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
permission_required = 'mediafile.can_manage'
success_url_name = 'mediafile_list'
@ -90,7 +93,9 @@ class MediafileDeleteView(DeleteView):
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/')
return Tab(
title=_('Media'),