diff options
Diffstat (limited to 'archaeological_context_records')
-rw-r--r-- | archaeological_context_records/forms.py | 156 | ||||
-rw-r--r-- | archaeological_context_records/urls.py | 16 | ||||
-rw-r--r-- | archaeological_context_records/views.py | 48 | ||||
-rw-r--r-- | archaeological_context_records/wizards.py | 114 |
4 files changed, 183 insertions, 151 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 816782bd8..983dbb869 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2011 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -31,86 +31,16 @@ from django.utils.translation import ugettext_lazy as _ from ishtar import settings +from ishtar_common.models import valid_id +from archaeological_operations.models import Period, Parcel, Operation import models import widgets -from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard, \ +from forms import FinalForm, FormSet, \ formset_factory, get_now, reverse_lazy, get_form_selection -from forms_common import get_town_field, SourceForm, SourceWizard, \ +from forms_common import get_town_field, SourceForm, \ SourceSelect, AuthorFormset from forms_operations import OperationSelect -class RecordWizard(Wizard): - model = models.ContextRecord - edit = False - - def get_current_operation(self, request, storage): - step = storage.get_current_step() - if not step: - return - if step.endswith('_creation'): # an operation has been selected - main_form_key = 'selec-' + self.url_name - try: - idx = int(self.session_get_value(request, storage, - main_form_key, 'operation_id')) - current_ope = models.Operation.objects.get(pk=idx) - return current_ope - except(TypeError, ValueError, ObjectDoesNotExist): - pass - current_cr = self.get_current_object(request, storage) - if current_cr: - return current_cr.parcel.operation - - def get_template_context(self, request, storage, form=None): - """ - Get the operation "reminder" on top of wizard forms - """ - context = super(RecordWizard, self).get_template_context(request, - storage, form) - operation = self.get_current_operation(request, storage) - if not operation: - return context - items = [] - if hasattr(operation, 'code_patriarche') and operation.code_patriarche: - items.append(unicode(operation.code_patriarche)) - items.append("-".join((unicode(operation.year), - unicode(operation.operation_code)))) - context['reminder'] = _("Current operation: ") + " - ".join(items) - return context - - def get_form(self, request, storage, step=None, data=None, files=None): - """ - Get associated operation - """ - if data: - data = data.copy() - else: - data = {} - if not step: - step = self.determine_step(request, storage) - form = self.get_form_list(request, storage)[step] - - general_form_key = 'general-' + self.url_name - if step.startswith('general-'): - if step.endswith('_creation'): # an operation has been selected - main_form_key = 'selec-' + self.url_name - try: - idx = int(self.session_get_value(request, storage, - main_form_key, 'operation_id')) - current_obj = models.Operation.objects.get(pk=idx) - data['operation'] = current_obj - except(TypeError, ValueError, ObjectDoesNotExist): - pass - else: - current_object = self.get_current_object(request, storage) - data['context_record'] = current_object - form = super(RecordWizard, self).get_form(request, storage, step, data, - files) - return form - -class RecordModifWizard(RecordWizard): - modification = True - model = models.ContextRecord - class RecordSelect(forms.Form): parcel__town = get_town_field() operation__year = forms.IntegerField(label=_(u"Year")) @@ -118,10 +48,8 @@ class RecordSelect(forms.Form): unit = forms.ChoiceField(label=_(u"Unit type"), choices=[]) def __init__(self, *args, **kwargs): super(RecordSelect, self).__init__(*args, **kwargs) - self.fields['datings__period'].choices = \ - models.Period.get_types() - self.fields['datings__period'].help_text = \ - models.Period.get_help() + self.fields['datings__period'].choices = Period.get_types() + self.fields['datings__period'].help_text = Period.get_help() self.fields['unit'].choices = models.Unit.get_types() self.fields['unit'].help_text = models.Unit.get_help() @@ -133,7 +61,7 @@ class RecordFormSelection(forms.Form): widget=widgets.JQueryJqGrid(reverse_lazy('get-contextrecord'), RecordSelect(), models.ContextRecord, source_full=reverse_lazy('get-contextrecord-full')), - validators=[models.valid_id(models.ContextRecord)]) + validators=[valid_id(models.ContextRecord)]) def clean(self): cleaned_data = self.cleaned_data @@ -145,7 +73,7 @@ class RecordFormSelection(forms.Form): class RecordFormGeneral(forms.Form): form_label = _("General") - associated_models = {'parcel':models.Parcel, 'unit':models.Unit} + associated_models = {'parcel':Parcel, 'unit':models.Unit} pk = forms.IntegerField(required=False, widget=forms.HiddenInput) operation_id = forms.IntegerField(widget=forms.HiddenInput) parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) @@ -210,8 +138,7 @@ class DatingForm(forms.Form): associated_models = {'dating_type':models.DatingType, 'quality':models.DatingQuality, 'period':models.Period} - period = forms.ChoiceField(label=_("Period"), - choices=models.Period.get_types()) + period = forms.ChoiceField(label=_("Period"), choices=Period.get_types()) start_date = forms.IntegerField(label=_(u"Start date"), required=False) end_date = forms.IntegerField(label=_(u"End date"), required=False) quality = forms.ChoiceField(label=_("Quality"), required=False, @@ -259,67 +186,25 @@ class RecordFormInterpretation(forms.Form): self.fields['identification'].help_text = \ models.IdentificationType.get_help() -record_search_wizard = SearchWizard([ - ('general-record_search', RecordFormSelection)], - url_name='record_search',) - OperationRecordFormSelection = get_form_selection( 'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', - models.Operation, OperationSelect, 'get-operation', + Operation, OperationSelect, 'get-operation', _(u"You should select an operation.")) -record_creation_wizard = RecordWizard([ - ('selec-record_creation', OperationRecordFormSelection), - ('general-record_creation', RecordFormGeneral), - ('datings-record_creation', DatingFormSet), - ('interpretation-record_creation', RecordFormInterpretation), - ('final-record_creation', FinalForm)], - url_name='record_creation',) - -record_modification_wizard = RecordModifWizard([ - ('selec-record_modification', RecordFormSelection), - ('general-record_modification', RecordFormGeneral), - ('datings-record_modification', DatingFormSet), - ('interpretation-record_modification', RecordFormInterpretation), - ('final-record_modification', FinalForm)], - url_name='record_modification',) - -class RecordDeletionWizard(DeletionWizard): - model = models.ContextRecord - fields = ['label', 'parcel', 'description', 'length', 'width', 'thickness', - 'depth', 'location', 'datings', 'units', 'has_furniture', - 'filling', 'interpretation', 'taq', 'taq_estimated', 'tpq', - 'tpq_estimated'] - class RecordDeletionForm(FinalForm): confirm_msg = " " confirm_end_msg = _(u"Would you like to delete this context record?") -record_deletion_wizard = RecordDeletionWizard([ - ('selec-record_deletion', RecordFormSelection), - ('final-record_deletion', RecordDeletionForm)], - url_name='record_deletion',) - ######################################### # Source management for context records # ######################################### -class RecordSourceWizard(SourceWizard): - model = models.ContextRecordSource - SourceRecordFormSelection = get_form_selection( 'SourceRecordFormSelection', _(u"Context record search"), 'context_record', models.ContextRecord, RecordSelect, 'get-contextrecord', _(u"You should select a context record.")) -record_source_creation_wizard = RecordSourceWizard([ - ('selec-record_source_creation', SourceRecordFormSelection), - ('source-record_source_creation', SourceForm), - ('authors-record_source_creation', AuthorFormset), - ('final-record_source_creation', FinalForm)], - url_name='record_source_creation',) - class RecordSourceSelect(SourceSelect): context_record__parcel__town = get_town_field( label=_(u"Town of the operation")) @@ -333,9 +218,9 @@ class RecordSourceSelect(SourceSelect): def __init__(self, *args, **kwargs): super(RecordSourceSelect, self).__init__(*args, **kwargs) self.fields['context_record__datings__period'].choices = \ - models.Period.get_types() + Period.get_types() self.fields['context_record__datings__period'].help_text = \ - models.Period.get_help() + Period.get_help() self.fields['context_record__unit'].choices = models.Unit.get_types() self.fields['context_record__unit'].help_text = models.Unit.get_help() @@ -345,18 +230,3 @@ RecordSourceFormSelection = get_form_selection( models.ContextRecordSource, RecordSourceSelect, 'get-contextrecordsource', _(u"You should select a document.")) -record_source_modification_wizard = RecordSourceWizard([ - ('selec-record_source_modification', RecordSourceFormSelection), - ('source-record_source_modification', SourceForm), - ('authors-record_source_modification', AuthorFormset), - ('final-record_source_modification', FinalForm)], - url_name='record_source_modification',) - -class RecordSourceDeletionWizard(DeletionWizard): - model = models.ContextRecordSource - fields = ['context_record', 'title', 'source_type', 'authors',] - -record_source_deletion_wizard = RecordSourceDeletionWizard([ - ('selec-record_source_deletion', RecordSourceFormSelection), - ('final-record_source_deletion', RecordDeletionForm)], - url_name='record_source_deletion',) diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index c42ae2b02..1cbf03f12 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -19,27 +19,27 @@ from django.conf.urls.defaults import * """ -import forms +import views # forms urlpatterns = patterns('', # Context records url(r'record_search/(?P<step>.+)$', - forms.record_search_wizard, name='record_search'), + views.record_search_wizard, name='record_search'), url(r'record_creation/(?P<step>.+)$', - forms.record_creation_wizard, name='record_creation'), + views.record_creation_wizard, name='record_creation'), url(r'record_modification/(?P<step>.+)$', - forms.record_modification_wizard, name='record_modification'), + views.record_modification_wizard, name='record_modification'), url(r'record_deletion/(?P<step>.+)$', - forms.record_deletion_wizard, name='record_deletion'), + views.record_deletion_wizard, name='record_deletion'), url(r'record_source_creation/(?P<step>.+)$', - forms.record_source_creation_wizard, + views.record_source_creation_wizard, name='record_source_creation'), url(r'record_source_modification/(?P<step>.+)$', - forms.record_source_modification_wizard, + views.record_source_modification_wizard, name='record_source_modification'), url(r'record_source_deletion/(?P<step>.+)$', - forms.record_source_deletion_wizard, + views.record_source_deletion_wizard, name='record_source_deletion'), ) diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 89a45482b..b1f8ca772 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -18,6 +18,9 @@ # See the file COPYING for details. from ishtar_common.views import get_item, show_item, revert_item +from ishtar_common.wizards import SearchWizard +from wizards import * +from forms import * import models show_contextrecord = show_item(models.ContextRecord, 'contextrecord') @@ -34,3 +37,48 @@ get_contextrecordsource = get_item(models.ContextRecordSource, 'context_record__datings__period':'context_record__datings__period__pk', 'context_record__unit':'context_record__unit__pk', }) + +record_search_wizard = SearchWizard.as_view([ + ('general-record_search', RecordFormSelection)], + url_name='record_search',) + +record_creation_wizard = RecordWizard.as_view([ + ('selec-record_creation', OperationRecordFormSelection), + ('general-record_creation', RecordFormGeneral), + ('datings-record_creation', DatingFormSet), + ('interpretation-record_creation', RecordFormInterpretation), + ('final-record_creation', FinalForm)], + url_name='record_creation',) + +record_modification_wizard = RecordModifWizard.as_view([ + ('selec-record_modification', RecordFormSelection), + ('general-record_modification', RecordFormGeneral), + ('datings-record_modification', DatingFormSet), + ('interpretation-record_modification', RecordFormInterpretation), + ('final-record_modification', FinalForm)], + url_name='record_modification',) + +record_deletion_wizard = RecordDeletionWizard.as_view([ + ('selec-record_deletion', RecordFormSelection), + ('final-record_deletion', RecordDeletionForm)], + url_name='record_deletion',) + +record_source_creation_wizard = RecordSourceWizard.as_view([ + ('selec-record_source_creation', SourceRecordFormSelection), + ('source-record_source_creation', SourceForm), + ('authors-record_source_creation', AuthorFormset), + ('final-record_source_creation', FinalForm)], + url_name='record_source_creation',) + +record_source_modification_wizard = RecordSourceWizard.as_view([ + ('selec-record_source_modification', RecordSourceFormSelection), + ('source-record_source_modification', SourceForm), + ('authors-record_source_modification', AuthorFormset), + ('final-record_source_modification', FinalForm)], + url_name='record_source_modification',) + +record_source_deletion_wizard = RecordSourceDeletionWizard.as_view([ + ('selec-record_source_deletion', RecordSourceFormSelection), + ('final-record_source_deletion', RecordDeletionForm)], + url_name='record_source_deletion',) + diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py new file mode 100644 index 000000000..b14272e16 --- /dev/null +++ b/archaeological_context_records/wizards.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +from django.conf import settings +from django.core.exceptions import ObjectDoesNotExist +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.utils.translation import ugettext_lazy as _ + +from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard +import models + +class RecordWizard(Wizard): + model = models.ContextRecord + edit = False + + def get_current_operation(self, request, storage): + step = storage.get_current_step() + if not step: + return + if step.endswith('_creation'): # an operation has been selected + main_form_key = 'selec-' + self.url_name + try: + idx = int(self.session_get_value(request, storage, + main_form_key, 'operation_id')) + current_ope = models.Operation.objects.get(pk=idx) + return current_ope + except(TypeError, ValueError, ObjectDoesNotExist): + pass + current_cr = self.get_current_object(request, storage) + if current_cr: + return current_cr.parcel.operation + + def get_template_context(self, request, storage, form=None): + """ + Get the operation "reminder" on top of wizard forms + """ + context = super(RecordWizard, self).get_template_context(request, + storage, form) + operation = self.get_current_operation(request, storage) + if not operation: + return context + items = [] + if hasattr(operation, 'code_patriarche') and operation.code_patriarche: + items.append(unicode(operation.code_patriarche)) + items.append("-".join((unicode(operation.year), + unicode(operation.operation_code)))) + context['reminder'] = _("Current operation: ") + " - ".join(items) + return context + + def get_form(self, request, storage, step=None, data=None, files=None): + """ + Get associated operation + """ + if data: + data = data.copy() + else: + data = {} + if not step: + step = self.determine_step(request, storage) + form = self.get_form_list(request, storage)[step] + + general_form_key = 'general-' + self.url_name + if step.startswith('general-'): + if step.endswith('_creation'): # an operation has been selected + main_form_key = 'selec-' + self.url_name + try: + idx = int(self.session_get_value(request, storage, + main_form_key, 'operation_id')) + current_obj = models.Operation.objects.get(pk=idx) + data['operation'] = current_obj + except(TypeError, ValueError, ObjectDoesNotExist): + pass + else: + current_object = self.get_current_object(request, storage) + data['context_record'] = current_object + form = super(RecordWizard, self).get_form(request, storage, step, data, + files) + return form + +class RecordModifWizard(RecordWizard): + modification = True + model = models.ContextRecord + +class RecordDeletionWizard(DeletionWizard): + model = models.ContextRecord + fields = ['label', 'parcel', 'description', 'length', 'width', 'thickness', + 'depth', 'location', 'datings', 'units', 'has_furniture', + 'filling', 'interpretation', 'taq', 'taq_estimated', 'tpq', + 'tpq_estimated'] + +class RecordSourceWizard(SourceWizard): + model = models.ContextRecordSource + +class RecordSourceDeletionWizard(DeletionWizard): + model = models.ContextRecordSource + fields = ['context_record', 'title', 'source_type', 'authors',] + |