X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ffc2e047ca6712af8da3e13891b7ea16f184264a..143ac9b891b8223386830835709377166564af8f:/apps/catalogue/models/image.py?ds=sidebyside diff --git a/apps/catalogue/models/image.py b/apps/catalogue/models/image.py index 90a6e02a..8f044d3e 100755 --- a/apps/catalogue/models/image.py +++ b/apps/catalogue/models/image.py @@ -9,6 +9,7 @@ from django.db import models from django.template.loader import render_to_string 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 @@ -21,6 +22,7 @@ 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) # cache _short_html = models.TextField(null=True, blank=True, editable=False) @@ -46,10 +48,14 @@ class Image(dvcs_models.Document): return ("catalogue_image", [self.slug]) def correct_about(self): - return "http://%s%s" % ( + return ["http://%s%s" % ( Site.objects.get_current().domain, self.get_absolute_url() - ) + ), + "http://%s%s" % ( + 'obrazy.redakcja.wolnelektury.pl', + self.get_absolute_url() + )] # State & cache # ============= @@ -69,7 +75,9 @@ class Image(dvcs_models.Document): """Returns own file object. Ignores slug ad mime_type.""" return open(self.image.path) - picture_xml = self.publishable().materialize() + publishable = self.publishable() + assert publishable, _("There is no publishable revision") + picture_xml = publishable.materialize() try: picture = WLPicture.from_string(picture_xml.encode('utf-8'), @@ -82,8 +90,16 @@ class Image(dvcs_models.Document): raise AssertionError(_('Invalid Dublin Core') + ': ' + str(e)) valid_about = self.correct_about() - assert (picture.picture_info.about == valid_about, - _("rdf:about is not") + " " + valid_about) + assert picture.picture_info.about in valid_about, \ + _("rdf:about is not") + " " + valid_about[0] + + def publishable_error(self): + try: + return self.assert_publishable() + except AssertionError, e: + return e + else: + return None def accessible(self, request): return self.public or request.user.is_authenticated()