fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Librarian with fixed epub thank-you note
[wolnelektury.git]
/
apps
/
picture
/
models.py
diff --git
a/apps/picture/models.py
b/apps/picture/models.py
index
3cb1d89
..
c34b39a
100644
(file)
--- a/
apps/picture/models.py
+++ b/
apps/picture/models.py
@@
-6,11
+6,10
@@
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.utils.datastructures import SortedDict
from django.template.loader import render_to_string
from django.core.files.storage import FileSystemStorage
from django.utils.datastructures import SortedDict
from django.template.loader import render_to_string
-from django.core.cache import cache
+from django.core.cache import
get_
cache
from catalogue.utils import split_tags
from django.utils.safestring import mark_safe
from catalogue.utils import split_tags
from django.utils.safestring import mark_safe
-from librarian import dcparser
-from slughifi import slughifi
+from fnpdjango.utils.text.slughifi import slughifi
from django.utils.translation import ugettext_lazy as _
from newtagging import managers
from django.utils.translation import ugettext_lazy as _
from newtagging import managers
@@
-45,9
+44,6
@@
class Picture(models.Model):
verbose_name = _('picture')
verbose_name_plural = _('pictures')
verbose_name = _('picture')
verbose_name_plural = _('pictures')
- URLID_RE = r'[a-z0-9-]+'
- FILEID_RE = r'[a-z0-9-]+'
-
def save(self, force_insert=False, force_update=False, reset_short_html=True, **kwargs):
from sortify import sortify
def save(self, force_insert=False, force_update=False, reset_short_html=True, **kwargs):
from sortify import sortify
@@
-65,10
+61,7
@@
class Picture(models.Model):
@permalink
def get_absolute_url(self):
@permalink
def get_absolute_url(self):
- return ('picture.views.picture_detail', [self.urlid()])
-
- def urlid(self):
- return self.slug
+ return ('picture.views.picture_detail', [self.slug])
@classmethod
def from_xml_file(cls, xml_file, image_file=None, overwrite=False):
@classmethod
def from_xml_file(cls, xml_file, image_file=None, overwrite=False):
@@
-80,7
+73,7
@@
class Picture(models.Model):
"""
from sortify import sortify
from django.core.files import File
"""
from sortify import sortify
from django.core.files import File
- from librarian.picture import WLPicture
+ from librarian.picture import WLPicture
, ImageStore
close_xml_file = False
close_image_file = False
# class SimpleImageStore(object):
close_xml_file = False
close_image_file = False
# class SimpleImageStore(object):
@@
-98,7
+91,8
@@
class Picture(models.Model):
try:
# use librarian to parse meta-data
try:
# use librarian to parse meta-data
- picture_xml = WLPicture.from_file(xml_file)
+ picture_xml = WLPicture.from_file(xml_file,
+ image_store=ImageStore(picture_storage.path('images')))
# image_store=SimpleImageStore
picture, created = Picture.objects.get_or_create(slug=picture_xml.slug)
# image_store=SimpleImageStore
picture, created = Picture.objects.get_or_create(slug=picture_xml.slug)
@@
-154,7
+148,7
@@
class Picture(models.Model):
for tag in catalogue.models.Tag.objects.filter(category='author'):
pics_by_author[tag] = []
for tag in catalogue.models.Tag.objects.filter(category='author'):
pics_by_author[tag] = []
- for pic in pics:
+ for pic in pics
.iterator()
:
authors = list(pic.tags.filter(category='author'))
if authors:
for author in authors:
authors = list(pic.tags.filter(category='author'))
if authors:
for author in authors:
@@
-167,6
+161,8
@@
class Picture(models.Model):
@property
def info(self):
if not hasattr(self, '_info'):
@property
def info(self):
if not hasattr(self, '_info'):
+ from librarian import dcparser
+ from librarian import picture
info = dcparser.parse(self.xml_file.path, picture.PictureInfo)
self._info = info
return self._info
info = dcparser.parse(self.xml_file.path, picture.PictureInfo)
self._info = info
return self._info
@@
-176,12
+172,12
@@
class Picture(models.Model):
return
cache_key = "Picture.short_html/%d" % (self.id)
return
cache_key = "Picture.short_html/%d" % (self.id)
-
cache
.delete(cache_key)
+
get_cache('permanent')
.delete(cache_key)
def short_html(self):
if self.id:
cache_key = "Picture.short_html/%d" % (self.id)
def short_html(self):
if self.id:
cache_key = "Picture.short_html/%d" % (self.id)
- short_html =
cache
.get(cache_key)
+ short_html =
get_cache('permanent')
.get(cache_key)
else:
short_html = None
else:
short_html = None
@@
-195,5
+191,5
@@
class Picture(models.Model):
{'picture': self, 'tags': tags}))
if self.id:
{'picture': self, 'tags': tags}))
if self.id:
-
cache.set(cache_key, short_html, catalogue.models.CACHE_FOREVER
)
+
get_cache('permanent').set(cache_key, short_html
)
return mark_safe(short_html)
return mark_safe(short_html)