Fixed error when a file was removed from filesystem. Fixed #1120.

This commit is contained in:
Norman Jäckel 2013-12-23 18:46:04 +01:00
parent 03fd7fd142
commit 1e52959f70
4 changed files with 20 additions and 11 deletions

View File

@ -8,6 +8,8 @@ Version 1.5.1 (unreleased)
========================== ==========================
[https://github.com/OpenSlides/OpenSlides/issues?milestone=15] [https://github.com/OpenSlides/OpenSlides/issues?milestone=15]
Files:
- Fixed error when a file was removed from filesystem.
Other: Other:
- Fixed http status code when requesting a non-existing static page using - Fixed http status code when requesting a non-existing static page using
Tordado web server. Tordado web server.

View File

@ -4,6 +4,7 @@ import mimetypes
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models from django.db import models
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy, ugettext_noop from django.utils.translation import ugettext_lazy, ugettext_noop
from openslides.projector.models import SlideMixin from openslides.projector.models import SlideMixin
@ -80,15 +81,20 @@ class Mediafile(SlideMixin, models.Model):
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. # TODO: Read http://stackoverflow.com/a/1094933 and think about it.
size = self.mediafile.size try:
if size < 1024: size = self.mediafile.size
return '< 1 kB' except OSError:
if size >= 1024 * 1024: size_string = _('unknown')
mB = size / 1024 / 1024
return '%d MB' % mB
else: else:
kB = size / 1024 if size < 1024:
return '%d kB' % kB size_string = '< 1 kB'
elif size >= 1024 * 1024:
mB = size / 1024 / 1024
size_string = '%d MB' % mB
else:
kB = size / 1024
size_string = '%d kB' % kB
return size_string

View File

@ -27,7 +27,7 @@
{% for mediafile in mediafile_list %} {% for mediafile in mediafile_list %}
<tr class="{% if mediafile.is_active_slide %}activeline{% endif %}"> <tr class="{% if mediafile.is_active_slide %}activeline{% endif %}">
<td><a href="{{ mediafile.mediafile.url }}">{{ mediafile }}</a></td> <td><a href="{{ mediafile.mediafile.url }}">{{ mediafile }}</a></td>
<td>{{ mediafile.filetype }}</td> <td>{% trans mediafile.filetype %}</td>
<td>{{ mediafile.get_filesize }}</td> <td>{{ mediafile.get_filesize }}</td>
<td>{{ mediafile.timestamp }}</td> <td>{{ mediafile.timestamp }}</td>
<td><a href="{{ mediafile.uploader|absolute_url }}">{{ mediafile.uploader }}</a></td> <td><a href="{{ mediafile.uploader|absolute_url }}">{{ mediafile.uploader }}</a></td>

View File

@ -195,4 +195,5 @@ class MediafileTest(TestCase):
bigfile.seek(1048575) bigfile.seek(1048575)
bigfile.write('0') bigfile.write('0')
self.assertEqual(object_4.get_filesize(), '1 MB') self.assertEqual(object_4.get_filesize(), '1 MB')
object_4.mediafile.delete() os.remove(mediafile_4_path)
self.assertEqual(object_4.get_filesize(), 'unknown')