OpenSlides/openslides/mediafile/models.py
Emanuel Schuetze abad75c129 A lot of template improvements and translation fixes
- Fixed agenda widget for special slide views (e.g. list of speakers, summary).
- Fixed back to motion(s) link
- Set icon for list of speakers widget.
- Fixed overlay widget layout of form elements.
- Added submenu with other config_pages to version.html.
- Updated completly DE translations, fixed EN strings.
- Coding style: Use correct ugettext and ugettext_lazy strings. Use "as _" for ugettext only.
Updated translation.
- Improved projector template (clock image, fixed facicon, added subtitle for list of speakers)
- Changed permission strings ('oneself'). Added check if group(pk=3) exists.
- Added event name and description to base template. Some minor template layout fixes.
- Use static subtile (no context var). Show last 2 old_speakers for projector.
- Cut old_speakers.
- Projektor template style changes (e.g. overlay list of speakers).
2013-04-24 10:38:03 +02:00

94 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.mediafile.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Models for the mediafile app.
:copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
import mimetypes
from django.db import models
from django.utils.translation import ugettext_lazy, ugettext_noop
from openslides.utils.person.models import PersonField
class Mediafile(models.Model):
"""
Class for uploaded files which can be delivered under a certain url.
"""
mediafile = models.FileField(upload_to='file', verbose_name=ugettext_lazy("File"))
"""
See https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
for more information.
"""
title = models.CharField(max_length=255, unique=True, verbose_name=ugettext_lazy("Title"))
"""A string representing the title of the file."""
uploader = PersonField(blank=True, verbose_name=ugettext_lazy("Uploaded by"))
"""A person the uploader of a file."""
timestamp = models.DateTimeField(auto_now_add=True)
"""A DateTimeField to save the upload date and time."""
filetype = models.CharField(max_length=255, editable=False)
"""A string used to show the type of the file."""
class Meta:
"""
Meta class for the mediafile model.
"""
ordering = ['title']
permissions = (
('can_see', ugettext_noop('Can see the list of files')),
('can_upload', ugettext_noop('Can upload files')),
('can_manage', ugettext_noop('Can manage files')),)
def __unicode__(self):
"""
Method for representation.
"""
return self.title
def save(self, *args, **kwargs):
"""
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:
self.filetype = ugettext_noop('unknown')
return super(Mediafile, self).save(*args, **kwargs)
@models.permalink
def get_absolute_url(self, link='update'):
"""
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.
"""
# TODO: Read http://stackoverflow.com/a/1094933 and think about it.
size = self.mediafile.size
if size < 1024:
return '< 1 kB'
if size >= 1024 * 1024:
mB = size / 1024 / 1024
return '%d MB' % mB
else:
kB = size / 1024
return '%d kB' % kB