summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 668546602..8d4945a0b 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -37,7 +37,8 @@ from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \
from archaeological_operations.models import AdministrativeAct
from archaeological_context_records.models import ContextRecord, Dating
-from ishtar_common.models import PRIVATE_FIELDS, SpatialReferenceSystem
+from ishtar_common.models import PRIVATE_FIELDS, SpatialReferenceSystem, \
+ BulkUpdatedItem
class MaterialType(GeneralType):
@@ -147,7 +148,7 @@ class BFBulkView(object):
"""
-class BaseFind(BaseHistorizedItem, OwnPerms):
+class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
label = models.TextField(_(u"Free ID"))
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
auto_external_id = models.BooleanField(
@@ -349,7 +350,12 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
@classmethod
def cached_label_bulk_update(cls, operation_id=None, parcel_id=None,
- context_record_id=None):
+ context_record_id=None, transaction_id=None):
+ transaction_id, is_recursion = cls.bulk_recursion(
+ transaction_id, [operation_id, parcel_id, context_record_id])
+ if is_recursion:
+ return
+
if operation_id:
filters = """
INNER JOIN archaeological_context_records_contextrecord acr
@@ -372,6 +378,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
kwargs = {'context_record_id': context_record_id}
else:
return
+ kwargs['transaction_id'] = transaction_id
sql = """
UPDATE "archaeological_finds_basefind" AS bf
@@ -449,12 +456,9 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
ope_prefix=settings.ISHTAR_DEF_OPE_PREFIX,
join=settings.JOINT, filters=filters,
zeros=settings.ISHTAR_FINDS_INDEX_ZERO_LEN * "0")
- # with connection.cursor() as c: # django 1.8
- c = connection.cursor()
- c.execute(sql, args)
- transaction.commit_unless_managed()
- cls._meta.get_field_by_name(
- 'find')[0].model.cached_label_bulk_update(**kwargs)
+ with connection.cursor() as c:
+ c.execute(sql, args)
+ Find.cached_label_bulk_update(**kwargs)
post_save.connect(post_save_point, sender=BaseFind)
@@ -469,8 +473,7 @@ CHECK_CHOICES = (('NC', _(u"Not checked")),
class FindBasket(Basket):
- items = models.ManyToManyField('Find', blank=True, null=True,
- related_name='basket')
+ items = models.ManyToManyField('Find', blank=True, related_name='basket')
class FirstBaseFindView(object):
@@ -509,8 +512,8 @@ class FBulkView(object):
"""
-class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
- ShortMenuItem):
+class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
+ OwnPerms, ShortMenuItem):
CHECK_DICT = dict(CHECK_CHOICES)
SHOW_URL = 'show-find'
SLUG = 'find'
@@ -687,7 +690,7 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
null=True)
previous_id = models.TextField(_(u"Previous ID"), blank=True, null=True)
index = models.IntegerField(u"Index", default=0)
- checked = models.CharField(_(u"Check"), max_length=2, default='NC',
+ checked = models.CharField(_(u"Check"), max_length=2, default=u'NC',
choices=CHECK_CHOICES)
check_date = models.DateField(_(u"Check date"),
default=datetime.date.today)
@@ -908,14 +911,14 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
return new
@classmethod
- def get_query_owns(cls, user):
- return (Q(base_finds__context_record__operation__scientist=user.
+ def get_query_owns(cls, ishtaruser):
+ return (Q(base_finds__context_record__operation__scientist=
ishtaruser.person) |
- Q(base_finds__context_record__operation__in_charge=user.
+ Q(base_finds__context_record__operation__in_charge=
ishtaruser.person) |
- Q(base_finds__context_record__operation__collaborators__pk=user.
+ Q(base_finds__context_record__operation__collaborators__pk=
ishtaruser.person.pk) |
- Q(history_creator=user)) \
+ Q(history_creator=ishtaruser.user_ptr)) \
& Q(base_finds__context_record__operation__end_date__isnull=True)
@classmethod
@@ -936,7 +939,12 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
@classmethod
def cached_label_bulk_update(cls, operation_id=None, parcel_id=None,
- context_record_id=None):
+ context_record_id=None, transaction_id=None):
+ transaction_id, is_recursion = cls.bulk_recursion(
+ transaction_id, [operation_id, parcel_id, context_record_id])
+ if is_recursion:
+ return
+
if operation_id:
filters = """
INNER JOIN find_first_base_find myfbf
@@ -1006,10 +1014,8 @@ class Find(ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms,
ope_prefix=settings.ISHTAR_DEF_OPE_PREFIX,
join=settings.JOINT, filters=filters,
zeros=settings.ISHTAR_FINDS_INDEX_ZERO_LEN * "0")
- # with connection.cursor() as c: # django 1.8
- c = connection.cursor()
- c.execute(sql, args)
- transaction.commit_unless_managed()
+ with connection.cursor() as c:
+ c.execute(sql, args)
def generate_index(self):
"""
@@ -1165,13 +1171,13 @@ class FindSource(Source):
return self.find
@classmethod
- def get_query_owns(cls, user):
- return (Q(find__base_finds__context_record__operation__scientist=user.
+ def get_query_owns(cls, ishtaruser):
+ return (Q(find__base_finds__context_record__operation__scientist=
ishtaruser.person) |
- Q(find__base_finds__context_record__operation__in_charge=user.
+ Q(find__base_finds__context_record__operation__in_charge=
ishtaruser.person) |
Q(
- find__base_finds__context_record__operation__collaborators__pk=user.
+ find__base_finds__context_record__operation__collaborators__pk=
ishtaruser.person.pk)) \
& Q(
find__base_finds__context_record__operation__end_date__isnull=True)