fnp
/
redakcja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update translation
[redakcja.git]
/
apps
/
catalogue
/
models
/
document.py
diff --git
a/apps/catalogue/models/document.py
b/apps/catalogue/models/document.py
index
5fa6242
..
ef5a5cc
100755
(executable)
--- a/
apps/catalogue/models/document.py
+++ b/
apps/catalogue/models/document.py
@@
-7,8
+7,10
@@
from __future__ import unicode_literals
from datetime import date
from django.conf import settings
from datetime import date
from django.conf import settings
+from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db import models
from django.template.loader import render_to_string
from django.db import models
from django.template.loader import render_to_string
+from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy as _
from dvcs.models import Ref
from organizations.models import Organization
from django.utils.translation import ugettext_lazy as _
from dvcs.models import Ref
from organizations.models import Organization
@@
-21,10
+23,12
@@
class Document(Ref):
owner_user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
owner_organization = models.ForeignKey(Organization, null=True)
owner_user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
owner_organization = models.ForeignKey(Organization, null=True)
- stage = models.CharField(_('stage'), max_length=128, blank=True, default=STAGES[0])
+ stage = models.CharField(_('stage'), max_length=128, blank=True, default=STAGES[0]
[0]
)
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name='assignments')
deleted = models.BooleanField(default=False)
assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name='assignments')
deleted = models.BooleanField(default=False)
- tags = models.ManyToManyField(Tag)
+ tags = models.ManyToManyField(Tag, blank=True)
+ # we need to know if it were ever published (for notifications)
+ published = models.BooleanField(default=False)
# Where to cache searchable stuff from metadata?
# Probably in some kind of search index.
# Where to cache searchable stuff from metadata?
# Probably in some kind of search index.
@@
-38,8
+42,7
@@
class Document(Ref):
def meta(self):
from lxml import etree
def meta(self):
from lxml import etree
- # Wrong! should be metadata
- d = {}
+ metadata = {}
data = self.materialize()
data = data.replace(u'\ufeff', '')
data = self.materialize()
data = data.replace(u'\ufeff', '')
@@
-53,8
+56,8
@@
class Document(Ref):
header = t.find('.//header')
if header is None:
header = etree.fromstring(data).find('.//{http://nowoczesnapolska.org.pl/sst#}header')
header = t.find('.//header')
if header is None:
header = etree.fromstring(data).find('.//{http://nowoczesnapolska.org.pl/sst#}header')
-
d
['title'] = getattr(header, 'text', ' ') or ' '
- #print 'meta', d['title']
+
metadata
['title'] = getattr(header, 'text', ' ') or ' '
+ #
print 'meta', d['title']
m = t.find('metadata')
if m is None:
m = t.find('metadata')
if m is None:
@@
-62,14
+65,16
@@
class Document(Ref):
if m is not None:
c = m.find('{http://purl.org/dc/elements/1.1/}relation.coverimage.url')
if c is not None:
if m is not None:
c = m.find('{http://purl.org/dc/elements/1.1/}relation.coverimage.url')
if c is not None:
-
d
['cover_url'] = c.text
+
metadata
['cover_url'] = c.text
c = m.find('{http://purl.org/dc/elements/1.1/}audience')
if c is not None:
c = m.find('{http://purl.org/dc/elements/1.1/}audience')
if c is not None:
-
d
['audience'] = c.text
+
metadata
['audience'] = c.text
- return
d
+ return
metadata
def can_edit(self, user):
def can_edit(self, user):
+ if user.is_superuser:
+ return True
if self.owner_user:
return self.owner_user == user
else:
if self.owner_user:
return self.owner_user == user
else:
@@
-84,10
+89,13
@@
class Document(Ref):
self.assigned_to = None
self.save()
self.assigned_to = None
self.save()
+ def stage_name(self):
+ return force_unicode(dict(STAGES)[self.stage]) if self.stage else None
+
def get_plan(self):
try:
plan = self.plan_set.get(stage=self.stage)
def get_plan(self):
try:
plan = self.plan_set.get(stage=self.stage)
- except:
+ except
(ObjectDoesNotExist, MultipleObjectsReturned)
:
return None
return plan
return None
return plan