summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/models.py6
-rw-r--r--archaeological_finds/models_finds.py8
-rw-r--r--archaeological_finds/models_treatments.py34
-rw-r--r--archaeological_operations/models.py6
-rw-r--r--ishtar_common/models.py2
-rw-r--r--ishtar_common/static/js/ishtar.js12
-rw-r--r--ishtar_common/views.py18
7 files changed, 70 insertions, 16 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 7d399ecd9..a0ba6c379 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -268,9 +268,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None):
- replace_query = {}
- if menu_filtr:
- replace_query = {'operation': menu_filtr}
+ replace_query = None
+ if menu_filtr and 'operation' in menu_filtr:
+ replace_query = Q(operation=menu_filtr['operation'])
owns = super(ContextRecord, cls).get_owns(
user, replace_query=replace_query,
limit=limit)
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 9a7a71f84..e29669773 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -663,9 +663,11 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None):
- replace_query = {}
- if menu_filtr:
- replace_query = {'base_finds__context_record': menu_filtr}
+ replace_query = None
+ if menu_filtr and 'contextrecord' in menu_filtr:
+ replace_query = Q(
+ base_finds__context_record=menu_filtr['contextrecord']
+ )
owns = super(Find, cls).get_owns(
user, replace_query=replace_query,
limit=limit)
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index eff8d8371..5e763085c 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -21,7 +21,7 @@ import datetime
from django.conf import settings
from django.contrib.gis.db import models
-from django.db.models import Max
+from django.db.models import Max, Q
from django.db.models.signals import post_save, post_delete, pre_delete
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _, ugettext
@@ -144,11 +144,29 @@ class Treatment(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
lbl += u" %s %s" % (_(u"by"), unicode(self.person))
return lbl
+ @property
+ def short_class_name(self):
+ return _(u"TREATMENT")
+
+ @classmethod
+ def get_query_owns(cls, user):
+ return (Q(history_creator=user) |
+ Q(person__ishtaruser=user.ishtaruser)) \
+ & Q(end_date__isnull=True)
+
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None):
- replace_query = {}
+ replace_query = None
if menu_filtr:
- replace_query = {'file': menu_filtr}
+ if 'treatmentfile' in menu_filtr:
+ replace_query = Q(file=menu_filtr['treatmentfile'])
+ if 'find' in menu_filtr:
+ q = Q(upstream=menu_filtr['find']) | Q(
+ downstream=menu_filtr['find'])
+ if replace_query:
+ replace_query = replace_query | q
+ else:
+ replace_query = q
owns = super(Treatment, cls).get_owns(
user, replace_query=replace_query, limit=limit)
return sorted(
@@ -455,6 +473,16 @@ class TreatmentFile(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return self.cached_label
@property
+ def short_class_name(self):
+ return _(u"Treatment file")
+
+ @classmethod
+ def get_query_owns(cls, user):
+ return (Q(history_creator=user) |
+ Q(in_charge__ishtaruser=user.ishtaruser)) \
+ & Q(end_date__isnull=True)
+
+ @property
def associated_filename(self):
return "-".join([str(slugify(getattr(self, attr)))
for attr in ('year', 'index', 'internal_reference',
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 7507da817..0270a0c74 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -377,9 +377,9 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None):
- replace_query = {}
- if menu_filtr:
- replace_query = {'associated_file': menu_filtr}
+ replace_query = None
+ if menu_filtr and 'file' in menu_filtr:
+ replace_query = Q(associated_file=menu_filtr['file'])
owns = super(Operation, cls).get_owns(
user, replace_query=replace_query,
limit=limit)
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index fcb367ae5..ccb817adc 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -257,7 +257,7 @@ class OwnPerms:
if query:
q = cls.objects.filter(query)
if replace_query:
- q = cls.objects.filter(**replace_query)
+ q = cls.objects.filter(replace_query)
if limit:
items += list(q.order_by('-pk')[:limit])
else:
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 8abf23289..b5f4f1a79 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -102,6 +102,18 @@ function init_shortcut_fields(){
load_shortcut_menu
);
});
+ $("#current_treatment").change(function(){
+ $.post('/' + url_path + 'update-current-item/',
+ {item:'treatment', value:$("#current_treatment").val()},
+ load_shortcut_menu
+ );
+ });
+ $("#current_treatmentfile").change(function(){
+ $.post('/' + url_path + 'update-current-item/',
+ {item:'treatmentfile', value:$("#current_treatmentfile").val()},
+ load_shortcut_menu
+ );
+ });
}
function init_advanced_shortcut_fields(){
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 783c6badb..cf3f968b1 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -264,7 +264,7 @@ def shortcut_menu(request):
'ishtar/blocks/advanced_shortcut_menu.html',
dct, context_instance=RequestContext(request))
dct = {'current_menu': []}
- current_selected_item = None
+ current_selected_item = {}
for lbl, model in CURRENT_ITEMS:
new_selected_item = None
model_name = model.SLUG
@@ -294,7 +294,8 @@ def shortcut_menu(request):
pass
if items:
dct['current_menu'].append((lbl, model_name, cls, items))
- current_selected_item = new_selected_item
+ if new_selected_item:
+ current_selected_item[model_name] = new_selected_item
return render_to_response('ishtar/blocks/shortcut_menu.html', dct,
context_instance=RequestContext(request))
@@ -317,6 +318,16 @@ def get_current_items(request):
def unpin(request, item_type):
+ if item_type not in ('find', 'contextrecord', 'operation', 'file',
+ 'treatment', 'treatmentfile'):
+ logger.warning("unpin unknow type: {}".format(item_type))
+ return HttpResponse('nok')
+ request.session['treatment'] = ''
+ if item_type == 'treatment':
+ return HttpResponse('ok')
+ request.session['treatmentfile'] = ''
+ if item_type == 'treatmentfile':
+ return HttpResponse('ok')
request.session['find'] = ''
if item_type == 'find':
return HttpResponse('ok')
@@ -327,7 +338,8 @@ def unpin(request, item_type):
if item_type == 'operation':
return HttpResponse('ok')
request.session['file'] = ''
- return HttpResponse('ok')
+ if item_type == 'file':
+ return HttpResponse('ok')
def update_current_item(request, item_type=None, pk=None):