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 | af719ae697e5b03582b28f8a59eae39524cb8f7f (patch) | |
tree | e106614f06c452a4b879104d6b745b7e710928c1 /ishtar_common | |
parent | 7ccc29e5c41fe8a4a33c803adc4bbbd94d6ad1d7 (diff) | |
download | Ishtar-af719ae697e5b03582b28f8a59eae39524cb8f7f.tar.bz2 Ishtar-af719ae697e5b03582b28f8a59eae39524cb8f7f.zip |
Djangoization - Major refactoring (step 13)
* Fix finds wizards
* Clean-up an unecessary file
Diffstat (limited to 'ishtar_common')
-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 |
4 files changed, 6 insertions, 85 deletions
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): """ |