summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-18 11:18:11 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-24 12:06:08 +0200
commite4886af839af1194d0153c99234751d7cd4fde27 (patch)
treed0bd953ebe547522206cb9a01ebe1b33dcaa89c4
parent1ca13841328bf1aa661b0d6bbb69c4e84950d9df (diff)
downloadIshtar-e4886af839af1194d0153c99234751d7cd4fde27.tar.bz2
Ishtar-e4886af839af1194d0153c99234751d7cd4fde27.zip
Display pined search on search input
-rw-r--r--archaeological_context_records/models.py8
-rw-r--r--archaeological_finds/models_finds.py10
-rw-r--r--ishtar_common/models.py6
-rw-r--r--ishtar_common/static/js/ishtar.js7
-rw-r--r--ishtar_common/templates/blocks/DataTables.html49
-rw-r--r--ishtar_common/templates/ishtar/blocks/advanced_shortcut_menu.html51
-rw-r--r--ishtar_common/templates/ishtar/blocks/shortcut_menu.html17
-rw-r--r--ishtar_common/views_item.py58
8 files changed, 107 insertions, 99 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 60f8fce1b..b0e2256a2 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -282,6 +282,10 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,
pgettext_lazy("key for text search", u"operation-code"),
'operation__operation_code'
),
+ 'operation__cached_label': (
+ pgettext_lazy("key for text search", u"operation"),
+ 'operation__cached_label'
+ ),
'archaeological_site': (
pgettext_lazy("key for text search", u"site"),
'archaeological_site__cached_label__icontains'
@@ -319,6 +323,10 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,
"identification__label", "activity__label",
"excavation_technic__label"]
M2M_SEARCH_VECTORS = ["datings__period__label"]
+ UP_MODEL_QUERY = {
+ "OPE": (pgettext_lazy("key for text search", u"operation"),
+ 'cached_label'),
+ }
history = HistoricalRecords()
# fields
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 3c44e0be4..fb7a8802a 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -858,6 +858,10 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
'basket': (
pgettext_lazy("key for text search", u"basket"),
'basket__label__exact'
+ ),
+ 'base_finds__context_record__operation__cached_label': (
+ pgettext_lazy("key for text search", u"operation"),
+ 'base_finds__context_record__operation__cached_label__icontains'
),
}
for v in ALT_NAMES.values():
@@ -895,6 +899,12 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
module='warehouse'
),
]
+ UP_MODEL_QUERY = {
+ "OPE": (pgettext_lazy("key for text search", u"operation"),
+ 'cached_label'),
+ "UE": (pgettext_lazy("key for text search", u"context-record"),
+ 'cached_label'),
+ }
# fields
base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"),
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a097951e0..15d6a0ba9 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1696,10 +1696,16 @@ class ShortMenuItem(object):
"""
Item available in the short menu
"""
+ UP_MODEL_QUERY = {}
+
@classmethod
def get_short_menu_class(cls, pk):
return ''
+ @property
+ def short_class_name(self):
+ return ""
+
class QuickAction(object):
"""
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 326a4cb85..2ff9e07a7 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -779,14 +779,9 @@ function manage_pinned_search(name, data){
$('#pinned_search_content_' + name).html('');
for (idx in data){
if (idx == 'pinned-search' && data[idx] != ''){
- $('#pinned_search_content_' + name).html(data[idx]);
+ $("#id_search_vector").val(data[idx]);
}
}
- if ($('#pinned_search_content_' + name).html()){
- $('#pinned_search_' + name).show();
- } else {
- $('#pinned_search_' + name).hide();
- }
}
var dt_generate_qa_url = function (table, url){
diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html
index 309bb0b09..8af5f1a7b 100644
--- a/ishtar_common/templates/blocks/DataTables.html
+++ b/ishtar_common/templates/blocks/DataTables.html
@@ -10,12 +10,6 @@
<p><a href="#" onclick="open_window('{{url_new}}');">{{new_message}}</a></p>
{% endif %}
-<div class="alert alert-info" role="alert" id="pinned_search_{{name}}">
- <i class="fa fa-thumb-tack"></i> &nbsp;
- <strong>{% trans "Pinned search:" %}</strong>
- <em><span id="pinned_search_content_{{name}}"></span></em>
-</div>
-
<div class="modal fade table-modal-lg" tabindex="-1" role="dialog"
aria-hidden="true" id="modal_grid_{{name}}">
<div class="modal-dialog full modal-lg">
@@ -207,49 +201,6 @@ jQuery(document).ready(function(){
if (datatables_i18n) datatable_options['language'] = datatables_i18n;
datatable_{{sname}} = jQuery("#grid_{{name}}").DataTable(datatable_options);
-{% comment %}
-
- jQuery("#grid_{{name}}").jqGrid({
- url:'{{source}}',
- datatype: "json",
- mtype: 'GET',
- colNames:['id', '', {{col_names|safe}}],
- colModel:[
- {name:'id', index:'id', hidden:true},
- {name:'link', index:'link', width:30},
- {{extra_cols|safe}}
- ],
- height: 300,
- sortname: '__default__',
- viewrecords: true,
- sortorder: "asc",
- emptyrecords: "{{no_result}}",
- loadtext: "{{loading}}",
- pager: '#pager_{{name}}',
- width: null,
- shrinkToFit: false,
- rowNum:20,
- {% if multiple_select %}multiselect: true,{% endif %}
- jsonReader : {repeatitems: false},
- loadError: function (jqXHR, textStatus, errorThrown) {
- alert("{% trans "An error as occured during search. Check your query fields." %}");
- },
- beforeProcessing: function(data, status, xhr){
- $('#pinned_search_content_{{name}}').html('');
- for (idx in data){
- if (idx == 'pinned-search' && data[idx] != ''){
- $('#pinned_search_content_{{name}}').html(data[idx]);
- }
- }
- if ($('#pinned_search_content_{{name}}').html()){
- $('#pinned_search_{{name}}').show();
- } else {
- $('#pinned_search_{{name}}').hide();
- }
- }
- });
-{% endcomment %}
-
{% if multiple %}
jQuery("#add_button_{{name}}").click(function (){
var mygrid = jQuery("#grid_{{name}}");
diff --git a/ishtar_common/templates/ishtar/blocks/advanced_shortcut_menu.html b/ishtar_common/templates/ishtar/blocks/advanced_shortcut_menu.html
index 953b0ef40..e1dc852d9 100644
--- a/ishtar_common/templates/ishtar/blocks/advanced_shortcut_menu.html
+++ b/ishtar_common/templates/ishtar/blocks/advanced_shortcut_menu.html
@@ -1,27 +1,36 @@
{% extends "ishtar/blocks/base_shortcut_menu.html" %}
{% load i18n %}
{% block short_content %}
-<div class="short-menu-buttons btn-group" role="group">
- <button type="button" class="btn btn-secondary"
- id='short-menu-simple' title="{% trans 'Simple menu limited to your own items. Be careful only the last 100 items are displayed.' %}">{% trans "simple" %}</button>
- <button type="button" class="btn btn-secondary active" id='short-menu-advanced' title="{% trans 'Advanced menu' %}">{% trans "advanced" %}</button>
-</div>
-<div id='action_current_items' class="btn-group" role="group">
- <button type="button" onclick='return activate_own_search();'
- title="{% trans 'Search within my items' %}"
- class='btn btn-secondary activate_own_search{% if SHORTCUT_SEARCH == "own" %} active{% endif %}'>
- <i class="icon fa fa-user" aria-hidden="true"></i>
- </button>
- <button type="button" onclick='return activate_all_search();'
- title="{% trans 'Search within all items' %}"
- class='btn btn-secondary activate_all_search{% if SHORTCUT_SEARCH == "all" %} active{% endif %}'>
- <i class="icon fa fa-users" aria-hidden="true"></i>
- </button>
- {% comment %}
- <p>
- <a href='' onclick='return load_shortcut_menu();' class='disabled'><i class="icon fa fa-2x fa-refresh" aria-hidden="true" title="{% trans 'Refresh menu' %}"></i></a>
- </p>
- {% endcomment %}
+<div class="d-flex">
+ <div class="short-menu-buttons btn-group p-2" role="group">
+ <button type="button" class="btn btn-secondary"
+ id='short-menu-simple' title="{% trans 'Simple menu limited to your own items. Be careful only the last 100 items are displayed.' %}">{% trans "simple" %}</button>
+ <button type="button" class="btn btn-secondary active" id='short-menu-advanced' title="{% trans 'Advanced menu' %}">{% trans "advanced" %}</button>
+ </div>
+ <div id='action_current_items' class="btn-group p-2" role="group">
+ <button type="button" onclick='return activate_own_search();'
+ title="{% trans 'Search within my items' %}"
+ class='btn btn-secondary activate_own_search{% if SHORTCUT_SEARCH == "own" %} active{% endif %}'>
+ <i class="icon fa fa-user" aria-hidden="true"></i>
+ </button>
+ <button type="button" onclick='return activate_all_search();'
+ title="{% trans 'Search within all items' %}"
+ class='btn btn-secondary activate_all_search{% if SHORTCUT_SEARCH == "all" %} active{% endif %}'>
+ <i class="icon fa fa-users" aria-hidden="true"></i>
+ </button>
+ {% comment %}
+ <p>
+ <a href='' onclick='return load_shortcut_menu();' class='disabled'><i class="icon fa fa-2x fa-refresh" aria-hidden="true" title="{% trans 'Refresh menu' %}"></i></a>
+ </p>
+ {% endcomment %}
+ </div>
+ <div class="short-menu-buttons btn-group ml-auto p-2" role="group">
+ <button type="button" class="btn btn-secondary active"
+ id='short-menu-refresh' onclick="location.reload();"
+ title="{% trans 'Refresh current page' %}">
+ <i class="icon fa fa-refresh" aria-hidden="true"></i>
+ </button>
+ </div>
</div>
<p id='current_items'>
{% for lbl, model_name, current, widget in menu %}
diff --git a/ishtar_common/templates/ishtar/blocks/shortcut_menu.html b/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
index 10113aa59..447deb573 100644
--- a/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
+++ b/ishtar_common/templates/ishtar/blocks/shortcut_menu.html
@@ -1,10 +1,19 @@
{% extends "ishtar/blocks/base_shortcut_menu.html" %}
{% load i18n %}
{% block short_content %}
-<div class="short-menu-buttons btn-group" role="group">
- <button type="button" class="btn btn-secondary active"
- id='short-menu-simple' title="{% trans 'Simple menu limited to your own items. Be careful only the last 100 items are displayed.' %}">{% trans "simple" %}</button>
- <button type="button" class="btn btn-secondary" id='short-menu-advanced' title="{% trans 'Advanced menu' %}">{% trans "advanced" %}</button>
+<div class="d-flex">
+ <div class="short-menu-buttons btn-group p-2" role="group">
+ <button type="button" class="btn btn-secondary active"
+ id='short-menu-simple' title="{% trans 'Simple menu limited to your own items. Be careful only the last 100 items are displayed.' %}">{% trans "simple" %}</button>
+ <button type="button" class="btn btn-secondary" id='short-menu-advanced' title="{% trans 'Advanced menu' %}">{% trans "advanced" %}</button>
+ </div>
+ <div class="short-menu-buttons btn-group ml-auto p-2" role="group">
+ <button type="button" class="btn btn-secondary active"
+ id='short-menu-refresh' onclick="location.reload();"
+ title="{% trans 'Refresh current page' %}">
+ <i class="icon fa fa-refresh" aria-hidden="true"></i>
+ </button>
+ </div>
</div>
<div>
<p class="alert alert-info mt-2">
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index cfb7a42c3..98dcd3d4c 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -440,7 +440,10 @@ def _search_manage_search_vector(model, dct, exc_dct, request_keys):
if 'search_vector' not in dct:
return dct, exc_dct
- parentheses_groups = _parse_parentheses(dct['search_vector'].strip())
+ # remove inside parenthesis
+ search_vector = \
+ dct['search_vector'].replace(u'(', u'').replace(u')', u'').strip()
+ parentheses_groups = _parse_parentheses(search_vector)
search_query, extra_dct, extra_exc_dct = _parse_parentheses_groups(
parentheses_groups, request_keys)
dct.update(extra_dct)
@@ -960,7 +963,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
if 'basket-' in value:
try:
dct = {"basket__pk":
- request.session[default_name].split('-')[-1]}
+ request.session[default_name].split('-')[-1]}
pinned_search = unicode(FindBasket.objects.get(
pk=dct["basket__pk"]))
except FindBasket.DoesNotExist:
@@ -968,26 +971,43 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
else:
try:
dct = {"pk": request.session[default_name]}
- pinned_search = unicode(model._meta.verbose_name) \
- + u" - " + unicode(
- model.objects.get(pk=dct["pk"]))
+ pinned_search = u'"{}"'.format(
+ model.objects.get(pk=dct["pk"])
+ )
except model.DoesNotExist:
pass
elif dct == (my_base_request or {}):
- # a parent item may be selected in the default menu
- for name, key in my_relative_session_names:
- if name in request.session and request.session[name] \
- and 'basket-' not in request.session[name] \
- and name in CURRENT_ITEM_KEYS_DICT:
- up_model = CURRENT_ITEM_KEYS_DICT[name]
- try:
- dct.update({key: request.session[name]})
- pinned_search = unicode(up_model._meta.verbose_name) \
- + u" - " + unicode(
- up_model.objects.get(pk=dct[key]))
- break
- except up_model.DoesNotExist:
- pass
+ if not hasattr(model, 'UP_MODEL_QUERY'):
+ logger.warning(
+ "**WARN get_item**: - UP_MODEL_QUERY not defined for "
+ "'{}'".format(model.__class__))
+ else:
+ # a parent item may be selected in the default menu
+ for name, key in my_relative_session_names:
+ if name in request.session and request.session[name] \
+ and 'basket-' not in request.session[name] \
+ and name in CURRENT_ITEM_KEYS_DICT:
+ up_model = CURRENT_ITEM_KEYS_DICT[name]
+ try:
+ dct.update({key: request.session[name]})
+ up_item = up_model.objects.get(pk=dct[key])
+ if up_item.short_class_name not in \
+ model.UP_MODEL_QUERY:
+ logger.warning(
+ "**WARN get_item**: - {} not in "
+ "UP_MODEL_QUERY for {}'".format(
+ up_item.short_class_name,
+ model))
+ else:
+ req_key, up_attr = model.UP_MODEL_QUERY[
+ up_item.short_class_name]
+ pinned_search = u'{}="{}"'.format(
+ req_key,
+ getattr(up_item, up_attr)
+ )
+ break
+ except up_model.DoesNotExist:
+ pass
if (not dct or data_type == 'csv') \
and func_name in request.session:
dct = request.session[func_name]