X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..a8ffbcfa8eed3032af4a7accec640a3cc424c842:/src/catalogue/models/image.py?ds=inline diff --git a/src/catalogue/models/image.py b/src/catalogue/models/image.py old mode 100755 new mode 100644 index 646dd0ae..becc308b --- a/src/catalogue/models/image.py +++ b/src/catalogue/models/image.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -7,10 +5,10 @@ from django.conf import settings from django.contrib.sites.models import Site from django.db import models from django.template.loader import render_to_string +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from catalogue.helpers import cached_in_field from catalogue.models import Project -from catalogue.tasks import refresh_instance from dvcs import models as dvcs_models @@ -22,10 +20,9 @@ class Image(dvcs_models.Document): title = models.CharField(_('title'), max_length=255, blank=True) slug = models.SlugField(_('slug'), unique=True) public = models.BooleanField(_('public'), default=True, db_index=True) - project = models.ForeignKey(Project, null=True, blank=True) + project = models.ForeignKey(Project, models.SET_NULL, null=True, blank=True) # cache - _short_html = models.TextField(null=True, blank=True, editable=False) _new_publishable = models.NullBooleanField(editable=False) _published = models.NullBooleanField(editable=False) _changed = models.NullBooleanField(editable=False) @@ -40,12 +37,11 @@ class Image(dvcs_models.Document): # Representing # ============ - def __unicode__(self): + def __str__(self): return self.title - @models.permalink def get_absolute_url(self): - return ("catalogue_image", [self.slug]) + return reverse("catalogue_image", args=[self.slug]) def correct_about(self): return ["http://%s%s" % ( @@ -83,11 +79,11 @@ class Image(dvcs_models.Document): picture = WLPicture.from_bytes( picture_xml.encode('utf-8'), image_store=SelfImageStore) - except ParseError, e: + except ParseError as e: raise AssertionError(_('Invalid XML') + ': ' + str(e)) except NoDublinCore: raise AssertionError(_('No Dublin Core found.')) - except ValidationError, e: + except ValidationError as e: raise AssertionError(_('Invalid Dublin Core') + ': ' + str(e)) valid_about = self.correct_about() @@ -97,13 +93,13 @@ class Image(dvcs_models.Document): def publishable_error(self): try: return self.assert_publishable() - except AssertionError, e: + except AssertionError as e: return e else: return None def accessible(self, request): - return self.public or request.user.is_authenticated() + return self.public or request.user.is_authenticated def is_new_publishable(self): change = self.publishable() @@ -122,33 +118,13 @@ class Image(dvcs_models.Document): return not self.head.publishable changed = cached_in_field('_changed')(is_changed) - @cached_in_field('_short_html') - def short_html(self): - return render_to_string( - 'catalogue/image_short.html', {'image': self}) - - def refresh(self): - """This should be done offline.""" - self.short_html - self.single - self.new_publishable - self.published - def touch(self): update = { "_changed": self.is_changed(), - "_short_html": None, "_new_publishable": self.is_new_publishable(), "_published": self.is_published(), } Image.objects.filter(pk=self.pk).update(**update) - refresh_instance(self) - - def refresh(self): - """This should be done offline.""" - self.changed - self.short_html - # Publishing # ==========