summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-18 01:05:08 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-02-18 01:05:08 +0100
commit50b565e74631a684b2b389cac55982db86d8d5ba (patch)
treea7256183a32a204ac4e90e2503483c5ffc1f33db /archaeological_operations
parent5e47cbfcbeb090762547042d809016074bf1c679 (diff)
downloadIshtar-50b565e74631a684b2b389cac55982db86d8d5ba.tar.bz2
Ishtar-50b565e74631a684b2b389cac55982db86d8d5ba.zip
New management of modules
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/admin.py20
-rw-r--r--archaeological_operations/forms.py47
-rw-r--r--archaeological_operations/ishtar_menu.py6
-rw-r--r--archaeological_operations/models.py437
-rw-r--r--archaeological_operations/views.py3
-rw-r--r--archaeological_operations/wizards.py8
6 files changed, 248 insertions, 273 deletions
diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py
index 2a0ec652c..34e6da2ca 100644
--- a/archaeological_operations/admin.py
+++ b/archaeological_operations/admin.py
@@ -24,17 +24,15 @@ from ishtar_common.admin import HistorizedObjectAdmin, GeneralTypeAdmin
import models
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-if FILES_AVAILABLE:
- class AdministrativeActAdmin(HistorizedObjectAdmin):
- list_display = ('year', 'index', 'operation', 'associated_file',
- 'act_type')
- list_filter = ('act_type',)
- search_fields = ('year', 'index')
- model = models.AdministrativeAct
+class AdministrativeActAdmin(HistorizedObjectAdmin):
+ list_display = ('year', 'index', 'operation', 'associated_file',
+ 'act_type')
+ list_filter = ('act_type',)
+ search_fields = ('year', 'index')
+ model = models.AdministrativeAct
- admin.site.register(models.AdministrativeAct, AdministrativeActAdmin)
+admin.site.register(models.AdministrativeAct, AdministrativeActAdmin)
class PeriodAdmin(admin.ModelAdmin):
@@ -78,9 +76,7 @@ admin.site.register(models.OperationSource, OperationSourceAdmin)
class ParcelAdmin(HistorizedObjectAdmin):
- list_display = ['section', 'parcel_number', 'operation']
- if FILES_AVAILABLE:
- list_display.append('associated_file')
+ list_display = ['section', 'parcel_number', 'operation', 'associated_file']
search_fields = ('operation__name',)
model = models.Parcel
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index d18e7cea7..37ccbf277 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -34,14 +34,11 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from django.utils.safestring import mark_safe
from ishtar_common.models import valid_id, PersonType, Person, Town, \
- DocumentTemplate, Organization, OrganizationType
+ DocumentTemplate, Organization, OrganizationType, get_current_profile
from ishtar_common.wizards import MultiValueDict
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-
-if FILES_AVAILABLE:
- from archaeological_files.models import File
+from archaeological_files.models import File
import models
from widgets import ParcelWidget, SelectParcelWidget
@@ -566,16 +563,16 @@ class OperationCodeInput(forms.TextInput):
'url': reverse_lazy('get_available_operation_code')}
return mark_safe(rendered + js)
-if FILES_AVAILABLE:
- class OperationFormFileChoice(forms.Form):
- form_label = _(u"Associated file")
- associated_models = {'associated_file': File, }
- currents = {'associated_file': File}
- associated_file = forms.IntegerField(
- label=_(u"Archaelogical file"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-file'), associated_model=File),
- validators=[valid_id(File)], required=False)
+
+class OperationFormFileChoice(forms.Form):
+ form_label = _(u"Associated file")
+ associated_models = {'associated_file': File, }
+ currents = {'associated_file': File}
+ associated_file = forms.IntegerField(
+ label=_(u"Archaelogical file"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-file'), associated_model=File),
+ validators=[valid_id(File)], required=False)
class OperationFormAbstract(forms.Form):
@@ -814,14 +811,13 @@ class OperationFormGeneral(forms.Form):
class OperationFormModifGeneral(OperationFormGeneral):
operation_code = forms.IntegerField(label=_(u"Operation code"),
required=False)
- if FILES_AVAILABLE:
- currents = {'associated_file': File}
- associated_file = forms.IntegerField(
- label=_(u"Archaelogical file"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-file'),
- associated_model=File),
- validators=[valid_id(File)], required=False)
+ currents = {'associated_file': File}
+ associated_file = forms.IntegerField(
+ label=_(u"Archaelogical file"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-file'),
+ associated_model=File),
+ validators=[valid_id(File)], required=False)
def __init__(self, *args, **kwargs):
super(OperationFormModifGeneral, self).__init__(*args, **kwargs)
@@ -829,12 +825,13 @@ class OperationFormModifGeneral(OperationFormGeneral):
self.fields.keyOrder.pop(self.fields.keyOrder.index('associated_file'))
self.fields.keyOrder.insert(self.fields.keyOrder.index('in_charge'),
'associated_file')
+ if not get_current_profile().files:
+ self.fields.pop('associated_file')
OperationFormModifGeneral.associated_models = \
OperationFormGeneral.associated_models.copy()
-if FILES_AVAILABLE:
- OperationFormModifGeneral.associated_models['associated_file'] = File
+OperationFormModifGeneral.associated_models['associated_file'] = File
class OperationFormPreventive(forms.Form):
diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py
index 60f764ab7..5a22efd05 100644
--- a/archaeological_operations/ishtar_menu.py
+++ b/archaeological_operations/ishtar_menu.py
@@ -17,17 +17,15 @@
# See the file COPYING for details.
-from django.conf import settings
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.menu_base import SectionItem, MenuItem
+from ishtar_common.models import get_current_profile
import models
# be carreful: each access_controls must be relevant with check_rights in urls
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-
MENU_SECTIONS = [
(30, SectionItem(
'operation_management', _(u"Operation"),
@@ -98,7 +96,7 @@ MENU_SECTIONS = [
),
]
-if FILES_AVAILABLE:
+if get_current_profile().files:
MENU_SECTIONS.insert(
1,
(
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 448adcd68..5bbe357c0 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -35,8 +35,6 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \
Person, Organization, Town, Dashboard, IshtarUser, ValueGetter, \
DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\
GeneralRecordRelations, post_delete_record_relation, OperationType
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-FINDS_AVAILABLE = 'archaeological_finds' in settings.INSTALLED_APPS
class RemainType(GeneralType):
@@ -137,8 +135,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
SHOW_URL = 'show-operation'
TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns',
'start_date', 'excavation_end_date']
- if FILES_AVAILABLE:
- TABLE_COLS.insert(4, 'associated_file_short_label')
+ TABLE_COLS.insert(4, 'associated_file_short_label')
creation_date = models.DateField(_(u"Creation date"),
default=datetime.date.today)
end_date = models.DateField(_(u"Closing date"), null=True, blank=True)
@@ -161,11 +158,10 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
year = models.IntegerField(_(u"Year"), null=True, blank=True)
operation_code = models.IntegerField(_(u"Operation code"), null=True,
blank=True)
- if FILES_AVAILABLE:
- associated_file = models.ForeignKey(
- 'archaeological_files.File',
- related_name='operations', verbose_name=_(u"File"),
- blank=True, null=True)
+ associated_file = models.ForeignKey(
+ 'archaeological_files.File',
+ related_name='operations', verbose_name=_(u"File"),
+ blank=True, null=True)
operation_type = models.ForeignKey(OperationType, related_name='+',
verbose_name=_(u"Operation type"))
surface = models.IntegerField(_(u"Surface (m2)"), blank=True, null=True)
@@ -286,15 +282,12 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
return reverse('show-operation', args=[self.pk, ''])
def has_finds(self):
- if not FINDS_AVAILABLE:
- return
from archaeological_finds.models import BaseFind
return BaseFind.objects.filter(context_record__operation=self).count()
def finds(self):
- if FINDS_AVAILABLE:
- from archaeological_finds.models import BaseFind
- return BaseFind.objects.filter(context_record__operation=self)
+ from archaeological_finds.models import BaseFind
+ return BaseFind.objects.filter(context_record__operation=self)
def get_reference(self, full=False):
ref = ""
@@ -360,7 +353,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
@property
def associated_file_short_label(self):
- if not FILES_AVAILABLE or not self.associated_file:
+ if not self.associated_file:
return ""
return self.associated_file.short_label
@@ -453,10 +446,9 @@ def operation_post_save(sender, **kwargs):
operation.fnap_financing = fnap_percent
operation.save()
cached_label_changed(sender, **kwargs)
- if FILES_AVAILABLE and operation.associated_file:
+ if operation.associated_file:
operation.associated_file.update_short_menu_class()
- # manage parcel association
- if FILES_AVAILABLE and operation.associated_file:
+ # manage parcel association
for parcel in operation.parcels.all():
parcel.copy_to_file()
post_save.connect(operation_post_save, sender=Operation)
@@ -548,216 +540,214 @@ class ActType(GeneralType):
verbose_name_plural = _(u"Act types")
ordering = ('label',)
-AdministrativeAct = None
-if FILES_AVAILABLE:
- class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
- TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'act_object',
- 'signature_date', 'associated_file', 'operation',
- 'towns_label']
- TABLE_COLS_FILE = [
- 'full_ref', 'year', 'index', 'act_type',
- 'act_object', 'associated_file', 'towns_label',
- ]
- TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation',
- 'act_object', 'towns_label']
- if settings.COUNTRY == 'fr':
- TABLE_COLS.append('departments_label')
- TABLE_COLS_FILE.append('departments_label')
- TABLE_COLS_OPE.append('departments_label')
- act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
- in_charge = models.ForeignKey(
- Person, blank=True, null=True,
- related_name='adminact_operation_in_charge',
- verbose_name=_(u"Person in charge of the operation"),
- on_delete=models.SET_NULL,)
- index = models.IntegerField(verbose_name=_(u"Index"), blank=True,
- null=True)
- operator = models.ForeignKey(
- Organization, blank=True, null=True,
- verbose_name=_(u"Archaeological preventive operator"),
- related_name='adminact_operator', on_delete=models.SET_NULL)
- scientist = models.ForeignKey(
- Person, blank=True, null=True,
- related_name='adminact_scientist', on_delete=models.SET_NULL,
- verbose_name=_(u"Scientist in charge"))
- signatory = models.ForeignKey(
- Person, blank=True, null=True, related_name='signatory',
- verbose_name=_(u"Signatory"), on_delete=models.SET_NULL,)
- operation = models.ForeignKey(
- Operation, blank=True, null=True,
- related_name='administrative_act', verbose_name=_(u"Operation"))
- if FILES_AVAILABLE:
- associated_file = models.ForeignKey(
- 'archaeological_files.File',
- blank=True, null=True,
- related_name='administrative_act',
- verbose_name=_(u"Archaelogical file"))
- signature_date = models.DateField(_(u"Signature date"), blank=True,
- null=True)
- year = models.IntegerField(_(u"Year"), blank=True, null=True)
- act_object = models.TextField(_(u"Object"), max_length=300, blank=True,
+
+class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
+ TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'act_object',
+ 'signature_date', 'associated_file', 'operation',
+ 'towns_label']
+ TABLE_COLS_FILE = [
+ 'full_ref', 'year', 'index', 'act_type',
+ 'act_object', 'associated_file', 'towns_label',
+ ]
+ TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation',
+ 'act_object', 'towns_label']
+ if settings.COUNTRY == 'fr':
+ TABLE_COLS.append('departments_label')
+ TABLE_COLS_FILE.append('departments_label')
+ TABLE_COLS_OPE.append('departments_label')
+ act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
+ in_charge = models.ForeignKey(
+ Person, blank=True, null=True,
+ related_name='adminact_operation_in_charge',
+ verbose_name=_(u"Person in charge of the operation"),
+ on_delete=models.SET_NULL,)
+ index = models.IntegerField(verbose_name=_(u"Index"), blank=True,
+ null=True)
+ operator = models.ForeignKey(
+ Organization, blank=True, null=True,
+ verbose_name=_(u"Archaeological preventive operator"),
+ related_name='adminact_operator', on_delete=models.SET_NULL)
+ scientist = models.ForeignKey(
+ Person, blank=True, null=True,
+ related_name='adminact_scientist', on_delete=models.SET_NULL,
+ verbose_name=_(u"Scientist in charge"))
+ signatory = models.ForeignKey(
+ Person, blank=True, null=True, related_name='signatory',
+ verbose_name=_(u"Signatory"), on_delete=models.SET_NULL,)
+ operation = models.ForeignKey(
+ Operation, blank=True, null=True,
+ related_name='administrative_act', verbose_name=_(u"Operation"))
+ associated_file = models.ForeignKey(
+ 'archaeological_files.File',
+ blank=True, null=True,
+ related_name='administrative_act',
+ verbose_name=_(u"Archaelogical file"))
+ signature_date = models.DateField(_(u"Signature date"), blank=True,
null=True)
- if settings.COUNTRY == 'fr':
- ref_sra = models.CharField(u"Référence SRA", max_length=15,
- blank=True, null=True)
- departments_label = models.TextField(
- _(u"Departments"), blank=True, null=True,
- help_text=_(u"Cached values get from associated departments"))
- towns_label = models.TextField(
- _(u"Towns"), blank=True, null=True,
- help_text=_(u"Cached values get from associated towns"))
- history = HistoricalRecords()
- _prefix = 'adminact_'
-
- class Meta:
- ordering = ('year', 'signature_date', 'index', 'act_type')
- verbose_name = _(u"Administrative act")
- verbose_name_plural = _(u"Administrative acts")
- permissions = (
- ("view_administrativeact",
- ugettext(u"Can view all Administrative act")),
- ("view_own_administrativeact",
- ugettext(u"Can view own Administrative act")),
- ("add_own_administrativeact",
- ugettext(u"Can add own Administrative act")),
- ("change_own_administrativeact",
- ugettext(u"Can change own Administrative act")),
- ("delete_own_administrativeact",
- ugettext(u"Can delete own Administrative act")),
- )
+ year = models.IntegerField(_(u"Year"), blank=True, null=True)
+ act_object = models.TextField(_(u"Object"), max_length=300, blank=True,
+ null=True)
+ if settings.COUNTRY == 'fr':
+ ref_sra = models.CharField(u"Référence SRA", max_length=15,
+ blank=True, null=True)
+ departments_label = models.TextField(
+ _(u"Departments"), blank=True, null=True,
+ help_text=_(u"Cached values get from associated departments"))
+ towns_label = models.TextField(
+ _(u"Towns"), blank=True, null=True,
+ help_text=_(u"Cached values get from associated towns"))
+ history = HistoricalRecords()
+ _prefix = 'adminact_'
+
+ class Meta:
+ ordering = ('year', 'signature_date', 'index', 'act_type')
+ verbose_name = _(u"Administrative act")
+ verbose_name_plural = _(u"Administrative acts")
+ permissions = (
+ ("view_administrativeact",
+ ugettext(u"Can view all Administrative act")),
+ ("view_own_administrativeact",
+ ugettext(u"Can view own Administrative act")),
+ ("add_own_administrativeact",
+ ugettext(u"Can add own Administrative act")),
+ ("change_own_administrativeact",
+ ugettext(u"Can change own Administrative act")),
+ ("delete_own_administrativeact",
+ ugettext(u"Can delete own Administrative act")),
+ )
+
+ def __unicode__(self):
+ return settings.JOINT.join(
+ [unicode(item) for item in [
+ self.operation, self.associated_file, self.act_object]
+ if item])
- def __unicode__(self):
- return settings.JOINT.join(
- [unicode(item) for item in [
- self.operation, self.associated_file, self.act_object]
- if item])
-
- full_ref_lbl = _(u"Ref.")
-
- @property
- def full_ref(self):
- lbl = []
- if self.year:
- lbl.append(unicode(self.year))
- if self.index:
- lbl.append(u"n°%d" % self.index)
- if settings.COUNTRY == 'fr' and self.ref_sra:
- lbl.append(u"[%s]" % self.ref_sra)
- return u" ".join(lbl)
-
- @property
- def towns(self):
- if self.associated_file:
- return self.associated_file.towns.all()
- elif self.operation:
- return self.operation.towns.all()
- return []
-
- @property
- def departments(self):
- if settings.COUNTRY != 'fr':
- return ''
- q = None
- if self.associated_file:
- q = self.associated_file.towns.all()
- elif self.operation:
- q = self.operation.towns.all()
- if not q:
- return ''
- dpts = []
- for town in q:
- dpt = town.numero_insee[:2]
- if dpt not in dpts:
- dpts.append(dpt)
- return ', '.join(list(sorted(dpts)))
-
- @property
- def related_item(self):
- return self.operation if self.operation else self.associated_file
-
- def get_filename(self):
- filename = self.related_item.associated_filename
- filename = u"-".join(filename.split('-')[:-1]) # remove date
- if self.act_type.code:
- filename += u"-" + self.act_type.code
- if self.signature_date and self.index:
- filename += u"-%d-%d" % (self.signature_date.year,
- self.index)
- if self.signature_date:
- filename += u"-" + self.signature_date.strftime('%Y%m%d')
- return filename
-
- def publish(self, template_pk=None):
- if not self.act_type.associated_template.count():
+ full_ref_lbl = _(u"Ref.")
+
+ @property
+ def full_ref(self):
+ lbl = []
+ if self.year:
+ lbl.append(unicode(self.year))
+ if self.index:
+ lbl.append(u"n°%d" % self.index)
+ if settings.COUNTRY == 'fr' and self.ref_sra:
+ lbl.append(u"[%s]" % self.ref_sra)
+ return u" ".join(lbl)
+
+ @property
+ def towns(self):
+ if self.associated_file:
+ return self.associated_file.towns.all()
+ elif self.operation:
+ return self.operation.towns.all()
+ return []
+
+ @property
+ def departments(self):
+ if settings.COUNTRY != 'fr':
+ return ''
+ q = None
+ if self.associated_file:
+ q = self.associated_file.towns.all()
+ elif self.operation:
+ q = self.operation.towns.all()
+ if not q:
+ return ''
+ dpts = []
+ for town in q:
+ dpt = town.numero_insee[:2]
+ if dpt not in dpts:
+ dpts.append(dpt)
+ return ', '.join(list(sorted(dpts)))
+
+ @property
+ def related_item(self):
+ return self.operation if self.operation else self.associated_file
+
+ def get_filename(self):
+ filename = self.related_item.associated_filename
+ filename = u"-".join(filename.split('-')[:-1]) # remove date
+ if self.act_type.code:
+ filename += u"-" + self.act_type.code
+ if self.signature_date and self.index:
+ filename += u"-%d-%d" % (self.signature_date.year,
+ self.index)
+ if self.signature_date:
+ filename += u"-" + self.signature_date.strftime('%Y%m%d')
+ return filename
+
+ def publish(self, template_pk=None):
+ if not self.act_type.associated_template.count():
+ return
+ if not template_pk:
+ template = self.act_type.associated_template.all()[0]
+ else:
+ q = self.act_type.associated_template.filter(pk=template_pk)
+ if not q.count():
return
- if not template_pk:
- template = self.act_type.associated_template.all()[0]
- else:
- q = self.act_type.associated_template.filter(pk=template_pk)
- if not q.count():
- return
- template = q.all()[0]
- return template.publish(self)
-
- def _get_index(self):
- if not self.index:
- c_index = 1
- q = AdministrativeAct.objects.filter(
- act_type__indexed=True, signature_date__year=self.year,
- index__isnull=False).order_by("-index")
- if q.count():
- c_index = q.all()[0].index + 1
- self.index = c_index
- conflict = AdministrativeAct.objects.filter(
+ template = q.all()[0]
+ return template.publish(self)
+
+ def _get_index(self):
+ if not self.index:
+ c_index = 1
+ q = AdministrativeAct.objects.filter(
act_type__indexed=True, signature_date__year=self.year,
- index=self.index)
+ index__isnull=False).order_by("-index")
+ if q.count():
+ c_index = q.all()[0].index + 1
+ self.index = c_index
+ conflict = AdministrativeAct.objects.filter(
+ act_type__indexed=True, signature_date__year=self.year,
+ index=self.index)
+ if self.pk:
+ conflict = conflict.exclude(pk=self.pk)
+ if conflict.count():
if self.pk:
- conflict = conflict.exclude(pk=self.pk)
- if conflict.count():
- if self.pk:
- raise ValidationError(_(u"This index already exists for "
- u"this year"))
- else:
- self._get_index()
-
- def clean(self, *args, **kwargs):
- if not self.signature_date:
- return super(AdministrativeAct, self).clean(*args, **kwargs)
- self.year = self.signature_date.year
- if not self.act_type.indexed:
- return super(AdministrativeAct, self).clean(*args, **kwargs)
- self._get_index()
- super(AdministrativeAct, self).clean(*args, **kwargs)
+ raise ValidationError(_(u"This index already exists for "
+ u"this year"))
+ else:
+ self._get_index()
+
+ def clean(self, *args, **kwargs):
+ if not self.signature_date:
+ return super(AdministrativeAct, self).clean(*args, **kwargs)
+ self.year = self.signature_date.year
+ if not self.act_type.indexed:
+ return super(AdministrativeAct, self).clean(*args, **kwargs)
+ self._get_index()
+ super(AdministrativeAct, self).clean(*args, **kwargs)
- def save(self, *args, **kwargs):
- if settings.COUNTRY == 'fr':
- self.departments_label = self.departments
- self.towns_label = u", ".join(
- list(sorted([unicode(town) for town in self.towns])))
+ def save(self, *args, **kwargs):
+ if settings.COUNTRY == 'fr':
+ self.departments_label = self.departments
+ self.towns_label = u", ".join(
+ list(sorted([unicode(town) for town in self.towns])))
- force = False
- if 'force' in kwargs:
- force = kwargs.pop('force')
+ force = False
+ if 'force' in kwargs:
+ force = kwargs.pop('force')
- if not self.signature_date:
- return super(AdministrativeAct, self).save(*args, **kwargs)
- self.year = self.signature_date.year
+ if not self.signature_date:
+ return super(AdministrativeAct, self).save(*args, **kwargs)
+ self.year = self.signature_date.year
- if not self.act_type.indexed:
- return super(AdministrativeAct, self).save(*args, **kwargs)
+ if not self.act_type.indexed:
+ return super(AdministrativeAct, self).save(*args, **kwargs)
- if not force:
+ if not force:
+ self._get_index()
+ else:
+ try:
self._get_index()
- else:
- try:
- self._get_index()
- except:
- pass
+ except:
+ pass
- super(AdministrativeAct, self).save(*args, **kwargs)
- if hasattr(self, 'associated_file') and self.associated_file:
- self.associated_file.update_has_admin_act()
- self.associated_file.update_short_menu_class()
+ super(AdministrativeAct, self).save(*args, **kwargs)
+ if hasattr(self, 'associated_file') and self.associated_file:
+ self.associated_file.update_has_admin_act()
+ self.associated_file.update_short_menu_class()
def strip_zero(value):
@@ -768,11 +758,10 @@ def strip_zero(value):
class Parcel(LightHistorizedItem):
- if FILES_AVAILABLE:
- associated_file = models.ForeignKey(
- 'archaeological_files.File',
- related_name='parcels', verbose_name=_(u"File"),
- blank=True, null=True)
+ associated_file = models.ForeignKey(
+ 'archaeological_files.File',
+ related_name='parcels', verbose_name=_(u"File"),
+ blank=True, null=True)
operation = models.ForeignKey(
Operation, related_name='parcels', blank=True, null=True,
verbose_name=_(u"Operation"))
@@ -867,7 +856,7 @@ class Parcel(LightHistorizedItem):
def long_label(self):
items = [unicode(self.operation) or
- (FILES_AVAILABLE and unicode(self.associated_file)) or ""]
+ unicode(self.associated_file) or ""]
items += [unicode(item) for item in [self.section, self.parcel_number]
if item]
return settings.JOINT.join(items)
@@ -931,12 +920,10 @@ def parcel_post_save(sender, **kwargs):
if parcel.operation and parcel.operation.pk and \
parcel.town not in list(parcel.operation.towns.all()):
parcel.operation.towns.add(parcel.town)
- if FILES_AVAILABLE and parcel.associated_file and \
+ if parcel.associated_file and \
parcel.associated_file.pk and \
parcel.town not in list(parcel.associated_file.towns.all()):
parcel.associated_file.towns.add(parcel.town)
- if not FILES_AVAILABLE:
- return
if parcel.operation and parcel.associated_file:
# parcels are copied between files and operations
parcel.copy_to_operation()
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 5299b7131..22d820b5b 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -30,6 +30,7 @@ from ishtar_common.wizards import SearchWizard, check_rights_condition
from ishtar_common.forms import ClosingDateFormSelection
from ishtar_common.forms_common import AuthorFormset, TownFormset, \
SourceDeletionForm
+from ishtar_common.models import get_current_profile
from wizards import *
from forms import *
import models
@@ -243,7 +244,7 @@ wizard_steps = [
('relations-operation_creation', RecordRelationsFormSet),
('abstract-operation_creation', OperationFormAbstract),
('final-operation_creation', FinalForm)]
-if FILES_AVAILABLE:
+if get_current_profile().files:
wizard_steps.insert(0, ('filechoice-operation_creation',
OperationFormFileChoice))
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 6e512e826..c90b6fa8a 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -31,9 +31,7 @@ from ishtar_common.wizards import Wizard, ClosingWizard, DeletionWizard, \
import models
from forms import GenerateDocForm
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-if FILES_AVAILABLE:
- from archaeological_files.models import File
+from archaeological_files.models import File
class OperationWizard(Wizard):
@@ -59,7 +57,7 @@ class OperationWizard(Wizard):
def get_current_file(self):
step = self.steps.current
- if not FILES_AVAILABLE or not step:
+ if not step:
return
file_form_key = 'general-' + self.url_name
if self.url_name == 'operation_creation':
@@ -104,8 +102,6 @@ class OperationWizard(Wizard):
"""
Get available towns
"""
- if not FILES_AVAILABLE:
- return -1
towns = []
file = self.get_current_file()
if not file: