summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/admin.py14
-rw-r--r--archaeological_operations/forms.py31
-rw-r--r--archaeological_operations/models.py25
-rw-r--r--archaeological_operations/views.py10
4 files changed, 55 insertions, 25 deletions
diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py
index e0d33a13e..c012b00e2 100644
--- a/archaeological_operations/admin.py
+++ b/archaeological_operations/admin.py
@@ -24,8 +24,14 @@ from ishtar_common.admin import HistorizedObjectAdmin, GeneralTypeAdmin
import models
+FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
+
class AdministrativeActAdmin(HistorizedObjectAdmin):
- list_display = ('year', 'index', 'operation', 'associated_file', 'act_type')
+ if FILES_AVAILABLE:
+ list_display = ('year', 'index', 'operation', 'associated_file',
+ 'act_type')
+ else:
+ list_display = ('year', 'index', 'operation', 'act_type')
list_filter = ('act_type',)
search_fields = ('year', 'index')
model = models.AdministrativeAct
@@ -69,7 +75,11 @@ class OperationSourceAdmin(admin.ModelAdmin):
admin.site.register(models.OperationSource, OperationSourceAdmin)
class ParcelAdmin(HistorizedObjectAdmin):
- list_display = ('section', 'parcel_number', 'operation', 'associated_file')
+ if FILES_AVAILABLE:
+ list_display = ('section', 'parcel_number', 'operation',
+ 'associated_file')
+ else:
+ list_display = ('section', 'parcel_number', 'operation',)
search_fields = ('operation__name',)
model = models.Parcel
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index d31d5c542..78e5a4ed4 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -35,7 +35,11 @@ from django.utils.safestring import mark_safe
from ishtar_common.models import valid_id, PersonType, Person, Town, \
DocumentTemplate, Organization, OrganizationType
-from archaeological_files.models import File
+
+FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
+
+if FILES_AVAILABLE:
+ from archaeological_files.models import File
import models
from widgets import ParcelWidget, SelectParcelWidget
@@ -292,14 +296,15 @@ class OperationCodeInput(forms.TextInput):
'url':reverse_lazy('get_available_operation_code')}
return mark_safe(rendered + js)
-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)
+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 OperationFormGeneral(forms.Form):
form_label = _(u"General")
@@ -419,9 +424,10 @@ class OperationFormGeneral(forms.Form):
return self.cleaned_data
class OperationFormModifGeneral(OperationFormGeneral):
- currents = {'associated_file':File}
operation_code = forms.IntegerField(label=_(u"Operation code"))
- associated_file = forms.IntegerField(label=_(u"Archaelogical file"),
+ 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)
@@ -435,7 +441,8 @@ class OperationFormModifGeneral(OperationFormGeneral):
OperationFormModifGeneral.associated_models = \
OperationFormGeneral.associated_models.copy()
-OperationFormModifGeneral.associated_models['associated_file'] = File
+if FILES_AVAILABLE:
+ OperationFormModifGeneral.associated_models['associated_file'] = File
class OperationFormPreventive(forms.Form):
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index c7a8c94ac..ca649d2d0 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -134,6 +134,9 @@ class ArchaeologicalSite(BaseHistorizedItem):
class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns',
+ 'start_date', 'excavation_end_date']
+ if FILES_AVAILABLE:
+ TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns',
'associated_file_short_label', 'start_date',
'excavation_end_date']
start_date = models.DateField(_(u"Start date"), null=True, blank=True)
@@ -434,7 +437,7 @@ def operation_post_save(sender, **kwargs):
operation.fnap_financing = fnap_percent
operation.save()
cached_label_changed(sender, **kwargs)
- if operation.associated_file:
+ if FILES_AVAILABLE and operation.associated_file:
operation.associated_file.update_short_menu_class()
post_save.connect(operation_post_save, sender=Operation)
@@ -493,6 +496,9 @@ class ActType(GeneralType):
class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date',
+ 'operation']
+ if FILES_AVAILABLE:
+ TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date',
'associated_file', 'operation']
TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file',
'associated_file.towns',]
@@ -550,9 +556,10 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
)
def __unicode__(self):
- return settings.JOINT.join([unicode(item)
- for item in [self.operation, self.associated_file, self.act_object]
- if item])
+ items = [self.operation, self.act_object]
+ if FILES_AVAILABLE:
+ items = [self.operation, self.associated_file, self.act_object]
+ return settings.JOINT.join([unicode(item) for item in items if item])
full_ref_lbl = _(u"Ref.")
@property
@@ -568,7 +575,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
@property
def towns(self):
- if self.associated_file:
+ if FILES_AVAILABLE and self.associated_file:
return self.associated_file.towns.all()
elif self.operation:
return self.operation.towns.all()
@@ -577,7 +584,8 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
@property
def related_item(self):
- return self.operation if self.operation else self.associated_file
+ return self.operation if self.operation \
+ else FILES_AVAILABLE and self.associated_file
def get_filename(self):
filename = self.related_item.associated_filename
@@ -643,7 +651,7 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
self._get_index()
super(AdministrativeAct, self).save(*args, **kwargs)
- if hasattr(self, 'associated_file') and self.associated_file:
+ if FILES_AVAILABLE and self.associated_file:
self.associated_file.update_has_admin_act()
self.associated_file.update_short_menu_class()
@@ -720,7 +728,8 @@ class Parcel(LightHistorizedItem):
return res
def long_label(self):
- items = [unicode(self.operation or self.associated_file)]
+ items = [unicode(self.operation or
+ (FILES_AVAILABLE and self.associated_file))]
items += [unicode(item) for item in [self.section, self.parcel_number]
if item]
return settings.JOINT.join(items)
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 6e623db88..5e6385de7 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -181,8 +181,7 @@ operation_search_wizard = SearchWizard.as_view([
label=_(u"Operation search"),
url_name='operation_search',)
-operation_creation_wizard = OperationWizard.as_view([
- ('filechoice-operation_creation', OperationFormFileChoice),
+wizard_steps = [
('general-operation_creation', OperationFormGeneral),
('preventive-operation_creation', OperationFormPreventive),
('preventivediag-operation_creation', OperationFormPreventiveDiag),
@@ -192,7 +191,12 @@ operation_creation_wizard = OperationWizard.as_view([
('parcels-operation_creation', SelectedParcelFormSet),
('remains-operation_creation', RemainFormset),
('periods-operation_creation', PeriodFormset),
- ('final-operation_creation', FinalForm)],
+ ('final-operation_creation', FinalForm)]
+if FILES_AVAILABLE:
+ wizard_steps.insert(0, ('filechoice-operation_creation',
+ OperationFormFileChoice))
+
+operation_creation_wizard = OperationWizard.as_view(wizard_steps,
label=_(u"New operation"),
condition_dict={
'preventive-operation_creation':\