diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-06-30 00:52:50 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-06-30 00:52:50 +0200 |
commit | 04911d3534c2ee903ddaf4b831c42e70c3d28986 (patch) | |
tree | 3115a748d06a6dc40dd9aff3b3e59c3fb197108a | |
parent | 78879daeb904ec89a2bb8ea2cdba9b00e228577e (diff) | |
download | Ishtar-04911d3534c2ee903ddaf4b831c42e70c3d28986.tar.bz2 Ishtar-04911d3534c2ee903ddaf4b831c42e70c3d28986.zip |
Sources creation modification and deletion for context records and archaelogical items (closes #497)
-rw-r--r-- | ishtar/ishtar_base/forms_context_records.py | 29 | ||||
-rw-r--r-- | ishtar/ishtar_base/forms_items.py | 143 | ||||
-rw-r--r-- | ishtar/ishtar_base/menus.py | 33 | ||||
-rw-r--r-- | ishtar/ishtar_base/models.py | 7 | ||||
-rw-r--r-- | ishtar/ishtar_base/urls.py | 26 | ||||
-rw-r--r-- | ishtar/ishtar_base/views.py | 15 |
6 files changed, 228 insertions, 25 deletions
diff --git a/ishtar/ishtar_base/forms_context_records.py b/ishtar/ishtar_base/forms_context_records.py index b40f5ae80..35b7b785c 100644 --- a/ishtar/ishtar_base/forms_context_records.py +++ b/ishtar/ishtar_base/forms_context_records.py @@ -34,8 +34,9 @@ from ishtar import settings import models import widgets from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard, \ - formset_factory, get_now, reverse_lazy -from forms_common import get_town_field, SourceForm, SourceWizard + formset_factory, get_now, reverse_lazy, get_form_selection +from forms_common import get_town_field, SourceForm, SourceWizard, \ + SourceSelect, AuthorFormset from forms_operations import OperationFormSelection class RecordWizard(Wizard): @@ -111,11 +112,9 @@ class RecordModifWizard(RecordWizard): class RecordSelect(forms.Form): parcel__town = get_town_field() - operation__year = forms.IntegerField(label=_("Year")) - datings__period = forms.ChoiceField(label=_("Period"), - choices=models.Period.get_types()) - unit = forms.ChoiceField(label=_("Unit type"), - choices=models.Unit.get_types()) + operation__year = forms.IntegerField(label=_(u"Year")) + datings__period = forms.ChoiceField(label=_(u"Period"), choices=[]) + unit = forms.ChoiceField(label=_(u"Unit type"), choices=[]) def __init__(self, *args, **kwargs): super(RecordSelect, self).__init__(*args, **kwargs) self.fields['datings__period'].choices = \ @@ -314,12 +313,14 @@ record_source_creation_wizard = RecordSourceWizard([ url_name='record_source_creation',) class RecordSourceSelect(SourceSelect): - context_record__parcel__town = get_town_field() - context_record__operation__year = forms.IntegerField(label=_(u"Year")) - context_record__datings__period = forms.ChoiceField(label=_(u"Period"), - choices=models.Period.get_types()) - context_record__unit = forms.ChoiceField(label=_(u"Unit type"), - choices=models.Unit.get_types()) + context_record__parcel__town = get_town_field( + label=_(u"Town of the operation")) + context_record__operation__year = forms.IntegerField( + label=_(u"Year of the operation")) + context_record__datings__period = forms.ChoiceField( + label=_(u"Period of the context record"), choices=[]) + context_record__unit = forms.ChoiceField( + label=_(u"Unit type of the context record"), choices=[]) def __init__(self, *args, **kwargs): super(RecordSourceSelect, self).__init__(*args, **kwargs) @@ -333,7 +334,7 @@ class RecordSourceSelect(SourceSelect): RecordSourceFormSelection = get_form_selection( 'RecordSourceFormSelection', _(u"Documentation search"), 'pk', - models.ContextRecordSource, RecordSourceSelect, 'get-recordsource', + models.ContextRecordSource, RecordSourceSelect, 'get-contextrecordsource', _(u"You should select a document.")) record_source_modification_wizard = RecordSourceWizard([ diff --git a/ishtar/ishtar_base/forms_items.py b/ishtar/ishtar_base/forms_items.py index b6da0f889..7e3047741 100644 --- a/ishtar/ishtar_base/forms_items.py +++ b/ishtar/ishtar_base/forms_items.py @@ -33,9 +33,10 @@ from ishtar import settings import models import widgets -from forms import Wizard, FinalForm, FormSet, SearchWizard, FloatField,\ - formset_factory, get_now, reverse_lazy -from forms_common import get_town_field +from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard,\ + FloatField, formset_factory, get_now, get_form_selection, reverse_lazy +from forms_common import get_town_field, SourceForm, SourceWizard, \ + SourceSelect, SourceDeletionForm, AuthorFormset from forms_context_records import RecordFormSelection class ItemWizard(Wizard): @@ -139,14 +140,23 @@ class ItemSelect(forms.Form): label=_(u"Year")) base_items__context_record__operation__code_patriarche = \ forms.IntegerField(label=_(u"Code PATRIARCHE")) - dating__period = forms.ChoiceField( - label=_(u"Period"), choices=models.Period.get_types()) + dating__period = forms.ChoiceField(label=_(u"Period"), choices=[]) # TODO search by warehouse - material_type = forms.ChoiceField( - label=_("Material type"), choices=models.MaterialType.get_types()) + material_type = forms.ChoiceField(label=_(u"Material type"), choices=[]) base_items__item__description = forms.CharField(label=_(u"Description")) base_items__is_isolated = forms.NullBooleanField(label=_(u"Is isolated?")) + def __init__(self, *args, **kwargs): + super(ItemSelect, self).__init__(*args, **kwargs) + self.fields['dating__period'].choices = \ + models.Period.get_types() + self.fields['dating__period'].help_text = \ + models.Period.get_help() + self.fields['material_type'].choices = \ + models.MaterialType.get_types() + self.fields['material_type'].help_text = \ + models.MaterialType.get_help() + class ItemFormSelection(forms.Form): form_label = _("Item search") associated_models = {'pk':models.Item} @@ -278,3 +288,122 @@ treatment_creation_wizard = TreatmentWizard([ }, url_name='treatment_creation',) +############################################# +# Source management for archaelogical items # +############################################# + +class ItemSourceWizard(SourceWizard): + model = models.ItemSource + +SourceItemFormSelection = get_form_selection( + 'SourceItemFormSelection', _(u"Archaelogical item search"), 'item', + models.Item, ItemSelect, 'get-item', + _(u"You should select an archaelogical item.")) + +item_source_creation_wizard = ItemSourceWizard([ + ('selec-item_source_creation', SourceItemFormSelection), + ('source-item_source_creation', SourceForm), + ('authors-item_source_creation', AuthorFormset), + ('final-item_source_creation', FinalForm)], + url_name='item_source_creation',) + +class ItemSourceSelect(SourceSelect): + item__base_items__context_record__operation__year = forms.IntegerField( + label=_(u"Year of the operation")) + item__dating__period = forms.ChoiceField( + label=_(u"Period of the archaelogical item"), + choices=[]) + item__material_type = forms.ChoiceField( + label=_("Material type of the archaelogical item"), + choices=models.MaterialType.get_types()) + item__description = forms.CharField( + label=_(u"Description of the archaelogical item")) + + def __init__(self, *args, **kwargs): + super(ItemSourceSelect, self).__init__(*args, **kwargs) + self.fields['item__dating__period'].choices = \ + models.Period.get_types() + self.fields['item__dating__period'].help_text = \ + models.Period.get_help() + self.fields['item__material_type'].choices = \ + models.MaterialType.get_types() + self.fields['item__material_type'].help_text = \ + models.MaterialType.get_help() + +ItemSourceFormSelection = get_form_selection( + 'ItemSourceFormSelection', _(u"Documentation search"), 'pk', + models.ItemSource, ItemSourceSelect, 'get-itemsource', + _(u"You should select a document.")) + +item_source_modification_wizard = ItemSourceWizard([ + ('selec-item_source_modification', ItemSourceFormSelection), + ('source-item_source_modification', SourceForm), + ('authors-item_source_modification', AuthorFormset), + ('final-item_source_modification', FinalForm)], + url_name='item_source_modification',) + +class ItemSourceDeletionWizard(DeletionWizard): + model = models.ItemSource + fields = ['item', 'title', 'source_type', 'authors',] + +item_source_deletion_wizard = ItemSourceDeletionWizard([ + ('selec-item_source_deletion', ItemSourceFormSelection), + ('final-item_source_deletion', SourceDeletionForm)], + url_name='item_source_deletion',) + +""" + +#################################### +# Source management for treatments # +#################################### + +class TreatmentSourceWizard(SourceWizard): + model = models.TreamentSource + +SourceTreatementFormSelection = get_form_selection( + 'SourceTreatmentFormSelection', _(u"Treatment search"), 'operation', + models.Treatment, TreatmentSelect, 'get-treatment', + _(u"You should select a treatment.")) + +treatment_source_creation_wizard = TreatmentSourceWizard([ + ('selec-treatment_source_creation', SourceTreatmentFormSelection), + ('source-treatment_source_creation', SourceForm), + ('authors-treatment_source_creation', AuthorFormset), + ('final-treatment_source_creation', FinalForm)], + url_name='treatment_source_creation',) + +class TreatmentSourceSelect(SourceSelect): + operation__towns = get_town_field(label=_(u"Operation's town")) + treatment__treatment_type = forms.ChoiceField(label=_(u"Operation type"), + choices=[]) + operation__year = forms.IntegerField(label=_(u"Operation's year")) + + def __init__(self, *args, **kwargs): + super(OperationSourceSelect, self).__init__(*args, **kwargs) + self.fields['operation__operation_type'].choices = \ + models.OperationType.get_types() + self.fields['operation__operation_type'].help_text = \ + models.OperationType.get_help() + + +OperationSourceFormSelection = get_form_selection( + 'OperationSourceFormSelection', _(u"Documentation search"), 'pk', + models.OperationSource, OperationSourceSelect, 'get-operationsource', + _(u"You should select a document.")) + +operation_source_modification_wizard = OperationSourceWizard([ + ('selec-operation_source_modification', OperationSourceFormSelection), + ('source-operation_source_modification', SourceForm), + ('authors-operation_source_modification', AuthorFormset), + ('final-operation_source_modification', FinalForm)], + url_name='operation_source_modification',) + +class OperationSourceDeletionWizard(DeletionWizard): + model = models.OperationSource + fields = ['operation', 'title', 'source_type', 'authors',] + +operation_source_deletion_wizard = OperationSourceDeletionWizard([ + ('selec-operation_source_deletion', OperationSourceFormSelection), + ('final-operation_source_deletion', SourceDeletionForm)], + url_name='operation_source_deletion',) +""" diff --git a/ishtar/ishtar_base/menus.py b/ishtar/ishtar_base/menus.py index f229e32f1..3d19e5b88 100644 --- a/ishtar/ishtar_base/menus.py +++ b/ishtar/ishtar_base/menus.py @@ -213,10 +213,21 @@ class Menu: childs=[ SectionItem('admin_add_sources', _(u"Add"), childs=[ - MenuItem('operation_source_add', _(u"Related to an operation"), + MenuItem('operation_source_creation', + _(u"Related to an operation"), model=models.OperationSource, access_controls=['change_operation', 'change_own_operation']), + MenuItem('record_source_creation', + _(u"Related to a context record"), + model=models.ContextRecordSource, + access_controls=['change_contextrecord', + 'change_own_contextrecord']), + MenuItem('item_source_creation', + _(u"Related to an archaelogical item"), + model=models.ItemSource, + access_controls=['change_item', + 'change_own_item']), ]), SectionItem('admin_mod_sources', _(u"Modify"), childs=[ @@ -225,6 +236,16 @@ class Menu: model=models.OperationSource, access_controls=['change_operation', 'change_own_operation']), + MenuItem('record_source_modification', + _(u"Related to a context record"), + model=models.ContextRecordSource, + access_controls=['change_contextrecord', + 'change_own_contextrecord']), + MenuItem('item_source_modification', + _(u"Related to an archaelogical item"), + model=models.ItemSource, + access_controls=['change_item', + 'change_own_item']), ]), SectionItem('admin_del_sources', _(u"Deletion"), childs=[ @@ -233,6 +254,16 @@ class Menu: model=models.OperationSource, access_controls=['change_operation', 'change_own_operation']), + MenuItem('record_source_deletion', + _(u"Related to a context record"), + model=models.ContextRecordSource, + access_controls=['change_contextrecord', + 'change_own_contextrecord']), + MenuItem('item_source_deletion', + _(u"Related to an archaelogical item"), + model=models.ItemSource, + access_controls=['change_item', + 'change_own_item']), ]), ]), SectionItem('warehouse', _(u"Warehouse"), diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index 8ae0af0f1..0f3cb8a8b 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -144,6 +144,9 @@ class GeneralType(models.Model): c_rank = -1 help_items = u"\n" for item in cls.get_types(dct=dct, instances=True): + if hasattr(item, '__iter__'): + # TODO: manage multiple levels + continue if not item.comment: continue if c_rank > item.rank: @@ -156,7 +159,9 @@ class GeneralType(models.Model): c_rank += 1 if c_rank: help_items += c_rank*u"</dl>" - return mark_safe(help_text + help_items) + if help_text or help_items != u'\n': + return mark_safe(help_text + help_items) + return u"" @classmethod def get_types(cls, dct={}, instances=False): diff --git a/ishtar/ishtar_base/urls.py b/ishtar/ishtar_base/urls.py index 60bee05b6..a45211c8b 100644 --- a/ishtar/ishtar_base/urls.py +++ b/ishtar/ishtar_base/urls.py @@ -92,6 +92,15 @@ urlpatterns = patterns('', ishtar_forms.record_modification_wizard, name='record_modification'), url(BASE_URL + r'record_deletion/(?P<step>.+)$', ishtar_forms.record_deletion_wizard, name='record_deletion'), + url(BASE_URL + r'record_source_creation/(?P<step>.+)$', + ishtar_forms.record_source_creation_wizard, + name='record_source_creation'), + url(BASE_URL + r'record_source_modification/(?P<step>.+)$', + ishtar_forms.record_source_modification_wizard, + name='record_source_modification'), + url(BASE_URL + r'record_source_deletion/(?P<step>.+)$', + ishtar_forms.record_source_deletion_wizard, + name='record_source_deletion'), # Finds url(BASE_URL + r'item_search/(?P<step>.+)$', ishtar_forms.item_search_wizard, name='item_search'), @@ -101,6 +110,15 @@ urlpatterns = patterns('', ishtar_forms.item_modification_wizard, name='item_modification'), url(BASE_URL + r'treatment_creation/(?P<step>.+)$', ishtar_forms.treatment_creation_wizard, name='treatment_creation'), + url(BASE_URL + r'item_source_creation/(?P<step>.+)$', + ishtar_forms.item_source_creation_wizard, + name='item_source_creation'), + url(BASE_URL + r'item_source_modification/(?P<step>.+)$', + ishtar_forms.item_source_modification_wizard, + name='item_source_modification'), + url(BASE_URL + r'item_source_deletion/(?P<step>.+)$', + ishtar_forms.item_source_deletion_wizard, + name='item_source_deletion'), ) for section in menu.childs: for menu_item in section.childs: @@ -158,16 +176,20 @@ urlpatterns += patterns('ishtar.ishtar_base.views', 'show_operation', name='show-operation'), url(BASE_URL + r'get-administrativeactop/(?P<type>.+)?$', 'get_administrativeactop', name='get-administrativeactop'), + url(BASE_URL + r'get-operationsource/(?P<type>.+)?$', + 'get_operationsource', name='get-operationsource'), # Context records url(BASE_URL + r'show-contextrecord/(?P<pk>.+)?/(?P<type>.+)?$', 'show_contextrecord', name='show-contextrecord'), url(BASE_URL + r'get-contextrecord/(?P<type>.+)?$', 'get_contextrecord', name='get-contextrecord'), + url(BASE_URL + r'get-contexrecordsource/(?P<type>.+)?$', + 'get_contextrecordsource', name='get-contextrecordsource'), # Finds url(BASE_URL + r'update-current-item/$', 'update_current_item', name='update-current-item'), url(BASE_URL + r'get-item/(?P<type>.+)?$', 'get_archaeologicalitem', name='get-item'), - url(BASE_URL + r'get-operationsource/(?P<type>.+)?$', - 'get_operationsource', name='get-operationsource'), + url(BASE_URL + r'get-itemsource/(?P<type>.+)?$', + 'get_itemsource', name='get-itemsource'), ) diff --git a/ishtar/ishtar_base/views.py b/ishtar/ishtar_base/views.py index f1d4522ce..a48912eeb 100644 --- a/ishtar/ishtar_base/views.py +++ b/ishtar/ishtar_base/views.py @@ -480,6 +480,14 @@ get_contextrecord = get_item(models.ContextRecord, extra_request_keys={'parcel__town':'parcel__town__pk', 'operation__year':'operation__year__contains', 'datings__period':'datings__period__pk'},) +get_contextrecordsource = get_item(models.ContextRecordSource, + 'get_contextrecordsource', 'contextrecordsource', + extra_request_keys={ + 'context_record__parcel__town':'context_record__parcel__town__pk', + 'context_record__operation__year':'context_record__operation__year', + 'context_record__datings__period':'context_record__datings__period__pk', + 'context_record__unit':'context_record__unit__pk', + }) get_archaeologicalitem = get_item(models.Item, 'get_archaeologicalitem', 'item', bool_fields = ['base_items__is_isolated'], @@ -493,6 +501,13 @@ get_archaeologicalitem = get_item(models.Item, 'dating__period':'dating__period__pk', 'base_items__item__description':'base_items__item__description__icontains', 'base_items__is_isolated':'base_items__is_isolated'}) +get_itemsource = get_item(models.ItemSource, + 'get_itemsource', 'itemsource', + extra_request_keys={ +'item__context_record__operation__year':'item__context_record__operation__year', +'item__dating__period':'item__dating__period__pk', +'item__description':'item__description__icontains', + }) def autocomplete_warehouse(request): if not request.user.has_perm('ishtar_base.view_warehouse', models.Warehouse)\ |