summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-20 15:25:07 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-20 15:25:07 +0200
commitdc7abf75836b59ad33d92da04fe727320400d512 (patch)
treeb26e820671aa6af552a4b03147c44a9d2aa84be8 /archaeological_context_records
parent029d08540f66524c371ae87ede5c1281fbe2c568 (diff)
downloadIshtar-dc7abf75836b59ad33d92da04fe727320400d512.tar.bz2
Ishtar-dc7abf75836b59ad33d92da04fe727320400d512.zip
Djangoization - Major refactoring (step 3)
Reorganization of views, urls, menus, admin, forms. Changes on models.
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/admin.py56
-rw-r--r--archaeological_context_records/forms.py362
-rw-r--r--archaeological_context_records/ishtar_menu.py67
-rw-r--r--archaeological_context_records/migrations/0001_initial.py70
-rw-r--r--archaeological_context_records/models.py49
-rw-r--r--archaeological_context_records/urls.py57
-rw-r--r--archaeological_context_records/views.py36
7 files changed, 594 insertions, 103 deletions
diff --git a/archaeological_context_records/admin.py b/archaeological_context_records/admin.py
new file mode 100644
index 000000000..5985f4462
--- /dev/null
+++ b/archaeological_context_records/admin.py
@@ -0,0 +1,56 @@
+#!/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.contrib import admin
+
+from ishtar_common.admin import HistorizedObjectAdmin
+
+import models
+
+class DatingAdmin(admin.ModelAdmin):
+ list_display = ('period', 'start_date', 'end_date', 'dating_type',
+ 'quality')
+ list_filter = ("period", 'dating_type', 'quality')
+ model = models.Dating
+
+admin.site.register(models.Dating, DatingAdmin)
+
+class ContextRecordAdmin(HistorizedObjectAdmin):
+ list_display = ('label', 'length', 'width',
+ 'thickness', 'depth')
+ list_filter = ('has_furniture',)
+ search_fields = ('parcel__operation__name', "datings__period__label")
+ model = models.ContextRecord
+
+admin.site.register(models.ContextRecord, ContextRecordAdmin)
+
+class ContextRecordSourceAdmin(admin.ModelAdmin):
+ list_display = ('context_record', 'title', 'source_type',)
+ list_filter = ('source_type',)
+ search_fields = ('title', )
+ model = models.ContextRecordSource
+
+admin.site.register(models.ContextRecordSource, ContextRecordSourceAdmin)
+
+basic_models = [models.DatingType, models.DatingQuality,
+ models.Unit, models.ActivityType, models.IdentificationType]
+
+for model in basic_models:
+ admin.site.register(model)
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
new file mode 100644
index 000000000..816782bd8
--- /dev/null
+++ b/archaeological_context_records/forms.py
@@ -0,0 +1,362 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2010-2011 É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.
+
+"""
+Context records forms definitions
+"""
+import datetime
+from itertools import groupby
+
+from django import forms
+from django.core import validators
+from django.core.exceptions import ObjectDoesNotExist
+from django.db.models import Max
+from django.utils.translation import ugettext_lazy as _
+
+from ishtar import settings
+
+import models
+import widgets
+from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard, \
+ formset_factory, get_now, reverse_lazy, get_form_selection
+from forms_common import get_town_field, SourceForm, SourceWizard, \
+ 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"))
+ 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 = \
+ models.Period.get_types()
+ self.fields['datings__period'].help_text = \
+ models.Period.get_help()
+ self.fields['unit'].choices = models.Unit.get_types()
+ self.fields['unit'].help_text = models.Unit.get_help()
+
+class RecordFormSelection(forms.Form):
+ form_label = _("Context record search")
+ associated_models = {'pk':models.ContextRecord}
+ currents = {'pk':models.ContextRecord}
+ pk = forms.IntegerField(label="", required=False,
+ widget=widgets.JQueryJqGrid(reverse_lazy('get-contextrecord'),
+ RecordSelect(), models.ContextRecord,
+ source_full=reverse_lazy('get-contextrecord-full')),
+ validators=[models.valid_id(models.ContextRecord)])
+
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ if 'pk' not in cleaned_data or not cleaned_data['pk']:
+ raise forms.ValidationError(_(u"You should at least select one "
+ u"context record."))
+ return cleaned_data
+
+
+class RecordFormGeneral(forms.Form):
+ form_label = _("General")
+ associated_models = {'parcel':models.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=[])
+ label = forms.CharField(label=_(u"ID"),
+ validators=[validators.MaxLengthValidator(200)])
+ description = forms.CharField(label=_(u"Description"),
+ widget=forms.Textarea, required=False)
+ length = forms.IntegerField(label=_(u"Length (cm)"), required=False)
+ width = forms.IntegerField(label=_(u"Width (cm)"), required=False)
+ thickness = forms.IntegerField(label=_(u"Thickness (cm)"), required=False)
+ depth = forms.IntegerField(label=_(u"Depth (cm)"), required=False)
+ unit = forms.ChoiceField(label=_("Unit"), required=False,
+ choices=models.Unit.get_types())
+ location = forms.CharField(label=_(u"Location"), widget=forms.Textarea,
+ required=False, validators=[validators.MaxLengthValidator(200)])
+
+ def __init__(self, *args, **kwargs):
+ operation = None
+ if 'data' in kwargs and kwargs['data'] and \
+ ('operation' in kwargs['data'] or 'context_record' in kwargs['data']):
+ if 'operation' in kwargs['data']:
+ operation = kwargs['data']['operation']
+ if 'context_record' in kwargs['data'] and \
+ kwargs['data']['context_record']:
+ operation = kwargs['data']['context_record'].operation
+ # clean data if not "real" data
+ prefix_value = kwargs['prefix']
+ if not [k for k in kwargs['data'].keys()
+ if k.startswith(kwargs['prefix']) and kwargs['data'][k]]:
+ kwargs['data'] = None
+ if 'files' in kwargs:
+ kwargs.pop('files')
+ super(RecordFormGeneral, self).__init__(*args, **kwargs)
+ self.fields['parcel'].choices = [('', '--')]
+ if operation:
+ self.fields['operation_id'].initial = operation.pk
+ parcels = operation.parcels.all()
+ sort = lambda x: (x.town.name, x.section)
+ parcels = sorted(parcels, key=sort)
+ for key, gparcels in groupby(parcels, sort):
+ self.fields['parcel'].choices.append(
+ (" - ".join(key), [(parcel.pk, parcel.short_label()) for parcel in gparcels])
+ )
+
+ def clean(self):
+ # manage unique context record ID
+ cleaned_data = self.cleaned_data
+ operation_id = cleaned_data.get("operation_id")
+ label = cleaned_data.get("label")
+ cr = models.ContextRecord.objects.filter(label=label,
+ parcel__operation__pk=operation_id)
+ if 'pk' in cleaned_data and cleaned_data['pk']:
+ cr = cr.exclude(pk=cleaned_data['pk'])
+ if cr.count():
+ raise forms.ValidationError(_(u"This ID already exist for "
+ u"this operation."))
+ return cleaned_data
+
+class DatingForm(forms.Form):
+ form_label = _("Dating")
+ base_model = 'dating'
+ associated_models = {'dating_type':models.DatingType,
+ 'quality':models.DatingQuality,
+ 'period':models.Period}
+ period = forms.ChoiceField(label=_("Period"),
+ choices=models.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,
+ choices=models.DatingQuality.get_types())
+ dating_type = forms.ChoiceField(label=_("Dating type"), required=False,
+ choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(DatingForm, self).__init__(*args, **kwargs)
+ self.fields['dating_type'].choices = models.DatingType.get_types()
+ self.fields['dating_type'].help_text = models.DatingType.get_help()
+
+
+DatingFormSet = formset_factory(DatingForm, can_delete=True,
+ formset=FormSet)
+DatingFormSet.form_label = _("Dating")
+
+class RecordFormInterpretation(forms.Form):
+ form_label = _("Interpretation")
+ associated_models = {'activity':models.ActivityType,
+ 'identification':models.IdentificationType,}
+ has_furniture = forms.NullBooleanField(label=_(u"Has furniture?"),
+ required=False)
+ filling = forms.CharField(label=_(u"Filling"),
+ widget=forms.Textarea, required=False)
+ interpretation = forms.CharField(label=_(u"Interpretation"),
+ widget=forms.Textarea, required=False)
+ activity = forms.ChoiceField(label=_(u"Activity"), required=False,
+ choices=[])
+ identification = forms.ChoiceField(label=_("Identification"),
+ required=False, choices=[])
+ taq = forms.IntegerField(label=_(u"TAQ"), required=False)
+ taq_estimated = forms.IntegerField(label=_(u"Estimated TAQ"),
+ required=False)
+ tpq = forms.IntegerField(label=_(u"TPQ"), required=False)
+ tpq_estimated = forms.IntegerField(label=_(u"Estimated TPQ"),
+ required=False)
+
+ def __init__(self, *args, **kwargs):
+ super(RecordFormInterpretation, self).__init__(*args, **kwargs)
+ self.fields['activity'].choices = models.ActivityType.get_types()
+ self.fields['activity'].help_text = models.ActivityType.get_help()
+ self.fields['identification'].choices = \
+ models.IdentificationType.get_types()
+ 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',
+ _(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"))
+ 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)
+ self.fields['context_record__datings__period'].choices = \
+ models.Period.get_types()
+ self.fields['context_record__datings__period'].help_text = \
+ models.Period.get_help()
+ self.fields['context_record__unit'].choices = models.Unit.get_types()
+ self.fields['context_record__unit'].help_text = models.Unit.get_help()
+
+
+RecordSourceFormSelection = get_form_selection(
+ 'RecordSourceFormSelection', _(u"Documentation search"), 'pk',
+ 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/ishtar_menu.py b/archaeological_context_records/ishtar_menu.py
new file mode 100644
index 000000000..c471a75a8
--- /dev/null
+++ b/archaeological_context_records/ishtar_menu.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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
+# 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.utils.translation import ugettext_lazy as _
+
+from archaeological_operations.models import Operation
+from ishtar_common.menu_base import SectionItem, MenuItem
+
+import models
+
+MENU_SECTIONS = [
+ (40, SectionItem('record_management', _(u"Context record"),
+ childs=[
+ MenuItem('record_search', _(u"Search"),
+ model=models.ContextRecord,
+ access_controls=['view_contextrecord',
+ 'view_own_contextrecord']),
+ MenuItem('record_creation', _(u"Creation"),
+ model=models.ContextRecord,
+ access_controls=['add_contextrecord',
+ 'add_own_contextrecord']),
+ MenuItem('record_modification', _(u"Modification"),
+ model=models.ContextRecord,
+ access_controls=['change_contextrecord',
+ 'change_own_contextrecord']),
+ MenuItem('record_deletion', _(u"Deletion"),
+ model=models.ContextRecord,
+ access_controls=['delete_contextrecord',
+ 'delete_own_contextrecord']),
+ SectionItem('record_source', _(u"Documentation"),
+ childs=[
+ MenuItem('record_source_creation',
+ _(u"Add"),
+ model=models.ContextRecordSource,
+ access_controls=['change_contextrecord',
+ 'change_own_contextrecord']),
+ MenuItem('record_source_modification',
+ _(u"Modification"),
+ model=models.ContextRecordSource,
+ access_controls=['change_contextrecord',
+ 'change_own_contextrecord']),
+ MenuItem('record_source_deletion',
+ _(u"Deletion"),
+ model=models.ContextRecordSource,
+ access_controls=['change_contextrecord',
+ 'change_own_contextrecord']),
+ ])
+ ])
+ )
+]
+
diff --git a/archaeological_context_records/migrations/0001_initial.py b/archaeological_context_records/migrations/0001_initial.py
index 09ee30efe..599a6d4f7 100644
--- a/archaeological_context_records/migrations/0001_initial.py
+++ b/archaeological_context_records/migrations/0001_initial.py
@@ -8,32 +8,6 @@ from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
- # Adding model 'Parcel'
- db.create_table('archaeological_context_records_parcel', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('history_modifier', self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', to=orm['auth.User'])),
- ('history_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
- ('associated_file', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='parcels', null=True, to=orm['archaeological_files.File'])),
- ('operation', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='parcels', null=True, to=orm['archaeological_operations.Operation'])),
- ('year', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
- ('town', self.gf('django.db.models.fields.related.ForeignKey')(related_name='parcels', to=orm['ishtar_common.Town'])),
- ('section', self.gf('django.db.models.fields.CharField')(max_length=4)),
- ('parcel_number', self.gf('django.db.models.fields.CharField')(max_length=6)),
- ))
- db.send_create_signal('archaeological_context_records', ['Parcel'])
-
- # Adding model 'ParcelOwner'
- db.create_table('archaeological_context_records_parcelowner', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('history_modifier', self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', to=orm['auth.User'])),
- ('history_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
- ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['ishtar_common.Person'])),
- ('parcel', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['archaeological_context_records.Parcel'])),
- ('start_date', self.gf('django.db.models.fields.DateField')()),
- ('end_date', self.gf('django.db.models.fields.DateField')()),
- ))
- db.send_create_signal('archaeological_context_records', ['ParcelOwner'])
-
# Adding model 'DatingType'
db.create_table('archaeological_context_records_datingtype', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
@@ -133,7 +107,7 @@ class Migration(SchemaMigration):
db.create_table('archaeological_context_records_contextrecord', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('history_modifier', self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', to=orm['auth.User'])),
- ('parcel', self.gf('django.db.models.fields.related.ForeignKey')(related_name='context_record', to=orm['archaeological_context_records.Parcel'])),
+ ('parcel', self.gf('django.db.models.fields.related.ForeignKey')(related_name='context_record', to=orm['archaeological_operations.Parcel'])),
('operation', self.gf('django.db.models.fields.related.ForeignKey')(related_name='context_record', to=orm['archaeological_operations.Operation'])),
('label', self.gf('django.db.models.fields.CharField')(max_length=200)),
('description', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
@@ -185,12 +159,6 @@ class Migration(SchemaMigration):
def backwards(self, orm):
- # Deleting model 'Parcel'
- db.delete_table('archaeological_context_records_parcel')
-
- # Deleting model 'ParcelOwner'
- db.delete_table('archaeological_context_records_parcelowner')
-
# Deleting model 'DatingType'
db.delete_table('archaeological_context_records_datingtype')
@@ -251,7 +219,7 @@ class Migration(SchemaMigration):
'length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'operation': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'context_record'", 'to': "orm['archaeological_operations.Operation']"}),
- 'parcel': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'context_record'", 'to': "orm['archaeological_context_records.Parcel']"}),
+ 'parcel': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'context_record'", 'to': "orm['archaeological_operations.Parcel']"}),
'taq': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'taq_estimated': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'thickness': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
@@ -333,28 +301,6 @@ class Migration(SchemaMigration):
'order': ('django.db.models.fields.IntegerField', [], {}),
'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
- 'archaeological_context_records.parcel': {
- 'Meta': {'object_name': 'Parcel'},
- 'associated_file': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_files.File']"}),
- 'history_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'operation': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_operations.Operation']"}),
- 'parcel_number': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
- 'section': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
- 'town': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'parcels'", 'to': "orm['ishtar_common.Town']"}),
- 'year': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
- },
- 'archaeological_context_records.parcelowner': {
- 'Meta': {'object_name': 'ParcelOwner'},
- 'end_date': ('django.db.models.fields.DateField', [], {}),
- 'history_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ishtar_common.Person']"}),
- 'parcel': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archaeological_context_records.Parcel']"}),
- 'start_date': ('django.db.models.fields.DateField', [], {})
- },
'archaeological_context_records.unit': {
'Meta': {'object_name': 'Unit'},
'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
@@ -456,6 +402,18 @@ class Migration(SchemaMigration):
'label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'txt_idx': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
+ 'archaeological_operations.parcel': {
+ 'Meta': {'object_name': 'Parcel'},
+ 'associated_file': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_files.File']"}),
+ 'history_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'history_modifier': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'operation': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'parcels'", 'null': 'True', 'to': "orm['archaeological_operations.Operation']"}),
+ 'parcel_number': ('django.db.models.fields.CharField', [], {'max_length': '6'}),
+ 'section': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
+ 'town': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'parcels'", 'to': "orm['ishtar_common.Town']"}),
+ 'year': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+ },
'archaeological_operations.period': {
'Meta': {'object_name': 'Period'},
'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index c47fd3354..75653e78e 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -22,53 +22,8 @@ from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _, ugettext
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
- LightHistorizedItem, HistoricalRecords, OwnPerms, Town, Person, Source
-FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
-if FILES_AVAILABLE:
- from archaeological_files.models import File
-from archaeological_operations.models import Operation, Period
-
-class Parcel(LightHistorizedItem):
- if FILES_AVAILABLE:
- associated_file = models.ForeignKey(File, related_name='parcels',
- blank=True, null=True, verbose_name=_(u"File"))
- operation = models.ForeignKey(Operation, related_name='parcels', blank=True,
- null=True, verbose_name=_(u"Operation"))
- year = models.IntegerField(_(u"Year"), blank=True, null=True)
- town = models.ForeignKey(Town, related_name='parcels',
- verbose_name=_(u"Town"))
- section = models.CharField(_(u"Section"), max_length=4)
- parcel_number = models.CharField(_(u"Parcel number"), max_length=6)
-
- class Meta:
- verbose_name = _(u"Parcel")
- verbose_name_plural = _(u"Parcels")
-
- def short_label(self):
- return JOINT.join([unicode(item) for item in [self.section,
- self.parcel_number] if item])
-
- def __unicode__(self):
- return self.short_label()
-
- def long_label(self):
- items = [unicode(self.operation or self.associated_file)]
- items += [unicode(item) for item in [self.section, self.parcel_number]
- if item]
- return JOINT.join(items)
-
-class ParcelOwner(LightHistorizedItem):
- owner = models.ForeignKey(Person, verbose_name=_(u"Owner"))
- parcel = models.ForeignKey(Parcel, verbose_name=_(u"Parcel"))
- start_date = models.DateField(_(u"Start date"))
- end_date = models.DateField(_(u"End date"))
-
- class Meta:
- verbose_name = _(u"Parcel owner")
- verbose_name_plural = _(u"Parcel owners")
-
- def __unicode__(self):
- return self.owner + JOINT + self.parcel
+ HistoricalRecords, OwnPerms, Town, Person, Source
+from archaeological_operations.models import Operation, Period, Parcel
class DatingType(GeneralType):
class Meta:
diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py
new file mode 100644
index 000000000..c42ae2b02
--- /dev/null
+++ b/archaeological_context_records/urls.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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
+# 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.urls.defaults import *
+"""
+import forms
+
+# forms
+urlpatterns = patterns('',
+ # Context records
+ url(r'record_search/(?P<step>.+)$',
+ forms.record_search_wizard, name='record_search'),
+ url(r'record_creation/(?P<step>.+)$',
+ forms.record_creation_wizard, name='record_creation'),
+ url(r'record_modification/(?P<step>.+)$',
+ forms.record_modification_wizard, name='record_modification'),
+ url(r'record_deletion/(?P<step>.+)$',
+ forms.record_deletion_wizard, name='record_deletion'),
+ url(r'record_source_creation/(?P<step>.+)$',
+ forms.record_source_creation_wizard,
+ name='record_source_creation'),
+ url(r'record_source_modification/(?P<step>.+)$',
+ forms.record_source_modification_wizard,
+ name='record_source_modification'),
+ url(r'record_source_deletion/(?P<step>.+)$',
+ forms.record_source_deletion_wizard,
+ name='record_source_deletion'),
+)
+
+urlpatterns += patterns('archaeological_context_records.views',
+ url(r'show-contextrecord/(?P<pk>.+)?/(?P<type>.+)?$',
+ 'show_contextrecord', name='show-contextrecord'),
+ url(r'get-contextrecord/(?P<type>.+)?$', 'get_contextrecord',
+ name='get-contextrecord'),
+ url(r'get-contextrecord-full/(?P<type>.+)?$',
+ 'get_contextrecord', name='get-contextrecord-full',
+ kwargs={'full':True}),
+ url(r'get-contexrecordsource/(?P<type>.+)?$',
+ 'get_contextrecordsource', name='get-contextrecordsource'),
+)
+"""
diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py
new file mode 100644
index 000000000..89a45482b
--- /dev/null
+++ b/archaeological_context_records/views.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 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
+# 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 ishtar_common.views import get_item, show_item, revert_item
+import models
+
+show_contextrecord = show_item(models.ContextRecord, 'contextrecord')
+get_contextrecord = get_item(models.ContextRecord,
+ 'get_contextrecord', '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',
+ })