diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-21 21:11:48 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-10-21 21:11:48 +0200 |
commit | 4e2c3dcd9dc31221a467a5bb4e727fd06336ea07 (patch) | |
tree | e106614f06c452a4b879104d6b745b7e710928c1 | |
parent | 9b74fc6fbcc6c51dc6e18d33179262d14188fcc5 (diff) | |
download | Ishtar-4e2c3dcd9dc31221a467a5bb4e727fd06336ea07.tar.bz2 Ishtar-4e2c3dcd9dc31221a467a5bb4e727fd06336ea07.zip |
Djangoization - Major refactoring (step 13)
* Fix finds wizards
* Clean-up an unecessary file
-rw-r--r-- | archaeological_finds/forms.py | 31 | ||||
-rw-r--r-- | archaeological_finds/views.py | 46 | ||||
-rw-r--r-- | archaeological_warehouse/forms.py | 87 | ||||
-rw-r--r-- | archaeological_warehouse/urls.py | 4 | ||||
-rw-r--r-- | archaeological_warehouse/views.py | 12 | ||||
-rw-r--r-- | archaeological_warehouse/wizards.py | 2 | ||||
-rw-r--r-- | example_project/urls.py | 3 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 51 | ||||
-rw-r--r-- | ishtar_common/forms_main.py | 26 | ||||
-rw-r--r-- | ishtar_common/urls.py | 1 | ||||
-rw-r--r-- | ishtar_common/views.py | 13 |
11 files changed, 127 insertions, 149 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 9c682b25a..c5480d8a8 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -34,13 +34,13 @@ from django.utils.translation import ugettext_lazy as _ from ishtar_common.models import Person, valid_id, valid_ids from archaeological_operations.models import Period, OperationType from archaeological_context_records.models import DatingType, DatingQuality -from archaeological_warehouse.models import Warehouse, ContainerType, Container +from archaeological_warehouse.models import Warehouse import models from ishtar_common import widgets from ishtar_common.forms import FinalForm, FormSet, FloatField, \ formset_factory, get_now, get_form_selection, reverse_lazy -from ishtar_common.forms_common import get_town_field, get_warehouse_field, \ +from ishtar_common.forms_common import get_town_field, \ SourceForm, SourceSelect, SourceDeletionForm, AuthorFormset from archaeological_context_records.forms import RecordFormSelection @@ -155,33 +155,6 @@ class FindMultipleFormSelection(forms.Form): u"archaeological find.")) return self.cleaned_data -class ContainerForm(forms.Form): - form_label = _(u"Container") - reference = forms.CharField(label=_(u"Reference")) - container_type = forms.ChoiceField(label=_(u"Container type"), choices=[]) - location = forms.IntegerField(label=_(u"Warehouse"), - widget=widgets.JQueryAutoComplete( - reverse_lazy('autocomplete-warehouse'), associated_model=Warehouse, - new=True), - validators=[valid_id(Warehouse)]) - comment = forms.CharField(label=_(u"Comment"), - widget=forms.Textarea, required=False) - - def __init__(self, *args, **kwargs): - super(ContainerForm, self).__init__(*args, **kwargs) - self.fields['container_type'].choices = ContainerType.get_types() - self.fields['container_type'].help_text = ContainerType.get_help() - - def save(self, user): - dct = self.cleaned_data - dct['history_modifier'] = user - dct['container_type'] = ContainerType.objects.get( - pk=dct['container_type']) - dct['location'] = Warehouse.objects.get(pk=dct['location']) - new_item = Container(**dct) - new_item.save() - return new_item - def check_treatment(form_name, type_key, type_list=[], not_type_list=[]): type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk for tpe in type_list] diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index b52e86659..c0ee19c9f 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -68,6 +68,29 @@ find_modification_wizard = FindModificationWizard.as_view([ label=_(u"Find modification"), url_name='find_modification',) +find_source_creation_wizard = FindSourceWizard.as_view([ + ('selec-find_source_creation', SourceFindFormSelection), + ('source-find_source_creation', SourceForm), + ('authors-find_source_creation', AuthorFormset), + ('final-find_source_creation', FinalForm)], + label=_(u"Find: new source"), + url_name='find_source_creation',) + +find_source_modification_wizard = FindSourceWizard.as_view([ + ('selec-find_source_modification', FindSourceFormSelection), + ('source-find_source_modification', SourceForm), + ('authors-find_source_modification', AuthorFormset), + ('final-find_source_modification', FinalForm)], + label=_(u"Find: source modification"), + url_name='find_source_modification',) + +find_source_deletion_wizard = FindSourceDeletionWizard.as_view([ + ('selec-find_source_deletion', FindSourceFormSelection), + ('final-find_source_deletion', SourceDeletionForm)], + label=_(u"Find: source deletion"), + url_name='find_source_deletion',) + +""" treatment_creation_wizard = TreatmentWizard.as_view([ ('basetreatment-treatment_creation', BaseTreatmentForm), ('selecfind-treatment_creation', UpstreamFindFormSelection), @@ -97,28 +120,7 @@ treatment_creation_wizard = TreatmentWizard.as_view([ }, label=_(u"New treatment"), url_name='treatment_creation',) - -find_source_creation_wizard = FindSourceWizard.as_view([ - ('selec-find_source_creation', SourceFindFormSelection), - ('source-find_source_creation', SourceForm), - ('authors-find_source_creation', AuthorFormset), - ('final-find_source_creation', FinalForm)], - label=_(u"Find: new source"), - url_name='find_source_creation',) - -find_source_modification_wizard = FindSourceWizard.as_view([ - ('selec-find_source_modification', FindSourceFormSelection), - ('source-find_source_modification', SourceForm), - ('authors-find_source_modification', AuthorFormset), - ('final-find_source_modification', FinalForm)], - label=_(u"Find: source modification"), - url_name='find_source_modification',) - -find_source_deletion_wizard = FindSourceDeletionWizard.as_view([ - ('selec-find_source_deletion', FindSourceFormSelection), - ('final-find_source_deletion', SourceDeletionForm)], - label=_(u"Find: source deletion"), - url_name='find_source_deletion',) +""" """ treatment_source_creation_wizard = TreatmentSourceWizard.as_view([ diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 33b7ba116..2e1bfcc05 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -20,11 +20,94 @@ import datetime from django import forms +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from ishtar_common.models import Person, valid_id from archaeological_finds.models import TreatmentType import models +from ishtar_common import widgets +from ishtar_common.forms import name_validator, reverse_lazy, get_form_selection +from archaeological_finds.forms import FindMultipleFormSelection + +def get_warehouse_field(label=_(u"Warehouse"), required=True): + # !FIXME hard_link, reverse_lazy doen't seem to work with formsets + url = "/" + settings.URL_PATH + 'autocomplete-warehouse' + widget = widgets.JQueryAutoComplete(url, associated_model=models.Warehouse) + return forms.IntegerField(widget=widget, label=label, required=required, + validators=[valid_id(models.Warehouse)]) + +class WarehouseForm(forms.Form): + name = forms.CharField(label=_(u"Name"), max_length=40, + validators=[name_validator]) + warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"), + choices=[]) + person_in_charge = forms.IntegerField(label=_(u"Person in charge"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-person'), associated_model=models.Person), + validators=[valid_id(models.Person)], + required=False) + comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + required=False) + address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, + required=False) + address_complement = forms.CharField(label=_(u"Address complement"), + widget=forms.Textarea, required=False) + postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + required=False) + town = forms.CharField(label=_(u"Town"), max_length=30, required=False) + country = forms.CharField(label=_(u"Country"), max_length=30, + required=False) + phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) + mobile_phone = forms.CharField(label=_(u"Town"), max_length=18, + required=False) + + def __init__(self, *args, **kwargs): + super(WarehouseForm, self).__init__(*args, **kwargs) + self.fields['warehouse_type'].choices = \ + models.WarehouseType.get_types() + self.fields['warehouse_type'].help_text = \ + models.WarehouseType.get_help() + + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['warehouse_type'] = models.WarehouseType.objects.get( + pk=dct['warehouse_type']) + if 'person_in_charge' in dct and dct['person_in_charge']: + dct['person_in_charge'] = models.Person.objects.get( + pk=dct['person_in_charge']) + new_item = models.Warehouse(**dct) + new_item.save() + return new_item + +class ContainerForm(forms.Form): + form_label = _(u"Container") + reference = forms.CharField(label=_(u"Reference")) + container_type = forms.ChoiceField(label=_(u"Container type"), choices=[]) + location = forms.IntegerField(label=_(u"Warehouse"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse, + new=True), + validators=[valid_id(models.Warehouse)]) + comment = forms.CharField(label=_(u"Comment"), + widget=forms.Textarea, required=False) + + def __init__(self, *args, **kwargs): + super(ContainerForm, self).__init__(*args, **kwargs) + self.fields['container_type'].choices = models.ContainerType.get_types() + self.fields['container_type'].help_text = \ + models.ContainerType.get_help() + + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['container_type'] = models.ContainerType.objects.get( + pk=dct['container_type']) + dct['location'] = models.Warehouse.objects.get(pk=dct['location']) + new_item = models.Container(**dct) + new_item.save() + return new_item class ContainerSelect(forms.Form): location = get_warehouse_field() @@ -62,5 +145,5 @@ class BasePackagingForm(forms.Form): self.fields['treatment_type'].initial = \ TreatmentType.objects.get(txt_idx='packaging').pk -class ItemPackagingFormSelection(ItemMultipleFormSelection): - form_label = _(u"Packaged items") +class FindPackagingFormSelection(FindMultipleFormSelection): + form_label = _(u"Packaged finds") diff --git a/archaeological_warehouse/urls.py b/archaeological_warehouse/urls.py index e91568b1e..2ae27c279 100644 --- a/archaeological_warehouse/urls.py +++ b/archaeological_warehouse/urls.py @@ -23,8 +23,8 @@ import views # forms urlpatterns = patterns('', - url(r'treatment_creation/(?P<step>.+)?$', - views.treatment_creation_wizard, name='treatment_creation'), + #url(r'treatment_creation/(?P<step>.+)?$', + # views.treatment_creation_wizard, name='treatment_creation'), url(r'warehouse_packaging/(?P<step>.+)?$', views.warehouse_packaging_wizard, name='warehouse_packaging'), ) diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index f15220efe..10a7b9bf4 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -24,9 +24,10 @@ from django.http import HttpResponse from django.shortcuts import render_to_response from django.utils.translation import ugettext_lazy as _ -from ishtar_common.views import get_item, show_item, revert_item +from ishtar_common.views import get_item, new_item import models from wizards import * +from ishtar_common.forms import FinalForm from forms import * get_container = get_item(models.Container, @@ -37,8 +38,8 @@ get_container = get_item(models.Container, 'reference':'reference__icontains', }) -new_warehouse = new_item(models.Warehouse) -new_container = new_item(models.Container) +new_warehouse = new_item(models.Warehouse, WarehouseForm) +new_container = new_item(models.Container, ContainerForm) def autocomplete_warehouse(request): if not request.user.has_perm('ishtar_common.view_warehouse', @@ -86,9 +87,10 @@ def autocomplete_container(request): warehouse_packaging_wizard = PackagingWizard.as_view([ ('seleccontainer-packaging', ContainerFormSelection), ('base-packaging', BasePackagingForm), - ('multiselecitems-packaging', ItemPackagingFormSelection), + ('multiselecitems-packaging', FindPackagingFormSelection), ('final-packaging', FinalForm)], - url_name='warehouse_packaging',) + label=_(u"Packaging"), + url_name='warehouse_packaging',) """ warehouse_packaging_wizard = ItemSourceWizard.as_view([ diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py index cbd756bc8..c40894c25 100644 --- a/archaeological_warehouse/wizards.py +++ b/archaeological_warehouse/wizards.py @@ -31,7 +31,7 @@ class PackagingWizard(TreatmentWizard): dct = self.get_extra_model(dct, form_list) obj = self.get_current_saved_object() dct['location'] = dct['container'].location - items = dct.pop('items') + items = dct.pop('finds') treatment = Treatment(**dct) treatment.save() if not hasattr(items, '__iter__'): diff --git a/example_project/urls.py b/example_project/urls.py index f39243cdb..0b72a1bc6 100644 --- a/example_project/urls.py +++ b/example_project/urls.py @@ -15,9 +15,6 @@ urlpatterns = patterns('', APP_LIST = ['archaeological_files', 'archaeological_operations', 'archaeological_context_records', 'archaeological_warehouse', 'archaeological_finds'] -APP_LIST = ['archaeological_files', 'archaeological_operations', - 'archaeological_context_records', - 'archaeological_finds'] for app in APP_LIST: if app in settings.INSTALLED_APPS: urlpatterns += patterns('', diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index ccae0b6d2..34a930e36 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -65,57 +65,6 @@ def get_person_field(label=_(u"Person"), required=True, person_type=None): return forms.IntegerField(widget=widget, label=label, required=required, validators=[models.valid_id(models.Person)]) -def get_warehouse_field(label=_(u"Warehouse"), required=True): - # !FIXME hard_link, reverse_lazy doen't seem to work with formsets - url = "/" + settings.URL_PATH + 'autocomplete-warehouse' - widget = widgets.JQueryAutoComplete(url, associated_model=models.Warehouse) - return forms.IntegerField(widget=widget, label=label, required=required, - validators=[models.valid_id(models.Warehouse)]) - -class WarehouseForm(forms.Form): - name = forms.CharField(label=_(u"Name"), max_length=40, - validators=[name_validator]) - warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"), - choices=[]) - person_in_charge = forms.IntegerField(label=_(u"Person in charge"), - widget=widgets.JQueryAutoComplete( - reverse_lazy('autocomplete-person'), associated_model=models.Person), - validators=[models.valid_id(models.Person)], - required=False) - comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, - required=False) - address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, - required=False) - address_complement = forms.CharField(label=_(u"Address complement"), - widget=forms.Textarea, required=False) - postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, - required=False) - town = forms.CharField(label=_(u"Town"), max_length=30, required=False) - country = forms.CharField(label=_(u"Country"), max_length=30, - required=False) - phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) - mobile_phone = forms.CharField(label=_(u"Town"), max_length=18, - required=False) - - def __init__(self, *args, **kwargs): - super(WarehouseForm, self).__init__(*args, **kwargs) - self.fields['warehouse_type'].choices = \ - models.WarehouseType.get_types() - self.fields['warehouse_type'].help_text = \ - models.WarehouseType.get_help() - - def save(self, user): - dct = self.cleaned_data - dct['history_modifier'] = user - dct['warehouse_type'] = models.WarehouseType.objects.get( - pk=dct['warehouse_type']) - if 'person_in_charge' in dct and dct['person_in_charge']: - dct['person_in_charge'] = models.Person.objects.get( - pk=dct['person_in_charge']) - new_item = models.Warehouse(**dct) - new_item.save() - return new_item - class OrganizationForm(forms.Form): name = forms.CharField(label=_(u"Name"), max_length=40, validators=[name_validator]) diff --git a/ishtar_common/forms_main.py b/ishtar_common/forms_main.py deleted file mode 100644 index 29253f284..000000000 --- a/ishtar_common/forms_main.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 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. - -from forms_common import * -#from forms_files import * -#from forms_operations import * -#from forms_context_records import * -#from forms_items import * -from forms import * - diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 7f82ade2f..cebea1dbe 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -20,7 +20,6 @@ from django.conf.urls.defaults import * from menus import menu -#import forms_main as ishtar_forms import views diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 4f010d866..6c682c932 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -49,11 +49,10 @@ if settings.XHTML2ODT_PATH: from xhtml2odt import xhtml2odt from menus import menu -import forms_main as ishtar_forms from ishtar_common.forms import FinalForm from ishtar_common.forms_common import PersonForm, PersonFormSelection,\ - AccountForm, FinalAccountForm + AccountForm, FinalAccountForm, OrganizationForm, AuthorForm from ishtar_common.wizards import PersonWizard, PersonModifWizard, AccountWizard import models @@ -494,13 +493,13 @@ def autocomplete_author(request): for author in authors]) return HttpResponse(data, mimetype='text/plain') -def new_item(model): +def new_item(model, frm): def func(request, parent_name): model_name = model._meta.object_name if not check_permission(request, 'add_'+model_name.lower()): not_permitted_msg = ugettext(u"Operation not permitted.") return HttpResponse(not_permitted_msg) - frm = getattr(ishtar_forms, model_name + 'Form') + #frm = getattr(ishtar_forms, model_name + 'Form') dct = {'title':unicode(_(u'New %s' % model_name.lower()))} if request.method == 'POST': dct['form'] = frm(request.POST) @@ -521,9 +520,9 @@ def new_item(model): context_instance=RequestContext(request)) return func -new_person = new_item(models.Person) -new_organization = new_item(models.Organization) -new_author = new_item(models.Author) +new_person = new_item(models.Person, PersonForm) +new_organization = new_item(models.Organization, OrganizationForm) +new_author = new_item(models.Author, AuthorForm) def action(request, action_slug, obj_id=None, *args, **kwargs): """ |