Re: customised generic view

2006-03-28 Thread yml

Thank you Michael,

This make sense now to me, I was expecting to much from it.


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-28 Thread Michael Radziej

yml schrieb:
> Eureka!
 > [...]

:-)

> Based on this, I can tell you that I do not understand at all what the
> following statement is doing.
> manipulator.do_html2python(new_data)

It converts the form data as received from the http POST request 
(strings) into the datatypes for the associated database fields (i.e., 
numbers, dates, etc.)

Michael

--~--~-~--~~~---~--~~
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: customised generic view

2006-03-28 Thread yml

Eureka!

Thank you all for your help and support. After 2 days of test and
fails. here it is the solution:
Here it is the save function which is solving my issue:

def save(self, new_data):
temp = Profile(
user=users.get_object(pk=new_data['user']),
pseudo=new_data['pseudo'],
#gender=new_data['gender'],
#address=new_data['address'],
#phonenumber=new_data['phonenumber'],

#want_to_publised_personal_info=new_data['want_to_publised_personal_info'],
want_to_publised_personal_info= False,

memberShipLevel=memberships.get_object(pk=new_data['memberShipLevel'])
)
#temp.set_localisation(newdata['localisation'])
temp.save()
return temp


Based on this, I can tell you that I do not understand at all what the
following statement is doing.
manipulator.do_html2python(new_data)

Does someone could help me on this?

Thank you again for open sourcing Django.


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread yml

Limodou,

This is what I did and the result is that it hapens in the:

manipulator.save()

So I am going to the same thing in this function in order to see which
satement is causing trouble.


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread yml

Limodou,

This is what I did and the result is that it hapens in the:

manipulator.save()

So I am going to the same thing in this function in order to see which
satement is causing trouble.


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread limodou

On 3/28/06, yml <[EMAIL PROTECTED]> wrote:
>
> Hello Limodou,
>
> ok I read the soucre of the formfield in order to fix the radio_admin
> buton I replace the SelectField by a RadioSelectField the form is now
> properly displayed with radio button.
>
> I agree with you that the error message seems to direct us to a pb of
> template but there the line which is causing me trouble is the line 50
> of my view.py:
> manipulator.save(new_data)
> if this line is commented everything work except that the object is not
> created.  :-)
>
> is there a way to run a view in "Debug Mode" with the debugger going
> line by line to follow my request in the django stack?
>
> do you have any other idea of what can cause this?
> Thank you
>

I'm sorry I don't know how to debug template step by step. And I can
only suggest you that add a pieces of codes each time to see where the
bug occured.

--
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: customised generic view

2006-03-27 Thread yml

Hello Limodou,

ok I read the soucre of the formfield in order to fix the radio_admin
buton I replace the SelectField by a RadioSelectField the form is now
properly displayed with radio button.

I agree with you that the error message seems to direct us to a pb of
template but there the line which is causing me trouble is the line 50
of my view.py:
manipulator.save(new_data)
if this line is commented everything work except that the object is not
created.  :-)

is there a way to run a view in "Debug Mode" with the debugger going
line by line to follow my request in the django stack?

do you have any other idea of what can cause this?
Thank you


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread limodou

On 3/28/06, yml <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> As discussed above I spend mos of my evening learning about
> manipulator. I was pretty happy since it seems much more difficult than
> it is.
> This is what I thaught when I did the couple of examples I found  on
> the web.
>
> So what I did is generate the custom manipulator using the script that
> I found there: http://code.djangoproject.com/wiki/ManipulatorScript
>
> The first trouble I had was with radio_admin. Django for some reason
> was complaining about them. Here it is the message:

I think you can check the forms/__init__.py source code to see all
FormField defined in django and see which parameters used in each
FormField class.

> ++
> TypeError at /profiles/create_manip/
> __init__() got an unexpected keyword argument 'radio_admin'
> Request Method: POST
> Request URL:http://localhost:8000/profiles/create_manip/
> Exception Type: TypeError
> Exception Value:__init__() got an unexpected keyword argument
> 'radio_admin'
> Exception Location:
> 
> E:\instal\django\view_servicealapersonne\votreservice\..\votreservice\announceManager\views.py
> in __init__, line 58
> ++
> So I remove those keyword. Does someone can tell me what I should do to
> solve this?

And I see that SelectField has not a radio_admin parameter existed.


> def save(self, new_data):
> temp = Profile(
> user=new_data['user'],
> pseudo=new_data['pseudo'],
> gender=new_data['gender'],
> address=new_data['address'],
> phonenumber=new_data['phonenumber'],
>
> want_to_publised_personal_info=new_data['want_to_publised_personal_info'],
> memberShipLevel=new_data['memberShipLevel']
> )
> temp.set_localisation(newdata['localisation'])
> temp.save()
> return temp
> =
> prodiles_form.py
> 
>
> {% block content %}
> {% block js %}
> 
> 
>  src="/media/js/admin/RelatedObjectLookups.js">
> 
>  src="/media/js/admin/DateTimeShortcuts.js">
>  src="/media/js/SelectBox.js">
>  src="/media/js/SelectFilter2.js">
>
> {% endblock %}
>
> {% if object %}
> Update Profile:
> {% else %}
> Create a Profile
> {% endif %}
>
> {% if form.has_errors %}
> Please correct the following error{{ form.errors|pluralize }}:
> {% endif %}
>
> 
>   
> User:
> {{ form.user }}
> {% if form.user.errors %}
>   *** {{ form.user.errors|join:", " }}
> {% endif %}
>   
> 
> pseudo:
> {{ form.pseudo }}
> {% if form.pseudo.errors %}
>   *** {{ form.pseudo.errors|join:", " }}
> {% endif %}
>   
>   
> gender:
> {{ form.gender }}
> {% if form.gender.errors %}
>   *** {{ form.gender.errors|join:", " }}
> {% endif %}
>   
>   
> address:
> {{ form.address }}
> {% if form.address.errors %}
>   *** {{ form.address.errors|join:", " }}
> {% endif %}
>   
>   
> phonenumber:
> {{ form.phonenumber }}
> {% if form.phonenumber.errors %}
>   *** {{ form.phonenumber.errors|join:", " }}
> {% endif %}
>   
>   
> want to publised
> personal info:
> {{ form.want_to_publised_personal_info }}
> {% if form.want_to_publised_personal_info.errors %}
>   *** {{ form.want_to_publised_personal_info.errors|join:", " }}
> {% endif %}
>   
>   
> localisation:
> {{ form.localisation }}
> {% if form.localisation.errors %}
>   *** {{ form.localisation.errors|join:", " }}
> {% endif %}
>   
>   
> membership:
> {{ form.memberShipLevel }}
> {% if form.memberShipLevel.errors %}
>   *** {{ form.memberShipLevel.errors|join:", " }}
> {% endif %}
>   
> 
> 
>
> {% endblock %}
>
> ==
> The error I am getting
> ===
> Traceback (most recent call last):
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\servers\basehttp.py",
> line 272, in run
> self.result = application(self.environ, self.start_response)
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\servers\basehttp.py",
> line 615, in __call__
> return self.application(environ, start_response)
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\handlers\wsgi.py",
> line 155, in __call__
> response = self.get_response(request.path, request)
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\handlers\base.py",
> line 109, in get_response
> return self.get_technical_error_response(request)
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\handlers\base.py",
> line 139, in get_technical_error_response
> return debug.technical_500_response(request, *sys.exc_info())
>
>   File
> "c:\python24\lib\site-packages\django-0.91-py2.4.egg\django\views\debug.py",
> line 126, in technical_500_response
> return 

Re: customised generic view

2006-03-27 Thread yml

Hello,

As discussed above I spend mos of my evening learning about
manipulator. I was pretty happy since it seems much more difficult than
it is.
This is what I thaught when I did the couple of examples I found  on
the web.

So what I did is generate the custom manipulator using the script that
I found there: http://code.djangoproject.com/wiki/ManipulatorScript

The first trouble I had was with radio_admin. Django for some reason
was complaining about them. Here it is the message:
++
TypeError at /profiles/create_manip/
__init__() got an unexpected keyword argument 'radio_admin'
Request Method: POST
Request URL:http://localhost:8000/profiles/create_manip/
Exception Type: TypeError
Exception Value:__init__() got an unexpected keyword argument
'radio_admin'
Exception Location:

E:\instal\django\view_servicealapersonne\votreservice\..\votreservice\announceManager\views.py
in __init__, line 58
++
So I remove those keyword. Does someone can tell me what I should do to
solve this?
Once I remove radio_admin everyting seems to work except the statement:
manipulator.save(new_data)

==
The Model
==
class Profile(meta.Model):
user =meta.ForeignKey(User)
pseudo = meta.CharField(maxlength=30,core=True)
gender=
meta.ForeignKey(Gender,radio_admin=True,null=True,blank=True)
address = meta.TextField(maxlength=300,null=True,blank=True)
phonenumber = meta.CharField(maxlength=10,null=True,blank=True)
want_to_publised_personal_info = meta.BooleanField()
#photo = meta.ImageField(upload_to="memberPhoto",null=True)
localisation =
meta.ManyToManyField(Localisation,null=True,blank=True,filter_interface=meta.HORIZONTAL)
memberShipLevel = meta.ForeignKey(Membership,radio_admin=True)
def __repr__(self):
return self.pseudo
class META:
admin = meta.Admin(
fields = (
('General information',{'fields':
('user','localisation')}),
('Online information',{'fields':
('pseudo','memberShipLevel','want_to_publised_personal_info')}),
('Optional information',{'fields':
('gender','address','phonenumber')}),
),
list_display =
('user','pseudo','want_to_publised_personal_info','phonenumber'),
ordering = ['pseudo'],
)



views.py
===

@login_required
def profiles_create_manipulator(request):
manipulator =announceManagerProfileManipulator()
logged_in_user=request.user
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data)
manipulator.save(new_data)
return render_to_response("announceManager/profiles_index")
else:
errors = new_data = {}
form = formfields.FormWrapper(manipulator, new_data, errors)
return render_to_response('announceManager/profiles_form', {'form':
form})

class announceManagerProfileManipulator(formfields.Manipulator):
def __init__(self, pk=None):
self.fields = (
formfields.SelectField(field_name='user', is_required=True,
choices=[('','---')] + [(o.id, o) for o in users.get_list()]),
formfields.TextField(field_name='pseudo', is_required=True,
maxlength=30),
#formfields.SelectField(field_name='gender',
radio_admin=True, choices=[('','---')] + [(o.id, o) for o in
genders.get_list()]),
formfields.SelectField(field_name='gender',
choices=[('','---')] + [(o.id, o) for o in genders.get_list()]),
formfields.TextField(field_name='address', maxlength=300),
formfields.TextField(field_name='phonenumber',
maxlength=10),

formfields.CheckboxField(field_name='want_to_publised_personal_info'),
#formfields.SelectField(field_name='memberShipLevel',
is_required=True, radio_admin=True, choices=[('','---')] + [(o.id,
o) for o in membershiplevels.get_list()]),
formfields.SelectField(field_name='memberShipLevel',
is_required=True, choices=[('','---')] + [(o.id, o) for o in
memberships.get_list()]),
formfields.SelectMultipleField(field_name='localisation',
choices=[(o.id, o) for o in localisations.get_list()]),
)

def save(self, new_data):
temp = Profile(
user=new_data['user'],
pseudo=new_data['pseudo'],
gender=new_data['gender'],
address=new_data['address'],
phonenumber=new_data['phonenumber'],

want_to_publised_personal_info=new_data['want_to_publised_personal_info'],
memberShipLevel=new_data['memberShipLevel']
)
temp.set_localisation(newdata['localisation'])
temp.save()
return temp
=
prodiles_form.py


{% block content %}

Re: customised generic view

2006-03-27 Thread limodou

On 3/27/06, yml <[EMAIL PROTECTED]> wrote:
>
> Hello Limodou,
>
> Thank you this is what I start to understand. The pb is that so far I
> have never try that and it looks pretty difficult. This impression
> might be becous I have never done it.
> This is time to learn...  :-)
> So I will try to implement my first manipulator this evening. My
> objective is to be able to put my application in production in may so I
> think it would be wise to move now to the magic removal branch before
> starting to write too much code.
> What do you think about this?
>
> Thank you
>

Yes, I think so. Because sooner or later, the magic-removal branch
will be released as 0.92 version. And I'm always working on MR branch.

--
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: customised generic view

2006-03-27 Thread Michael Radziej

yml schrieb:
> This look very interesting so what I will do is to install magic
> removal branch this evening and try your recipe.

But: be prepared that if you use this on existing code, you might have 
to change quite a lot. See 
http://code.djangoproject.com/wiki/RemovingTheMagic

--and, it is a kind of moving target. Mostly functional, but here and 
there *are* still serious problems.

I'm not sure if you really have to install the new version. I've only 
used Django with the magic removal branch ;-)

> I have a couple of question before doing that, I want to make sure that
> I have a good understanding of what I should do.
> 
> Could you confirm that "Person" in your code is related to what I call
> Member in my Model?
> What is "pwuse" ? What I would like to do is to add the current logged
> in "User" in the user attribute of my Member and, this at run time.

Yes, People this is a Model. pwuse is just some random stuff, forget 
about it.

> Just to make here it is yet another time my scenario:
> A user is logged in and he want to create a member. (The Member class
> has a foreign key relation to the User class) So What I want to do is
> to create display the from representing the Member minus the user
> field. [This is were I think you method is helping me] 

Yep.

> The user will
> key in all the needed information click on submit.
> My application will add the user, based on the session information,
> then the application will validate the information. If everything is
> fine the application will save/create my member else ask to the end
> user to correct its form.

Well, that's the plain Django route here.

> 
> Thank you for your help and your time.

You're welcome :-)

Michael

--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread yml

Hello Limodou,

Thank you this is what I start to understand. The pb is that so far I
have never try that and it looks pretty difficult. This impression
might be becous I have never done it.
This is time to learn...  :-)
So I will try to implement my first manipulator this evening. My
objective is to be able to put my application in production in may so I
think it would be wise to move now to the magic removal branch before
starting to write too much code.
What do you think about this?

Thank you


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-27 Thread yml

Hi,

I understand your point but for some reason in that case I need a one
to many relationship.
cu


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-26 Thread lawgon

>
> Hello,
>
> what I am trying to do since this morning is to allow my logged in user
> to create Members. As you will see below Member is related to the User
> class by a foreignkey.

convention is to use OneToOneField

kg


--~--~-~--~~~---~--~~
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: customised generic view

2006-03-26 Thread limodou

On 3/27/06, yml <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> what I am trying to do since this morning is to allow my logged in user
> to create Members. As you will see below Member is related to the User
> class by a foreignkey.
> so far I create User, Member using generic view. What I would like to
> do is to remove the user field from the form: "members_form". And this
> is where I am stuck.
> since the user attribute is mandatory for a member.
>
> here it is an abstract of my model:
>
> class Member(meta.Model):
> user =meta.ForeignKey(User)
> pseudo = meta.CharField(maxlength=30,core=True)
> gender=
> meta.ForeignKey(Gender,radio_admin=True,null=True,blank=True)
> address = meta.TextField(maxlength=300,null=True,blank=True)
> phonenumber = meta.CharField(maxlength=10,null=True,blank=True)
> want_to_publised_personal_info = meta.BooleanField()
> #photo = meta.ImageField(upload_to="memberPhoto",null=True)
> localisation =
> meta.ManyToManyField(Localisation,null=True,blank=True,filter_interface=meta.HORIZONTAL)
> memberShipLevel = meta.ForeignKey(Membership,radio_admin=True)
> def __repr__(self):
> return self.pseudo
> class META:
> admin = meta.Admin(
> fields = (
> ('General information',{'fields':
> ('user','localisation')}),
> ('Online information',{'fields':
> ('pseudo','memberShipLevel','want_to_publised_personal_info')}),
> ('Optional information',{'fields':
> ('gender','address','phonenumber')}),
> ),
> list_display =
> ('user','pseudo','want_to_publised_personal_info','phonenumber'),
> ordering = ['pseudo'],
> )
>
>
> so far I am calling my generic view from urls.py like this:
> (r'^members/create/?$',
> 'django.views.generic.create_update.create_object',
> dict(info_dict_members, post_save_redirect="/members/") ),
>
>
> I hope that someone is going to take some times to help me.
>
> thank you
>
> PS: thank you to the authors of django for open sourcing this
> beautifull tool.
>

I think if you don't want to user field in Manipulator you can easily
delete it, just like:

m = model.AddManipulator or model.Changemanipulator(object_id)
del m['user']

But because you are using generic_view, and manipulator is created in
the function, so I think there is no way to do like above. So I think
you had to create a custom manipulator to do that, it's better.

--
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
-~--~~~~--~~--~--~---