Re: error on manipulator fields
I tried the newforms-admin branch - it did not solve the problem. I am now back to revision 7776 of the trunk. I think the problem is in the documentation. It seems like you must add a "get_manipulator_field_objs" method to your customized class. For example, I added: def get_manipulator_field_objs(self): return [oldforms.TextField] You can see examples in django/db/models/fields/__init__.py Chuck --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: error on manipulator fields
nlforms is "from django.contrib.localflavor.nl import forms as nlforms" so these are django's own forms. But now I understand. I hadn't taken notice of the newforms-admin branch. I noticed admin was using oldforms, but did not know what to do about it. I will try newforms-admin branch tonight. If you don't hear back from me, that'll have worked :D Thanks, TiNo On Jun 20, 12:53 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Thu, Jun 19, 2008 at 6:21 PM, TiNo <[EMAIL PROTECTED]> wrote: > > Hi, > > > (Django version 0.97-pre-SVN-7633) > > > I am trying to use a custom modelfield. When I try to ad an entry in > > the admin, i get: > > > --- > > TypeError at /admin/klanten/klant/add/ > > __init__() got an unexpected keyword argument 'is_required' > > > Traceback: > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/core/handlers/base.py" in get_response > > 82. response = callback(request, *callback_args, > > **callback_kwargs) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/contrib/admin/views/decorators.py" in _checklogin > > 62. return view_func(request, *args, **kwargs) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/views/decorators/cache.py" in _wrapped_view_func > > 44. response = view_func(request, *args, **kwargs) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/contrib/admin/views/main.py" in add_stage > > 253. manipulator = model.AddManipulator() > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/db/models/manipulators.py" in __init__ > > 70. > > self.fields.extend(f.get_manipulator_fields(self.opts, self, > > self.change)) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > > site-packages/django/db/models/fields/__init__.py" in > > get_manipulator_fields > > 352. return [man(field_name=field_names[i], **params) for i, > > man in enumerate(field_objs)] > > > Exception Type: TypeError at /admin/klanten/klant/add/ > > Exception Value: __init__() got an unexpected keyword argument > > 'is_require > > - > > > the modelfield is defined as: > > > - > > from django.db.models import * > > from django.contrib.localflavor.nl import forms as nlforms > > from django.core import validators > > from django.newforms.fields import EMPTY_VALUES > > from django.utils.encoding import smart_unicode > > from django import oldforms > > import re > > > phone_re = re.compile('^\+?\d+$') > > > class NLPhoneNumberField(Field): > > >def get_internal_type(self): > >return "CharField" > > >def db_type(self): > >return "char(16)" > > >def to_python(self, value): > >if field_data in EMPTY_VALUES: > >return u'' > > >phone_nr = re.sub('[\-\s\(\)]', '', value) > > >if not phone_re.search(p): > >raise validation.ValidationError('Ongeldig telefoon > > nummer. Voer (evt. +) 10 cijfers in.') > > >if len(phone_nr) == 12: > >if phone_nr[:3] == '+31': > >phone_nr = phone_nr[3:] > >else: > >return phone_nr > >elif len(phone_nr) != 10: > >raise validation.ValidationError('Ongeldig telefoon > > nummer. Voer (evt. +) 10 cijfers in.') > > >if phone_nr[0] == '6': > >return '06 ' + phone_nr[1:] > >else: > >return '%s %s' % (phone_nr[:3],phone_nr[3:]) > > >def get_manipulator_field_objs(self): > >return [nlforms.NLPhoneNumberField] > > >def formfield(self, **kwargs): > >defaults = {'form_class': nlforms.NLPhoneNumberField, > > 'max_length':16} > >defaults.update(kwargs) > >return super(NLPhoneNumberField, self).formfield(**defaults) > > > > > The field is then used in a model without any arguments. > > > The problem disappears when I change: > > > >def get_manipulator_field_objs(self): > >return [nlforms.NLPhoneNumberField] > > > > to: > > > >def get_manipulator_field_objs(self): > >return [oldforms.TextField] > > > > What is nlforms.NLPhoneNumberField? It sounds like it is a custom > newforms-type form field to go with your model field? But > get_manipulator_field_objs is an oldforms-type
Re: error on manipulator fields
On Thu, Jun 19, 2008 at 6:21 PM, TiNo <[EMAIL PROTECTED]> wrote: > Hi, > > (Django version 0.97-pre-SVN-7633) > > I am trying to use a custom modelfield. When I try to ad an entry in > the admin, i get: > > --- > TypeError at /admin/klanten/klant/add/ > __init__() got an unexpected keyword argument 'is_required' > > Traceback: > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/core/handlers/base.py" in get_response > 82. response = callback(request, *callback_args, > **callback_kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/contrib/admin/views/decorators.py" in _checklogin > 62. return view_func(request, *args, **kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/views/decorators/cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/contrib/admin/views/main.py" in add_stage > 253. manipulator = model.AddManipulator() > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/db/models/manipulators.py" in __init__ > 70. > self.fields.extend(f.get_manipulator_fields(self.opts, self, > self.change)) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ > site-packages/django/db/models/fields/__init__.py" in > get_manipulator_fields > 352. return [man(field_name=field_names[i], **params) for i, > man in enumerate(field_objs)] > > Exception Type: TypeError at /admin/klanten/klant/add/ > Exception Value: __init__() got an unexpected keyword argument > 'is_require > - > > the modelfield is defined as: > > > - > from django.db.models import * > from django.contrib.localflavor.nl import forms as nlforms > from django.core import validators > from django.newforms.fields import EMPTY_VALUES > from django.utils.encoding import smart_unicode > from django import oldforms > import re > > phone_re = re.compile('^\+?\d+$') > > class NLPhoneNumberField(Field): > >def get_internal_type(self): >return "CharField" > >def db_type(self): >return "char(16)" > >def to_python(self, value): >if field_data in EMPTY_VALUES: >return u'' > >phone_nr = re.sub('[\-\s\(\)]', '', value) > >if not phone_re.search(p): >raise validation.ValidationError('Ongeldig telefoon > nummer. Voer (evt. +) 10 cijfers in.') > >if len(phone_nr) == 12: >if phone_nr[:3] == '+31': >phone_nr = phone_nr[3:] >else: >return phone_nr >elif len(phone_nr) != 10: >raise validation.ValidationError('Ongeldig telefoon > nummer. Voer (evt. +) 10 cijfers in.') > >if phone_nr[0] == '6': >return '06 ' + phone_nr[1:] >else: >return '%s %s' % (phone_nr[:3],phone_nr[3:]) > >def get_manipulator_field_objs(self): >return [nlforms.NLPhoneNumberField] > >def formfield(self, **kwargs): >defaults = {'form_class': nlforms.NLPhoneNumberField, > 'max_length':16} >defaults.update(kwargs) >return super(NLPhoneNumberField, self).formfield(**defaults) > > > The field is then used in a model without any arguments. > > The problem disappears when I change: > >def get_manipulator_field_objs(self): >return [nlforms.NLPhoneNumberField] > > to: > >def get_manipulator_field_objs(self): >return [oldforms.TextField] > > What is nlforms.NLPhoneNumberField? It sounds like it is a custom newforms-type form field to go with your model field? But get_manipulator_field_objs is an oldforms-type thing and isn't going to work when handed a newforms custom field. Have you considered trying the newforms-admin branch? There admin will be using newforms instead of oldforms so you won't have to get the oldforms stuff working for your custom model field, just newforms. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at
error on manipulator fields
Hi, (Django version 0.97-pre-SVN-7633) I am trying to use a custom modelfield. When I try to ad an entry in the admin, i get: --- TypeError at /admin/klanten/klant/add/ __init__() got an unexpected keyword argument 'is_required' Traceback: File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/core/handlers/base.py" in get_response 82. response = callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/views/decorators.py" in _checklogin 62. return view_func(request, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/contrib/admin/views/main.py" in add_stage 253. manipulator = model.AddManipulator() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/manipulators.py" in __init__ 70. self.fields.extend(f.get_manipulator_fields(self.opts, self, self.change)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/db/models/fields/__init__.py" in get_manipulator_fields 352. return [man(field_name=field_names[i], **params) for i, man in enumerate(field_objs)] Exception Type: TypeError at /admin/klanten/klant/add/ Exception Value: __init__() got an unexpected keyword argument 'is_require - the modelfield is defined as: - from django.db.models import * from django.contrib.localflavor.nl import forms as nlforms from django.core import validators from django.newforms.fields import EMPTY_VALUES from django.utils.encoding import smart_unicode from django import oldforms import re phone_re = re.compile('^\+?\d+$') class NLPhoneNumberField(Field): def get_internal_type(self): return "CharField" def db_type(self): return "char(16)" def to_python(self, value): if field_data in EMPTY_VALUES: return u'' phone_nr = re.sub('[\-\s\(\)]', '', value) if not phone_re.search(p): raise validation.ValidationError('Ongeldig telefoon nummer. Voer (evt. +) 10 cijfers in.') if len(phone_nr) == 12: if phone_nr[:3] == '+31': phone_nr = phone_nr[3:] else: return phone_nr elif len(phone_nr) != 10: raise validation.ValidationError('Ongeldig telefoon nummer. Voer (evt. +) 10 cijfers in.') if phone_nr[0] == '6': return '06 ' + phone_nr[1:] else: return '%s %s' % (phone_nr[:3],phone_nr[3:]) def get_manipulator_field_objs(self): return [nlforms.NLPhoneNumberField] def formfield(self, **kwargs): defaults = {'form_class': nlforms.NLPhoneNumberField, 'max_length':16} defaults.update(kwargs) return super(NLPhoneNumberField, self).formfield(**defaults) The field is then used in a model without any arguments. The problem disappears when I change: def get_manipulator_field_objs(self): return [nlforms.NLPhoneNumberField] to: def get_manipulator_field_objs(self): return [oldforms.TextField] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to build manipulator fields in dynamic way?
hi Jaroslaw, I guess you're trying to implement multipage forms. here is the basic ideas: 1. set a 'step' flag in your view function for determine the current step the user is doing 2. use the form manipulator.fields.append(forms.) to dynamically create form's layout base on 'step' 3. while processing to the next step, you could save the form elements' values in two ways as you like: (1) save them in the session/cookie (2) save them by put them into next step form's hidden elements' value 4. in the final step, you do the actual db saving. HTH :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
How to build manipulator fields in dynamic way?
How to create manipulator fields in more dynamic way? For example I have the form, where only one combobox field is displayed in the begining. After submit, another combobox will be displayed. But its content depends on previous choice... How to do it if I have to define all fields in the constructor? (it is executed only once): class Test(forms.Manipulator): def __init__(self): self.fields = ( forms.SelectField(field_name='first', choices=[(1,1), (2,2)]), forms.SelectField(field_name='second', choices=[what_todo]), ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Manipulator fields
On 3/28/06, PythonistL <[EMAIL PROTECTED]> wrote: > > In my program I use something like this: > > # > > ... > > for Field in manipulator.fields: > #do something > print Field >. > .. > # > print Field there > can print the correct value that is e.g. > name="Pieces_4" size="4" value="" maxlength="4" /> > > but because Field is an instance I can not use that in > further processing e.g. > string.replace(Field ,'id=','disabled id=') > > Is there any solution to my problem that is how to replace any text in > the Field? > Thanks for reply > L. > every formfield has a render() method, and the function need a data parameter, so you can use it to get the output html code with the properly data. or just using str(field) to get the html code. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Manipulator fields
PythonistL wrote: > In my program I use something like this: > > # > > ... > > for Field in manipulator.fields: s/F/f/ it's an instance, not a class (Python's convention is to use CamelCase for classes and all_lowers for instances). > #do something > print Field >. > .. > # > print Field there > can print the correct value that is e.g. > name="Pieces_4" size="4" value="" maxlength="4" /> > > but because Field is an instance I can not use that in > further processing e.g. > string.replace(Field ,'id=','disabled id=') use 'disabled="disabled"' (xhtml compatibility) And : this is not "because field is an instance", this is "because field is not a string" (hint: *everything* in Python is an instance). > Is there any solution to my problem that is how to replace any text in > the Field? s/'text in the field'/'string generated by the field's __str__() method'/ Sorry if I look overly pedantic, but correct naming is the prerequisite to correct understanding. Depends on what you're trying to achieve. If you want to get the text generated by the field's __str__() method, modify this text, then use it, you can do something like: tags = [] for field in manipulator.fields: tags.append(str(field).replace('id=', 'disabled="disabled" id=') But this won't impact the field object itself, so further calls to field.__str__ will be as usual. Another solution would be to subclass Fields classes and write your own manipulators, but this would require a lot of (boring) work. Yet another solution solution (and a far better one IMHO) is to take advantage of Python's delegation mechanisms and use the decorator pattern (nb : not tested): class DisabledField(object): def __init__(self, field): self._field = field def __str__(self): return str(self._field).replace('id=', 'disabled="disabled" id=') def __getattr__(self, name): return getattr(self._field, name) for id, field in enumerate(manipulator.fields): manipulator.fields[id] = DisabledField(field) Then you can use your manipulator as usual. My 2 cents... -- bruno desthuilliers développeur [EMAIL PROTECTED] http://www.modulix.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Manipulator fields
In my program I use something like this: # ... for Field in manipulator.fields: #do something print Field . .. # print Field there can print the correct value that is e.g. but because Field is an instance I can not use that in further processing e.g. string.replace(Field ,'id=','disabled id=') Is there any solution to my problem that is how to replace any text in the Field? Thanks for reply L. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---