summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_files/models.py6
-rw-r--r--archaeological_operations/models.py5
-rw-r--r--ishtar_common/forms_common.py21
-rw-r--r--ishtar_common/models.py26
-rw-r--r--ishtar_common/templates/ishtar/sheet_person.html108
-rw-r--r--ishtar_common/templates/ishtar/sheet_person_pdf.html18
-rw-r--r--ishtar_common/templates/ishtar/sheet_person_window.html3
-rw-r--r--ishtar_common/urls.py4
-rw-r--r--ishtar_common/views.py41
9 files changed, 209 insertions, 23 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 7b7a7d9b5..49b9086d0 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -68,7 +68,7 @@ class File(BaseHistorizedItem, OwnPerms):
null=True, max_length=60, unique=True)
name = models.CharField(_(u"Name"), max_length=100, blank=True, null=True)
file_type = models.ForeignKey(FileType, verbose_name=_(u"File type"))
- in_charge = models.ForeignKey(Person, related_name='+',
+ in_charge = models.ForeignKey(Person, related_name='file_responsability',
verbose_name=_(u"Person in charge"),
blank=True, null=True)
general_contractor = models.ForeignKey(Person, related_name='+',
@@ -180,6 +180,10 @@ class File(BaseHistorizedItem, OwnPerms):
def is_active(self):
return not bool(self.end_date)
+ @property
+ def town_list(self):
+ return u", ".join([unicode(tw) for tw in self.towns.all()])
+
def closing(self):
if self.is_active():
return
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 589d8d69e..6619bc72e 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -79,8 +79,9 @@ class Operation(BaseHistorizedItem, OwnPerms):
excavation_end_date = models.DateField(_(u"Excavation end date"), null=True,
blank=True)
end_date = models.DateField(_(u"Closing date"), null=True, blank=True)
- in_charge = models.ForeignKey(Person, related_name='+', null=True,
- blank=True, verbose_name=_(u"In charge"))
+ in_charge = models.ForeignKey(Person, blank=True, null=True,
+ verbose_name=_(u"In charge"),
+ related_name='operation_responsability')
year = models.IntegerField(_(u"Year"), null=True, blank=True)
operation_code = models.IntegerField(_(u"Operation code"), null=True,
blank=True)
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index db406aaa9..0a001883c 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -100,13 +100,28 @@ class OrganizationForm(forms.Form):
new_item.save()
return new_item
+class PersonSelect(TableSelect):
+ name = forms.CharField(label=_(u"Name"), max_length=30)
+ surname = forms.CharField(label=_(u"Surname"), max_length=20)
+ email = forms.CharField(label=_(u"Email"), max_length=40)
+ person_types = forms.ChoiceField(label=_(u"Type"), choices=[])
+ attached_to = forms.IntegerField(label=_("Organization"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-organization'),
+ associated_model=models.Organization),
+ validators=[models.valid_id(models.Organization)])
+
+ def __init__(self, *args, **kwargs):
+ super(PersonSelect, self).__init__(*args, **kwargs)
+ self.fields['person_types'].choices = models.PersonType.get_types()
+
class PersonFormSelection(forms.Form):
form_label = _(u"Person search")
associated_models = {'pk':models.Person}
currents = {'pk':models.Person}
- pk = forms.IntegerField(label=_("Person"),
- widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'),
- associated_model=models.Person),
+ pk = forms.IntegerField(label="",
+ widget=widgets.JQueryJqGrid(reverse_lazy('get-person'),
+ PersonSelect, models.Person),
validators=[models.valid_id(models.Person)])
class PersonForm(forms.Form):
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,
diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html
new file mode 100644
index 000000000..61b87654d
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_person.html
@@ -0,0 +1,108 @@
+{% extends "ishtar/sheet.html" %}
+{% load i18n %}
+{% block content %}
+<div class='tool'>{%trans "Export as:"%} <a href='{% url show-person item.pk "odt" %}'>{%trans "OpenOffice.org file"%}</a>, <a href='{% url show-person item.pk "pdf" %}'>{%trans "PDF file"%}</a></div>
+
+<h3>{% trans "Person"%}</h3>
+
+<p><label>{% trans "Name" %}</label> <span class='value'>{{item.name}}</span></p>
+<p><label>{% trans "Surname" %}</label> <span class='value'>{{item.surname}}</span></p>
+{% if item.email %}<p><label>{% trans "Email" %}</label> <span class='value'>{{item.email}}</span></p>{% endif %}
+<p><label>{% trans "Type(s)" %}</label> <span class='value'>{{item.person_types_list}}</span></p>
+{% if item.address %}<p><label>{% trans "Address" %}</label> <span class='value'>{{item.address}}</span></p> {% endif %}
+{% if item.address_complement %}<p><label>{% trans "Address complement" %}</label> <span class='value'>{{item.address_complement}}</span></p> {% endif %}
+{% if item.postal_code %}<p><label>{% trans "Postal code" %}</label> <span class='value'>{{item.postal_code}}</span></p> {% endif %}
+{% if item.town %}<p><label>{% trans "Town" %}</label> <span class='value'>{{item.town}}</span></p> {% endif %}
+{% if item.phone %}<p><label>{% trans "Phone" %}</label> <span class='value'>{{item.phone}}</span></p> {% endif %}
+{% if item.mobile_phone %}<p><label>{% trans "Mobile phone" %}</label> <span class='value'>{{item.mobile_phone}}</span></p> {% endif %}
+
+
+{% if item.organization %}<h3>{% trans "Associated organization"%}</h3>
+<p><label>{% trans "Name" %}</label> <span class='value'>{{item.organization}}</span></p>
+{% if item.organization.address %}<p><label>{% trans "Address" %}</label> <span class='value'>{{item.organization.address}}</span></p> {% endif %}
+{% if item.organization.address_complement %}<p><label>{% trans "Address complement" %}</label> <span class='value'>{{item.organization.address_complement}}</span></p> {% endif %}
+{% if item.organization.postal_code %}<p><label>{% trans "Postal code" %}</label> <span class='value'>{{item.organization.postal_code}}</span></p> {% endif %}
+{% if item.organization.town %}<p><label>{% trans "Town" %}</label> <span class='value'>{{item.organization.town}}</span></p> {% endif %}
+{% if item.organization.phone %}<p><label>{% trans "Phone" %}</label> <span class='value'>{{item.organization.phone}}</span></p> {% endif %}
+{% if item.organization.mobile_phone %}<p><label>{% trans "Mobile phone" %}</label> <span class='value'>{{item.organization.mobile_phone}}</span></p> {% endif %}
+{% endif %}
+
+
+<table>
+ <caption>{%trans "Associated operations"%}</caption>
+ <tr>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Ref." %}</th>
+ <th>Code Patriarche</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "In charge" %}</th>
+ <th>{% trans "Start date" %}</th>
+ <th>{% trans "Excavation end date" %}</th>
+ <th class='link'>&nbsp;</th>
+ </tr>
+ {% for operation in item.operation_responsability.all %}
+ <tr>
+ <td>{{operation.year|default:""}}</td>
+ <td>{{operation.operation_code|default:""}}</td>
+ <td>{{operation.code_patriarche|default:""}}</td>
+ <td class='string'>{{operation.operation_type}}</td>
+ <td class='string'>{{operation.in_charge|default:""}}</td>
+ <td>{{operation.start_date|default:""}}</td>
+ <td>{{operation.excavation_end_date|default:""}}</td>
+ <td class='link'><a href="#" onclick='load_window("{%url show-operation operation.pk ''%}")'>{% trans "Details" %}</a></td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="8" class='no_items'>{% trans "No operation associated to this person" %}</td></tr>
+ {% endfor %}
+</table>
+
+<table>
+ <caption>{%trans "Associated archaelogical files"%}</caption>
+ <tr>
+ <th>{% trans "Ref." %}</th>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Internal ref." %}</th>
+ <th>{% trans "File type" %}</th>
+ <th>Type de saisine</th>
+ <th>{% trans "Towns" %}</th>
+ <th class='link'>&nbsp;</th>
+ </tr>
+ {% for file in item.file_responsability.all %}
+ <tr>
+ <td>{{file.numeric_reference}}</td>
+ <td>{{file.year}}</td>
+ <td>{{file.internal_reference}}</td>
+ <td>{{file.file_type}}</td>
+ <td>{{file.saisine_type}}</td>
+ <td class='string'>{{file.town_list}}</td>
+ <td class='link'><a href="#" onclick='load_window("{%url show-file file.pk ''%}")'>{% trans "Details" %}</a></td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="8" class='no_items'>{% trans "No archaelogical file associated to this person" %}</td></tr>
+ {% endfor %}
+</table>
+
+<table>
+ <caption>{%trans "Documents"%}</caption>
+ <tr>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Title" %}</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "Link" %}</th>
+ </tr>
+ {% for author in item.author.all %}
+ {% for doc in author.related_sources %}
+ <tr>
+ <td class='string'>{{ doc.creation_date|date:"Y"}}</td>
+ <td class='string'>{{ doc.title }}</td>
+ <td class='string'>{{ doc.source_type }}</td>
+ <td class='string'>{% if doc.associated_url %}<a href='{{doc.associated_url}}'>{% trans "Link"%}</a>{% endif %}</td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4" class='no_items'>{% trans "No document associated to this person" %}</td></tr>
+ {% endfor %}
+ {% endfor %}
+</table>
+
+
+{% endblock %}
diff --git a/ishtar_common/templates/ishtar/sheet_person_pdf.html b/ishtar_common/templates/ishtar/sheet_person_pdf.html
new file mode 100644
index 000000000..1abc70243
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_person_pdf.html
@@ -0,0 +1,18 @@
+{% extends "ishtar/sheet_person.html" %}
+{% block header %}
+<link rel="stylesheet" href="{{STATIC_URL}}/media/style_basic.css" />
+{% endblock %}
+{% block main_head %}
+{{ block.super }}
+<div id="pdfheader">
+Ishtar &ndash; {{APP_NAME}} &ndash; {{item}}
+</div>
+{% endblock %}
+{%block head_sheet%}{%endblock%}
+{%block main_foot%}
+<div id="pdffooter">
+&ndash; <pdf:pagenumber/> &ndash;
+</div>
+</body>
+</html>
+{%endblock%}
diff --git a/ishtar_common/templates/ishtar/sheet_person_window.html b/ishtar_common/templates/ishtar/sheet_person_window.html
new file mode 100644
index 000000000..4e8d874cd
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_person_window.html
@@ -0,0 +1,3 @@
+{% extends "ishtar/sheet_person.html" %}
+{% block main_head %}{%endblock%}
+{% block main_foot %}{%endblock%}
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index 597327379..a11c989d5 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -56,6 +56,10 @@ urlpatterns += patterns('ishtar_common.views',
'new_person', name='new-person'),
url(r'autocomplete-person/([0-9_]+)?$', 'autocomplete_person',
name='autocomplete-person'),
+ url(r'get-person/(?P<type>.+)?$', 'get_person',
+ name='get-person'),
+ url(r'show-person/(?P<pk>.+)?/(?P<type>.+)?$',
+ 'show_person', name='show-person'),
url(r'autocomplete-town/?$', 'autocomplete_town',
name='autocomplete-town'),
url(r'new-author/(?P<parent_name>.+)?/$',
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 554fcc839..2278cf47a 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -374,21 +374,23 @@ def show_item(model, name):
date = 'date' in dct and dct.pop('date')
dct['window_id'] = "%s-%d-%s" % (name, item.pk,
datetime.datetime.now().strftime('%M%s'))
- if date:
- try:
- date = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%f')
- item = item.get_previous(date=date)
- assert item != None
- except (ValueError, AssertionError):
- return HttpResponse(None, mimetype='text/plain')
- dct['previous'] = item._previous
- dct['next'] = item._next
- else:
- historized = item.history.all()
- if historized:
- item.history_date = historized[0].history_date
- if len(historized) > 1:
- dct['previous'] = historized[1].history_date
+ if hasattr(item, 'history'):
+ if date:
+ try:
+ date = datetime.datetime.strptime(date,
+ '%Y-%m-%dT%H:%M:%S.%f')
+ item = item.get_previous(date=date)
+ assert item != None
+ except (ValueError, AssertionError):
+ return HttpResponse(None, mimetype='text/plain')
+ dct['previous'] = item._previous
+ dct['next'] = item._next
+ else:
+ historized = item.history.all()
+ if historized:
+ item.history_date = historized[0].history_date
+ if len(historized) > 1:
+ dct['previous'] = historized[1].history_date
dct['item'], dct['item_name'] = item, name
context_instance = RequestContext(request)
context_instance.update(dct)
@@ -545,6 +547,15 @@ def new_item(model, frm):
new_person = new_item(models.Person, PersonForm)
new_organization = new_item(models.Organization, OrganizationForm)
new_author = new_item(models.Author, AuthorForm)
+show_person = show_item(models.Person, 'person')
+get_person = get_item(models.Person,
+ 'get_person', 'person',
+ extra_request_keys={
+ 'name':'name__icontains',
+ 'surname':'surname__icontains',
+ 'attached_to':'attached_to__pk',
+ 'person_types':'person_types__pk__in',
+ },)
def action(request, action_slug, obj_id=None, *args, **kwargs):
"""