fix pdf upload

This commit is contained in:
j 2016-11-30 11:36:29 +01:00
parent 14bfb1a451
commit 6ad112a3b8

View file

@ -162,15 +162,20 @@ class Document(models.Model):
s.extension = self.extension s.extension = self.extension
s.size = self.size s.size = self.size
s.matches = self.matches s.matches = self.matches
if self.extension == 'pdf': if self.extension == 'pdf':
s.dimensions = ox.sort_string('2') + ox.sort_string('%d' % self.pages) prefix = 2
value = self.pages
else: else:
if self.extension == 'html': if self.extension == 'html':
resolution_sort = self.dimensions prefix = 1
s.dimensions = ox.sort_string('1') + ox.sort_string('%d' % resolution_sort) value = self.dimensions
else: else:
resolution_sort = self.width * self.height prefix = 0
s.dimensions = ox.sort_string('0') + ox.sort_string('%d' % resolution_sort) value = self.width * self.height
if value < 0:
value = 0
s.dimensions = ox.sort_string('%d' % prefix) + ox.sort_string('%d' % value)
def sortNames(values): def sortNames(values):
sort_value = u'' sort_value = u''
@ -259,19 +264,23 @@ class Document(models.Model):
self.get_info() self.get_info()
if self.extension == 'html': if self.extension == 'html':
self.size = len(self.data.get('text', '')) self.size = len(self.data.get('text', ''))
is_ready = not self.uploading and (self.file or self.extension == 'html')
if self.id: if self.id:
self.update_sort() if is_ready:
self.update_find() self.update_sort()
self.update_facets() self.update_find()
self.update_facets()
new = False new = False
else: else:
new = True new = True
super(Document, self).save(*args, **kwargs) super(Document, self).save(*args, **kwargs)
if new: if new:
self.update_sort() if is_ready:
self.update_find() self.update_sort()
self.update_facets() self.update_find()
self.update_facets()
self.update_matches() self.update_matches()
def __unicode__(self): def __unicode__(self):