From 3a62c5b92b06d11331cb8aa9add47d22c32cae31 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 26 Aug 2013 23:55:44 +0200 Subject: 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 --- ishtar_common/forms_common.py | 21 +++- ishtar_common/models.py | 26 ++++- ishtar_common/templates/ishtar/sheet_person.html | 108 +++++++++++++++++++++ .../templates/ishtar/sheet_person_pdf.html | 18 ++++ .../templates/ishtar/sheet_person_window.html | 3 + ishtar_common/urls.py | 4 + ishtar_common/views.py | 41 +++++--- 7 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 ishtar_common/templates/ishtar/sheet_person.html create mode 100644 ishtar_common/templates/ishtar/sheet_person_pdf.html create mode 100644 ishtar_common/templates/ishtar/sheet_person_window.html (limited to 'ishtar_common') 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 %} +
{%trans "Export as:"%} {%trans "OpenOffice.org file"%}, {%trans "PDF file"%}
+ +

{% trans "Person"%}

+ +

{{item.name}}

+

{{item.surname}}

+{% if item.email %}

{{item.email}}

{% endif %} +

{{item.person_types_list}}

+{% if item.address %}

{{item.address}}

{% endif %} +{% if item.address_complement %}

{{item.address_complement}}

{% endif %} +{% if item.postal_code %}

{{item.postal_code}}

{% endif %} +{% if item.town %}

{{item.town}}

{% endif %} +{% if item.phone %}

{{item.phone}}

{% endif %} +{% if item.mobile_phone %}

{{item.mobile_phone}}

{% endif %} + + +{% if item.organization %}

{% trans "Associated organization"%}

+

{{item.organization}}

+{% if item.organization.address %}

{{item.organization.address}}

{% endif %} +{% if item.organization.address_complement %}

{{item.organization.address_complement}}

{% endif %} +{% if item.organization.postal_code %}

{{item.organization.postal_code}}

{% endif %} +{% if item.organization.town %}

{{item.organization.town}}

{% endif %} +{% if item.organization.phone %}

{{item.organization.phone}}

{% endif %} +{% if item.organization.mobile_phone %}

{{item.organization.mobile_phone}}

{% endif %} +{% endif %} + + + + + + + + + + + + + + + {% for operation in item.operation_responsability.all %} + + + + + + + + + + + {% empty %} + + {% endfor %} +
{%trans "Associated operations"%}
{% trans "Year" %}{% trans "Ref." %}Code Patriarche{% trans "Type" %}{% trans "In charge" %}{% trans "Start date" %}{% trans "Excavation end date" %} 
{{operation.year|default:""}}{{operation.operation_code|default:""}}{{operation.code_patriarche|default:""}}{{operation.operation_type}}{{operation.in_charge|default:""}}{{operation.start_date|default:""}}{{operation.excavation_end_date|default:""}}
{% trans "No operation associated to this person" %}
+ + + + + + + + + + + + + {% for file in item.file_responsability.all %} + + + + + + + + + + {% empty %} + + {% endfor %} +
{%trans "Associated archaelogical files"%}
{% trans "Ref." %}{% trans "Year" %}{% trans "Internal ref." %}{% trans "File type" %}Type de saisine{% trans "Towns" %} 
{{file.numeric_reference}}{{file.year}}{{file.internal_reference}}{{file.file_type}}{{file.saisine_type}}{{file.town_list}}
{% trans "No archaelogical file associated to this person" %}
+ + + + + + + + + + {% for author in item.author.all %} + {% for doc in author.related_sources %} + + + + + + + {% empty %} + + {% endfor %} + {% endfor %} +
{%trans "Documents"%}
{% trans "Year" %}{% trans "Title" %}{% trans "Type" %}{% trans "Link" %}
{{ doc.creation_date|date:"Y"}}{{ doc.title }}{{ doc.source_type }}{% if doc.associated_url %}{% trans "Link"%}{% endif %}
{% trans "No document associated to this person" %}
+ + +{% 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 %} + +{% endblock %} +{% block main_head %} +{{ block.super }} +
+Ishtar – {{APP_NAME}} – {{item}} +
+{% endblock %} +{%block head_sheet%}{%endblock%} +{%block main_foot%} +
+– – +
+ + +{%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.+)?$', 'get_person', + name='get-person'), + url(r'show-person/(?P.+)?/(?P.+)?$', + 'show_person', name='show-person'), url(r'autocomplete-town/?$', 'autocomplete_town', name='autocomplete-town'), url(r'new-author/(?P.+)?/$', 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): """ -- cgit v1.2.3