diff options
-rw-r--r-- | ishtar/__init__.py | 4 | ||||
-rw-r--r-- | ishtar/furnitures/forms.py | 37 | ||||
-rw-r--r-- | ishtar/furnitures/forms_common.py | 79 | ||||
-rw-r--r-- | ishtar/furnitures/forms_files.py | 6 | ||||
-rw-r--r-- | ishtar/furnitures/forms_operations.py | 4 | ||||
-rw-r--r-- | ishtar/furnitures/urls.py | 4 | ||||
-rw-r--r-- | ishtar/furnitures/views.py | 5 | ||||
-rw-r--r-- | ishtar/furnitures/widgets.py | 6 | ||||
-rw-r--r-- | static/js/ishtar.js | 4 |
9 files changed, 99 insertions, 50 deletions
diff --git a/ishtar/__init__.py b/ishtar/__init__.py index 8f70261d2..d73e2ee0b 100644 --- a/ishtar/__init__.py +++ b/ishtar/__init__.py @@ -1,8 +1,10 @@ -# force the retranslation of strings in the registration module +# force the retranslation of generated strings and external module from django.utils.translation import ugettext as _ _(u"username") _(u"email address") _(u"warehouse") +_(u"New warehouse") +_(u"warehouse") if settings.XHTML2ODT_PATH: import sys sys.path.append(settings.XHTML2ODT_PATH) diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index b5d29b7d4..77e2c9b7e 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -70,43 +70,6 @@ regexp_name = re.compile(r'^[\w\- ]+$', re.UNICODE) name_validator = validators.RegexValidator(regexp_name, _(u"Enter a valid name consisting of letters, spaces and hyphens."), 'invalid') -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=models.WarehouseType.get_types()) - 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 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 FinalForm(forms.Form): final = True form_label = _("Confirm") diff --git a/ishtar/furnitures/forms_common.py b/ishtar/furnitures/forms_common.py index 387e8ec17..c62160df6 100644 --- a/ishtar/furnitures/forms_common.py +++ b/ishtar/furnitures/forms_common.py @@ -40,6 +40,70 @@ import widgets from forms import Wizard, FinalForm, FormSet, reverse_lazy, name_validator,\ clean_duplicated +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=models.WarehouseType.get_types()) + 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 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]) + organization_type = forms.ChoiceField(label=_(u"Organization type"), + choices=models.OrganizationType.get_types()) + 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 save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['organization_type'] = models.OrganizationType.objects.get( + pk=dct['organization_type']) + new_item = models.Organization(**dct) + new_item.save() + return new_item + class PersonWizard(Wizard): model = models.Person @@ -67,7 +131,7 @@ class PersonForm(forms.Form): choices=models.PersonType.get_types()) attached_to = forms.IntegerField(label=_("Current organization"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'), - associated_model=models.Organization), + associated_model=models.Organization, new=True), validators=[models.valid_id(models.Organization)], required=False) is_author = forms.BooleanField(label=_(u"Is an author?"), required=False) @@ -78,11 +142,24 @@ class PersonForm(forms.Form): super(PersonForm, self).__init__(*args, **kwargs) self.fields['person_type'].choices = models.PersonType.get_types() + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['person_type'] = models.PersonType.objects.get( + pk=dct['person_type']) + if 'attached_to' in dct and dct['attached_to']: + dct['attached_to'] = models.Organization.objects.get( + pk=dct['attached_to']) + new_item = models.Person(**dct) + new_item.save() + return new_item + person_creation_wizard = PersonWizard([ ('identity-person_creation', PersonForm), ('final-person_creation', FinalForm)], url_name='person_creation',) + person_modification_wizard = PersonWizard([ ('selec-person_modification', PersonFormSelection), ('identity-person_modification', PersonForm), diff --git a/ishtar/furnitures/forms_files.py b/ishtar/furnitures/forms_files.py index 15b289fae..632f1d9f3 100644 --- a/ishtar/furnitures/forms_files.py +++ b/ishtar/furnitures/forms_files.py @@ -158,7 +158,7 @@ class FileFormGeneral(forms.Form): in_charge = forms.IntegerField(label=_("Person in charge"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', args=[models.PersonType.objects.get(txt_idx='sra_agent').pk]), - associated_model=models.Person), + associated_model=models.Person, new=True), validators=[models.valid_id(models.Person)]) year = forms.IntegerField(label=_("Year"), initial=lambda:datetime.datetime.now().year, @@ -211,14 +211,14 @@ class FileFormPreventive(forms.Form): widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=[models.PersonType.objects.get(txt_idx='general_contractor').pk]), - associated_model=models.Person), + associated_model=models.Person, new=True), validators=[models.valid_id(models.Person)]) town_planning_service = forms.IntegerField(required=False, label=_(u"Town planning service"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-organization', args=[models.OrganizationType.objects.get(txt_idx='planning_service').pk]), - associated_model=models.Organization), + associated_model=models.Organization, new=True), validators=[models.valid_id(models.Organization)]) permit_type = forms.ChoiceField(label=_("Permit type"), required=False, choices=models.PermitType.get_types()) diff --git a/ishtar/furnitures/forms_operations.py b/ishtar/furnitures/forms_operations.py index 564d65b0b..c69c62e84 100644 --- a/ishtar/furnitures/forms_operations.py +++ b/ishtar/furnitures/forms_operations.py @@ -223,7 +223,7 @@ class OperationFormGeneral(forms.Form): args=["_".join( [unicode(models.PersonType.objects.get(txt_idx='head_scientist').pk), unicode(models.PersonType.objects.get(txt_idx='sra_agent').pk)])]), - associated_model=models.Person), + associated_model=models.Person, new=True), validators=[models.valid_id(models.Person)], required=False) associated_file = forms.IntegerField(label=_("Archaelogical file"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), @@ -561,7 +561,7 @@ class AdministrativeActOpeForm(forms.Form): choices=models.ActType.get_types(dct={'intented_to':'O'})) signatory = forms.IntegerField(label=_("Signatory"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'), - associated_model=models.Person), + associated_model=models.Person, new=True), validators=[models.valid_id(models.Person)]) act_object = forms.CharField(label=_(u"Object"), max_length=200, widget=forms.Textarea) diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index ee67882cc..6d01923b5 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -139,4 +139,8 @@ urlpatterns += patterns('ishtar.furnitures.views', name='get-item'), url(BASE_URL + r'new-warehouse/(?P<parent_name>.+)?/$', 'new_warehouse', name='new-warehouse'), + url(BASE_URL + r'new-person/(?P<parent_name>.+)?/$', + 'new_person', name='new-person'), + url(BASE_URL + r'new-organization/(?P<parent_name>.+)?/$', + 'new_organization', name='new-organization'), ) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 40e9aeaf0..1bdca3442 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -511,7 +511,7 @@ def new_item(model): not_permitted_msg = ugettext(u"Operation not permitted.") return HttpResponse(not_permitted_msg) frm = getattr(ishtar_forms, model_name + 'Form') - dct = {'title':unicode(_(u'New ')) + unicode(_(model_name.lower()))} + dct = {'title':unicode(_(u'New %s' % model_name.lower()))} if request.method == 'POST': dct['form'] = frm(request.POST) if dct['form'].is_valid(): @@ -523,6 +523,7 @@ def new_item(model): if '_select_' in dct['parent_pk']: parents = dct['parent_pk'].split('_') dct['parent_pk'] = "_".join([parents[0]] + parents[2:]) + print dct return render_to_response('window.html', dct, context_instance=RequestContext(request)) else: @@ -532,6 +533,8 @@ def new_item(model): return func new_warehouse = new_item(models.Warehouse) +new_person = new_item(models.Person) +new_organization = new_item(models.Organization) def action(request, action_slug, obj_id=None, *args, **kwargs): """ diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index 4507a9dd8..596abf784 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -176,9 +176,9 @@ objects.get(pk=value)) new = ''
if self.new:
model_name = self.associated_model._meta.object_name.lower()
- new = u' <a href="#" onclick="open_window(\'%s\');">%s</a>' % \
- (reverse('new-' + model_name, args=[attrs_select['id']]),
- unicode(_(u"Add")))
+ url_new = reverse('new-' + model_name, args=[attrs_select['id']])
+ new = u' <a href="#" onclick="open_window(\'%s\');">%s</a>' % (
+ url_new, unicode(_(u"Add")))
html = u'''<input%(attrs_select)s/>%(new)s\
<input type="hidden"%(attrs_hidden)s/>\
<script type="text/javascript"><!--//
diff --git a/static/js/ishtar.js b/static/js/ishtar.js index 534670cba..04070bc64 100644 --- a/static/js/ishtar.js +++ b/static/js/ishtar.js @@ -71,14 +71,14 @@ function load_url(url){ } function open_window(url){ - var newwindow = window.open(url, 'Ishtar', + var newwindow = window.open(url, '_blank', 'height=400,width=550,scrollbars=yes'); if (window.focus) {newwindow.focus()} return false; } function save_and_close_window(name_label, name_pk, item_name, item_pk){ - var main_page = opener.document.wizard; + var main_page = opener.document; jQuery(main_page).find("#"+name_label).val(item_name); jQuery(main_page).find("#"+name_pk).val(item_pk); opener.focus(); |