summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-08-26 23:55:44 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-08-26 23:55:44 +0200
commit3a62c5b92b06d11331cb8aa9add47d22c32cae31 (patch)
tree521a78f091de04ec15654218d7ec8aefd67bb0fa /ishtar_common/models.py
parentcc0f377471c838076b8f28f113ba8ddf6ba4740f (diff)
downloadIshtar-3a62c5b92b06d11331cb8aa9add47d22c32cae31.tar.bz2
Ishtar-3a62c5b92b06d11331cb8aa9add47d22c32cae31.zip
Change Person selection form - add a Person sheet (refs #425)
* change sheet creation to allow non historized object * add related names corresponding to person for operation, files and sources (through Author) * use a jqGrid associated to a form to select persons * create sheet templates for persons * add appropriate urls
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 738e86107..3f0cdc6b4 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -634,6 +634,8 @@ class Person(Address, OwnPerms) :
('Md', _(u'Mrs')),
('Dr', _(u'Doctor')),
)
+ TABLE_COLS = ('name', 'surname', 'email', 'person_types_list',
+ 'attached_to')
title = models.CharField(_(u"Title"), max_length=2, choices=TYPE)
surname = models.CharField(_(u"Surname"), max_length=20, blank=True,
null=True)
@@ -660,6 +662,11 @@ class Person(Address, OwnPerms) :
if getattr(self, attr)]
return u" ".join(values)
+ person_types_list_lbl = _(u"Types")
+ @property
+ def person_types_list(self):
+ return u", ".join([unicode(pt) for pt in self.person_types.all()])
+
def has_right(self, right_name):
if type(right_name) in (list, tuple):
return bool(
@@ -677,6 +684,13 @@ class Person(Address, OwnPerms) :
if getattr(self, attr)]
return u" ".join(values)
+ @property
+ def associated_filename(self):
+ values = [unicode(getattr(self, attr))
+ for attr in ('surname', 'name', 'attached_to')
+ if getattr(self, attr)]
+ return slugify(u"-".join(values))
+
class IshtarUser(User):
person = models.ForeignKey(Person, verbose_name=_(u"Person"), unique=True)
@@ -710,7 +724,8 @@ class AuthorType(GeneralType):
verbose_name_plural = _(u"Author types")
class Author(models.Model):
- person = models.ForeignKey(Person, verbose_name=_(u"Person"))
+ person = models.ForeignKey(Person, verbose_name=_(u"Person"),
+ related_name='author')
author_type = models.ForeignKey(AuthorType, verbose_name=_(u"Author type"))
class Meta:
@@ -720,6 +735,12 @@ class Author(models.Model):
def __unicode__(self):
return unicode(self.person) + settings.JOINT + unicode(self.author_type)
+ def related_sources(self):
+ return list(self.treatmentsource_related.all()) + \
+ list(self.operationsource_related.all()) + \
+ list(self.findsource_related.all()) + \
+ list(self.contextrecordsource_related.all())
+
class SourceType(GeneralType):
class Meta:
verbose_name = _(u"Source type")
@@ -728,7 +749,8 @@ class SourceType(GeneralType):
class Source(models.Model):
title = models.CharField(_(u"Title"), max_length=300)
source_type = models.ForeignKey(SourceType, verbose_name=_(u"Type"))
- authors = models.ManyToManyField(Author, verbose_name=_(u"Authors"))
+ authors = models.ManyToManyField(Author, verbose_name=_(u"Authors"),
+ related_name="%(class)s_related")
associated_url = models.URLField(verify_exists=False, blank=True, null=True,
verbose_name=_(u"Numerical ressource (web address)"))
receipt_date = models.DateField(blank=True, null=True,