summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py7
-rw-r--r--ishtar_common/migrations/0040_auto_20180413_1147.py25
-rw-r--r--ishtar_common/models.py33
3 files changed, 58 insertions, 7 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index c4d6f2026..70e144980 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -279,10 +279,17 @@ class FormHeader(object):
class IshtarForm(forms.Form):
TYPES = [] # FieldType list
+ PROFILE_FILTER = {} # profile key associated to field list
HEADERS = {} # field key associated to FormHeader instance
def __init__(self, *args, **kwargs):
super(IshtarForm, self).__init__(*args, **kwargs)
+ if self.PROFILE_FILTER:
+ profile = models.get_current_profile()
+ for profile_key in self.PROFILE_FILTER:
+ if not getattr(profile, profile_key):
+ for field_key in self.PROFILE_FILTER[profile_key]:
+ self.fields.pop(field_key)
for field in self.TYPES:
self._init_type(field)
for k in self.fields:
diff --git a/ishtar_common/migrations/0040_auto_20180413_1147.py b/ishtar_common/migrations/0040_auto_20180413_1147.py
new file mode 100644
index 000000000..2dd9ab3de
--- /dev/null
+++ b/ishtar_common/migrations/0040_auto_20180413_1147.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-13 11:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0039_auto_20180405_1923'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='operationtype',
+ name='judiciary',
+ field=models.BooleanField(default=False, verbose_name='Is judiciary'),
+ ),
+ migrations.AlterField(
+ model_name='import',
+ name='state',
+ field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 8d0339b92..b92614e08 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3069,15 +3069,19 @@ m2m_changed.connect(town_child_changed, sender=Town.children.through)
class OperationType(GeneralType):
order = models.IntegerField(_(u"Order"), default=1)
preventive = models.BooleanField(_(u"Is preventive"), default=True)
+ judiciary = models.BooleanField(_(u"Is judiciary"), default=False)
class Meta:
verbose_name = _(u"Operation type")
verbose_name_plural = _(u"Operation types")
- ordering = ['-preventive', 'order', 'label']
+ ordering = ['judiciary', '-preventive', 'order', 'label']
@classmethod
- def get_types(cls, dct={}, instances=False, exclude=[], empty_first=True,
- default=None, initial=[]):
+ def get_types(cls, dct=None, instances=False, exclude=None,
+ empty_first=True, default=None, initial=None):
+ dct = dct or {}
+ exclude = exclude or []
+ initial = initial or []
tuples = []
dct['available'] = True
if not instances and empty_first and not default:
@@ -3093,7 +3097,7 @@ class OperationType(GeneralType):
exclude.append(default.txt_idx)
if exclude:
items = items.exclude(txt_idx__in=exclude)
- current_preventive, current_lst = None, None
+ current_preventive, current_judiciary, current_lst = None, None, None
item_list = list(items.order_by(*cls._meta.ordering).all())
new_vals = cls._get_initial_types(initial, [i.pk for i in item_list],
instance=True)
@@ -3103,12 +3107,19 @@ class OperationType(GeneralType):
if instances:
return item_list
for item in item_list:
- if not current_lst or item.preventive != current_preventive:
+ if not current_lst or item.preventive != current_preventive \
+ or item.judiciary != current_judiciary:
if current_lst:
tuples.append(current_lst)
- current_lst = [_(u"Preventive") if item.preventive else
- _(u"Research"), []]
+ if item.judiciary:
+ gp_lbl = _(u"Judiciary")
+ elif item.preventive:
+ gp_lbl = _(u"Preventive")
+ else:
+ gp_lbl = _(u"Research")
+ current_lst = [gp_lbl, []]
current_preventive = item.preventive
+ current_judiciary = item.judiciary
current_lst[1].append((item.pk, _(unicode(item))))
if current_lst:
tuples.append(current_lst)
@@ -3124,6 +3135,14 @@ class OperationType(GeneralType):
return op_type.preventive
return key == op_type.txt_idx
+ @classmethod
+ def is_judiciary(cls, ope_type_id):
+ try:
+ op_type = cls.objects.get(pk=ope_type_id)
+ except cls.DoesNotExist:
+ return False
+ return op_type.judiciary
+
post_save.connect(post_save_cache, sender=OperationType)
post_delete.connect(post_save_cache, sender=OperationType)