From fd0a0165c3a06ecea377cc9a16ac2706b1dc9d40 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 3 Dec 2015 13:05:06 +0100 Subject: Better management of raw_names for search and windows --- ishtar_common/forms_common.py | 5 +++++ ishtar_common/models.py | 2 +- ishtar_common/templates/ishtar/sheet_person.html | 26 ++++++++++++------------ ishtar_common/views.py | 19 ++++++++++++----- 4 files changed, 33 insertions(+), 19 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 0e6a34b74..1ff9532e9 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -258,6 +258,7 @@ class SimplePersonForm(NewItemForm): validators=[name_validator]) name = forms.CharField(label=_(u"Name"), max_length=30, validators=[name_validator]) + raw_name = forms.CharField(label=_(u"Raw name"), max_length=255) address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, required=False) address_complement = forms.CharField(label=_(u"Address complement"), @@ -278,6 +279,10 @@ class SimplePersonForm(NewItemForm): associated_model=models.Organization, new=True), validators=[models.valid_id(models.Organization)], required=False) + def __init__(self, *args, **kwargs): + super(SimplePersonForm, self).__init__(*args, **kwargs) + self.fields['raw_name'].widget.attrs['readonly'] = True + class BasePersonForm(forms.ModelForm): class Meta: diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e762bf67f..72b41e0cf 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1864,7 +1864,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter): ('Md', _(u'Mrs')), ('Dr', _(u'Doctor')), ) - TABLE_COLS = ('name', 'surname', 'email', 'person_types_list', + TABLE_COLS = ('name', 'surname', 'raw_name', 'email', 'person_types_list', 'attached_to') title = models.CharField(_(u"Title"), max_length=100, choices=TYPE, blank=True, null=True) diff --git a/ishtar_common/templates/ishtar/sheet_person.html b/ishtar_common/templates/ishtar/sheet_person.html index b6bf99d56..38bc39c58 100644 --- a/ishtar_common/templates/ishtar/sheet_person.html +++ b/ishtar_common/templates/ishtar/sheet_person.html @@ -1,5 +1,5 @@ {% extends "ishtar/sheet.html" %} -{% load i18n %} +{% load i18n window_field %} {% block head_sheet %} {{block.super}} @@ -9,18 +9,18 @@ {% block content %}
{%trans "Export as:"%} {%trans "OpenOffice.org file"%}, {%trans "PDF file"%}
-

{{item.name}}

-

{{item.surname}}

-

{{ item.history_creator.ishtaruser.full_label }}

-{% 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 %} - +{% field "Name" item.name %} +{% field "Surname" item.surname %} +{% field "Raw name" item.raw_name %} +{% field "Created by" item.history_creator.ishtaruser.full_label %} +{% field "Email" item.email %} +{% field "Type(s)" item.person_types_list %} +{% field "Address" item.address %} +{% field "Address complement" item.address_complement %} +{% field "Postal code" item.postal_code %} +{% field "Town" item.town %} +{% field "Phone" item.phone %} +{% field "Mobile phone" item.mobile_phone %} {% if item.organization %}

{% trans "Associated organization"%}

{{item.organization}}

diff --git a/ishtar_common/views.py b/ishtar_common/views.py index f605c4b25..819c88f32 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -356,10 +356,19 @@ def get_item(model, func_name, default_name, extra_request_keys=[], except ValueError: return HttpResponse('[]', mimetype='text/plain') for k in request_keys: - q = request_items.get(k) - if not q: + val = request_items.get(k) + if not val: + continue + req_keys = request_keys[k] + if type(req_keys) not in (list, tuple): + dct[req_keys] = val continue - dct[request_keys[k]] = q + # multiple choice target + reqs = Q(**{req_keys[0]: val}) + for req_key in req_keys[1:]: + q = Q(**{req_key: val}) + reqs = reqs | q + and_reqs.append(reqs) if not dct and 'submited' not in request_items: if default_name in request.session and \ request.session[default_name]: @@ -832,8 +841,8 @@ get_person = get_item( models.Person, 'get_person', 'person', extra_request_keys={ - 'name': 'name__icontains', - 'surname': 'surname__icontains', + 'name': ['name__icontains', 'raw_name__icontains'], + 'surname': ['surname__icontains', 'raw_name__icontains'], 'attached_to': 'attached_to__pk', 'person_types': 'person_types__pk__in', }) -- cgit v1.2.3