Re: form problem

2009-10-18 Thread Michael P. Jung

> I made the change but now the following error appears:
> 'QueryDict' object is not callable

Whops. request.GET is a query dict, so it's of course not callable. I
ment to call get('user_text', '') on the request.GET:

request.GET.get('user_text', '')


--mp

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form problem

2009-10-18 Thread A_Swtos

I made the change but now the following error appears:

'QueryDict' object is not callable


On Oct 18, 6:43 pm, "Michael P. Jung"  wrote:
> First of all may I recommend you to use Django forms:
>
> http://docs.djangoproject.com/en/dev/topics/forms/
>
> > With this method i have the following error:
> > Key 'user_text' not found in 
> >> def view(request):
> >>      user_text = request.GET['user_text']
> >>      return render_to_reponse("html",{'user_text':user_text})
>
> When requesting the view for the first time the request.GET dict will
> not contain a 'user_text'. If you replace request.GET['user_text'] by
> request.GET('user_text', '') it will not raise an exception, but return
> '' (empty string) if no 'user_text' is contained in the GET dict.
>
> Besides it's good practice to use POST for forms, if they're used to
> submit new or modify existing data. That's the reason why the example
> code in the forms documentation always checks for request.method ==
> 'POST' to see if the form is actually being submitted or loaded for the
> first time.
>
> In order to get the idea of POST and GET better you might be best of
> googeling for it and reading up what the HTTP methods are supposted to
> be used for. Rule of thumb: Use POST whenever you're modifying data and
> GET when querying data.
>
> --mp
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form problem

2009-10-18 Thread Michael P. Jung

First of all may I recommend you to use Django forms:

http://docs.djangoproject.com/en/dev/topics/forms/

> With this method i have the following error:
> Key 'user_text' not found in 

>> def view(request):
>>  user_text = request.GET['user_text']
>>  return render_to_reponse("html",{'user_text':user_text})

When requesting the view for the first time the request.GET dict will
not contain a 'user_text'. If you replace request.GET['user_text'] by
request.GET('user_text', '') it will not raise an exception, but return
'' (empty string) if no 'user_text' is contained in the GET dict.

Besides it's good practice to use POST for forms, if they're used to
submit new or modify existing data. That's the reason why the example
code in the forms documentation always checks for request.method ==
'POST' to see if the form is actually being submitted or loaded for the
first time.

In order to get the idea of POST and GET better you might be best of
googeling for it and reading up what the HTTP methods are supposted to
be used for. Rule of thumb: Use POST whenever you're modifying data and
GET when querying data.


--mp

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form problem

2009-10-18 Thread A_Swtos

With this method i have the following error:

Key 'user_text' not found in 

What should i change or add to my code?

On Oct 18, 5:40 pm, Rama Vadakattu  wrote:
> Simple Capture the form variable and send it to another template
>
> def view(request):
>      user_text = request.GET['user_text']
>      return render_to_reponse("html",{'user_text':user_text})
>
> --rama
> On Oct 18, 7:26 pm, A_Swtos  wrote:
>
>
>
> > I have a form like this:
>
> > 
> > Text:
> >      > maxlength="20" />
> > 
> > 
>
> > The user can type into the form whatever wants.If i press the button
> > 'submit' i want to go to a page where it appears what i wrote before.
> > Is this possible without saving it into a database?
> > What is the code that you propose?
> > Im new in django and i would like to tell me all the details that will
> > help me, if you can.
> > Thanks.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form problem

2009-10-18 Thread Rama Vadakattu

Simple Capture the form variable and send it to another template

def view(request):
 user_text = request.GET['user_text']
 return render_to_reponse("html",{'user_text':user_text})

--rama
On Oct 18, 7:26 pm, A_Swtos  wrote:
> I have a form like this:
>
> 
> Text:
>      maxlength="20" />
> 
> 
>
> The user can type into the form whatever wants.If i press the button
> 'submit' i want to go to a page where it appears what i wrote before.
> Is this possible without saving it into a database?
> What is the code that you propose?
> Im new in django and i would like to tell me all the details that will
> help me, if you can.
> Thanks.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



form problem

2009-10-18 Thread A_Swtos

I have a form like this:


Text:





The user can type into the form whatever wants.If i press the button
'submit' i want to go to a page where it appears what i wrote before.
Is this possible without saving it into a database?
What is the code that you propose?
Im new in django and i would like to tell me all the details that will
help me, if you can.
Thanks.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: jquery ajax form problem--Can't render template variables

2009-06-10 Thread Malcolm MacKinnon
Thanks Alex. I'll give it a try. I appreciate your comments.

On Wed, Jun 10, 2009 at 5:49 AM, Alex Robbins  wrote:

>
> I haven't used that form plugin before, but from the documentation it
> looks like the problem is this line:
> target:"#new",
> http://malsup.com/jquery/form/#options-object
> You are asking jQuery to jam the whole response in, just like you are
> seeing. What happens if you take that line out? It looks like it will
> just call your success callback. Watch out though, I think the success
> callback happens whenever you get a 200 response from the server. That
> will happen even if your form is bad. (There will be a 200 response
> with errors in it.) You need to check if the response is good or bad
> based on the text in the response, which would get passed to the
> success callback as response_text)
>
> Anyway, I haven't actually used this library but that is how the
> jquery ajax callbacks work.
>
> Hope that helps,
> Alex
>
> On Jun 9, 6:01 pm, Mac  wrote:
> > I'm new to programming and can't figure out how to properly render the
> > {{comment}} and {{username}} variables in the  element
> > below using jquery and the ajax form plugin. Everything posts to the
> > database just as it should. However, I want to show what gets posted
> > in the template after submission. What happens is the entire html page
> > gets inserted in the  element. The images, everything,
> > gets duplicated as the response_text is inserted. Note that the
> > following code has a lot of simple test scripts I'm attempting to use.
> > My template looks like this:
> > (I'm referencing a javascript file, global.js in the template, which
> > is included below it):
> >
> > {% extends "base.html" %}
> > {%block content %}
> > 
> > 

Re: jquery ajax form problem--Can't render template variables

2009-06-10 Thread Alex Robbins

I haven't used that form plugin before, but from the documentation it
looks like the problem is this line:
target:"#new",
http://malsup.com/jquery/form/#options-object
You are asking jQuery to jam the whole response in, just like you are
seeing. What happens if you take that line out? It looks like it will
just call your success callback. Watch out though, I think the success
callback happens whenever you get a 200 response from the server. That
will happen even if your form is bad. (There will be a 200 response
with errors in it.) You need to check if the response is good or bad
based on the text in the response, which would get passed to the
success callback as response_text)

Anyway, I haven't actually used this library but that is how the
jquery ajax callbacks work.

Hope that helps,
Alex

On Jun 9, 6:01 pm, Mac  wrote:
> I'm new to programming and can't figure out how to properly render the
> {{comment}} and {{username}} variables in the  element
> below using jquery and the ajax form plugin. Everything posts to the
> database just as it should. However, I want to show what gets posted
> in the template after submission. What happens is the entire html page
> gets inserted in the  element. The images, everything,
> gets duplicated as the response_text is inserted. Note that the
> following code has a lot of simple test scripts I'm attempting to use.
> My template looks like this:
> (I'm referencing a javascript file, global.js in the template, which
> is included below it):
>
> {% extends "base.html" %}
> {%block content %}
> 
> 

jquery ajax form problem--Can't render template variables

2009-06-09 Thread Mac

I'm new to programming and can't figure out how to properly render the
{{comment}} and {{username}} variables in the  element
below using jquery and the ajax form plugin. Everything posts to the
database just as it should. However, I want to show what gets posted
in the template after submission. What happens is the entire html page
gets inserted in the  element. The images, everything,
gets duplicated as the response_text is inserted. Note that the
following code has a lot of simple test scripts I'm attempting to use.
My template looks like this:
(I'm referencing a javascript file, global.js in the template, which
is included below it):

{% extends "base.html" %}
{%block content %}



 Welcome to Site
{% include "form.html" %}



This will fade out
Here is the camo image

Users and comments:


{{comment}}
{{username}}



{% if error %}
Errors:
{{error}}
{% endif %}

{% endblock%}



Here is global.js

$(document).ready(function(){
$("div.htm").text("The DOM is now loaded and can be
manipulated.");

 $(":header").css({ background:'#CCC', color:'green' });
  $("img").css({ width:'25%' });
  $("p").bind("click", function(e){
  var str = "( " + e.pageX + ", " + e.pageY + " )";
  $("div.htm").text("Click happened! " + str);
});
$("form.theform").ajaxForm({
clearform: true,
target:"#new",
success: function(response_text, status_text) {
var $inp=$("input.com").val();
var $inpa=$("textarea.comms").val();
$("input.news").val($inp);
$("Hello" + " " + $inp + " " + $inpa + "").appendTo("div.htm");
$("p.hide").hide();

$("input.com").val("");
$("textarea.comms").val("");
alert("ajx working");
alert(response_text);
$("Thanks for your sporthill order!").appendTo("p.inp");
$("div.shw").show("slow");
$('p.inp').fadeOut("slow");
$('#hide').hide();

}
});

 });




view is:
def ajx_form(request):


if form.is_valid:
if request.is_ajax:
name = request.POST.get('name', '')
password = request.POST.get('password', '')
comments=request.POST.get('comment', '')
u=Users.objects.create(user=name,  comment=comments)

return render_to_response('my_ajx.html',
{'username':name,  'comment': comments, 'request':request, },
context_instance=RequestContext(request))
return render_to_response('my_ajx.html', {'error':'You"ve got
errors',   },  context_instance=RequestContext(request))
return render_to_response('my_ajx.html', {'error':'You"ve got
errors',   },  context_instance=RequestContext(request))

Please let me know if you have a solution or any ideas. Thanks!!

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange widget and form problem

2009-05-12 Thread Karen Tracey
On Mon, May 11, 2009 at 8:25 AM, timc3  wrote:

>
> I have just updated to trunk and now I get a problem...


OK, after looking at this a little more closely I'm not sure your shell
session is accurately re-creating whatever problem your real code is
encountering. I also see an error in  your form definition that may be
causing a problem.  First, let's start with the form definition:



class MediaObjectForm(forms.ModelForm):
>class Meta:
>model = MediaObject
>fields = ('path')
>
> Where MediaObject looks like this:
>
> class MediaObject(models.Model):
>name = models.CharField(max_length=256)
>path = models.FileField(_("File"), max_length=256,
> upload_to='tempUpload/')
>mob_mediaitem = models.ForeignKey(MediaItem)
>creation_date = models.DateTimeField(_("Creation date"),
> auto_now_add=True)
>

That "fields = ('path')" looks like an error.  Any tuple with a single
element needs to have a trailing comma after the single element.  Without
the comma your fields attribute is set to the string 'file', not a
single-element tuple containing the string 'file'.  This is a common Python
gotcha.

It's a bit surprising that this error didn't cause a problem sooner.  From a
few tests I tried it appears that what you show below actually worked on
Django prior to r10062.  In r10062 some code was added that iterates over
the elements of fields in Meta, and then you start running into problems
because iterating over ('file') returns 'f','i','l','e', not 'file'.  For a
few revisions the declaration you have there would cause an error on import,
but a fix to another bug changed things so that what you wind up with now
when you instantiate a form declared like this is a form with a fields
dictionary:

{'f': None, 'i': None, 'l': None, 'e': None}

which causes the error you see below in full_clean because none of the
'fields' have actual Field instances associated with them.

In some sense this may be considered a bug introduced into Django, as
something that worked before is now failing, but I doubt it will be fixed by
making the definition as you have it go back to working.  It was a bit of a
bizarre accident that that ever worked.  I think it would be more likely to
be fixed so that the error in your fields definition is more obviously
reported than it is right now.  So, as a first step, I'd fix you definition
and see if things go back to working on current trunk code.

Now as to why I don't think your shell session is accurately re-creating the
real problem you are seeing in you code:

uploading files
> into a filefield so I did an interactive session in shellplus and got
> the following:
>
> In [1]: from testsite.media.forms import MediaObjectForm
>
> In [2]: d = {u'path': "my test image.png"}
>
> In [3]: f = MediaObjectForm(d)
>

You are passing a FileField in the form's data dictionary (1st positional
argument), whereas it's expected to be in the files dictionary (or 2nd
positional argument).  (Further I don't think you could just specify the
file name in the files dictionary -- it needs to be an object that includes
that actual file content, see:
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form).
So the expected response to:


> In [4]: f.is_valid()
>

for a validly-defined form here would be False, as the form's required
'path' field has not been supplied to the form.  Thus I don't think what
you've got in the shell session here accurately recreates your working code,
as I don't see how this could ever work.  But getting it to work in the
shell is beside the point...it's possible that just fixing the fields
definition in your form will fix whatever problem your actual code is
hitting.  If not, we'll need some more details on what your real code is
doing and the failure encountered in order to track down what's going on.

Karen



>
> ---
> AttributeErrorTraceback (most recent call
> last)
>
> /Volumes/PersonalItems/ContentCentre/development/BrokerService/code/
> brokersite/ in ()
>
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/django/forms/forms.py in is_valid(self)
>118 being ignored, returns False.
>119 """
> --> 120 return self.is_bound and not bool(self.errors)
>121
>122 def add_prefix(self, field_name):
>
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/django/forms/forms.py in _get_errors(self)
>109 "Returns an ErrorDict for the data provided for the
> form"
>110 if self._errors is None:
> --> 111 self.full_clean()
>112 return self._errors
>113 errors = property(_get_errors)
>
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/django/forms/forms.py in full_clean(self)
>232 # Each widget type knows how to retrieve its own
> data

Re: Strange widget and form problem

2009-05-11 Thread timc3

> [snip]
>
> "Just updated to trunk" doesn't actually tell us what level you are at.  I
> know there was very recently (within the last couple of hours) a fix made
> for a recent bug introduced in upload file handling.  I do not not if you
> are running with that fix or not.
>
> So first, make sure you are really at latest, so that you have that fix.
> Then, if you are still seeing a problem (since your symptoms don't exactly
> match what I've seen of that bug) it would help if you would do a binary
> search between the revision you had that worked and the latest, to find out
> what changeset, exactly, caused the error.  My wild guess would be r10717,
> so you might first want to compare r10716 behavior with r10717 as that might
> save some time.  Or not, if my guess is wrong...this could be due to
> something completely different.
>
> (The behavior where is_valid first causes an AttributeError and subsequently
> returns True is because the forms code ensures full_clean on the form is
> only called once.  Something in full_clean is causing the AttributeError but
> it isn't called the 2nd time because the first time through it already
> created the _errors dict for the form, which prevents it ever being called
> again.)
>

Well I went back and tried the 1.0.2 release and that worked. The info
I have for the directory is:

URL: http://code.djangoproject.com/svn/django/trunk/django
Repository Root: http://code.djangoproject.com/svn
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 10736

Which file or folder are you more interested in?



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange widget and form problem

2009-05-11 Thread Karen Tracey
On Mon, May 11, 2009 at 8:25 AM, timc3  wrote:

>
> I have just updated to trunk and now I get a problem uploading files
> into a filefield so I did an interactive session in shellplus and got
> the following:
>
[snip]

"Just updated to trunk" doesn't actually tell us what level you are at.  I
know there was very recently (within the last couple of hours) a fix made
for a recent bug introduced in upload file handling.  I do not not if you
are running with that fix or not.

So first, make sure you are really at latest, so that you have that fix.
Then, if you are still seeing a problem (since your symptoms don't exactly
match what I've seen of that bug) it would help if you would do a binary
search between the revision you had that worked and the latest, to find out
what changeset, exactly, caused the error.  My wild guess would be r10717,
so you might first want to compare r10716 behavior with r10717 as that might
save some time.  Or not, if my guess is wrong...this could be due to
something completely different.

(The behavior where is_valid first causes an AttributeError and subsequently
returns True is because the forms code ensures full_clean on the form is
only called once.  Something in full_clean is causing the AttributeError but
it isn't called the 2nd time because the first time through it already
created the _errors dict for the form, which prevents it ever being called
again.)

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange widget and form problem

2009-05-11 Thread timc3

I have just updated to trunk and now I get a problem uploading files
into a filefield so I did an interactive session in shellplus and got
the following:

In [1]: from testsite.media.forms import MediaObjectForm

In [2]: d = {u'path': "my test image.png"}

In [3]: f = MediaObjectForm(d)

In [4]: f.is_valid()
---
AttributeErrorTraceback (most recent call
last)

/Volumes/PersonalItems/ContentCentre/development/BrokerService/code/
brokersite/ in ()

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/django/forms/forms.py in is_valid(self)
118 being ignored, returns False.
119 """
--> 120 return self.is_bound and not bool(self.errors)
121
122 def add_prefix(self, field_name):

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/django/forms/forms.py in _get_errors(self)
109 "Returns an ErrorDict for the data provided for the
form"
110 if self._errors is None:
--> 111 self.full_clean()
112 return self._errors
113 errors = property(_get_errors)

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/django/forms/forms.py in full_clean(self)
232 # Each widget type knows how to retrieve its own
data, because some
233 # widgets split data over several HTML fields.
--> 234 value = field.widget.value_from_datadict
(self.data, self.files, self.add_prefix(name))
235 try:
236 if isinstance(field, FileField):

AttributeError: 'NoneType' object has no attribute 'widget'

In [5]: f.is_valid()
Out[5]: True



As you can see the first time that I use is_valid() I get an
AttributeError. The second time it works. MediaObjectForm looks like:

class MediaObjectForm(forms.ModelForm):
class Meta:
model = MediaObject
fields = ('path')

Where MediaObject looks like this:

class MediaObject(models.Model):
name = models.CharField(max_length=256)
path = models.FileField(_("File"), max_length=256,
upload_to='tempUpload/')
mob_mediaitem = models.ForeignKey(MediaItem)
creation_date = models.DateTimeField(_("Creation date"),
auto_now_add=True)


Not sure why this has started happening right now.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom form problem...

2009-05-06 Thread NicoEchániz

On May 6, 10:47 am, NicoEchániz  wrote:
> On May 6, 8:57 am, Daniel Roseman 
> wrote:
> > On May 6, 5:26 am, NicoEchániz  wrote:
> > > Hello,
>
> > > I have a model which has a ForeignKey to itself. I'm doing this to
> > > represent a hierarchy which I then need to display in the
> > > corresponding select field of my form.
> >[]
> > > You can find the corresponding code snippet 
> > > here:http://dpaste.com/hold/41342/
>
> > Your code in lines 22 onwards is being executed when the form class is
> > defined. So the choices for robro_superior are being set at that
> > point, and not updated.
>
> > To fix this, put this code into an __init__() method. This is called
> > when the form is *instantiated* - so each time, it will get the list
> > fresh from the database.
>
> > class RubroForm(ModelForm):
> >     rubro_superior = ModelChoiceField(queryset=Rubro.objects.all(),
> > required=False)
>
> >     def __init__(self, *args, **kwargs)
> >         super(RubroForm, self).__init__(*args, **kwargs)
> >         r = Rubro.objects.all()
> >         choices = [('', '- - - -')] + [(rubro.id, rubro.jerarquia) for
> > rubro in r]
> >         choices.sort(key=itemgetter(1))
> >         rubro_superior.choices = choices
>
> > --
> > DR.
>
> Daniel,
>
> Thanks for your reply.
> I had already tried this, but there's another problem whith this
> solution. The class attribute rubro_superior seems inaccesible for
> some reason.
>
> I get the error:
> global name 'rubro_superior' is not defined
>
> I've tried changing the offending line:
> rubro_superior.choices = choices
>
> for:
> RubroForm.rubro_superior.choices = choices
> and for:
> self.__class__.rubro_superior.choices = choices
>
> to no avail...
>
> so... the description of the problem seems correct to me, but I can't
> find the way to solve it.
>
> Thanks,
>
> NicoEchániz


solved it after reading:
http://stackoverflow.com/questions/738301/how-to-modify-choices-of-modelmultiplechoicefield

I just needed to access the attribute like this:

self.fields['rubro_superior'].choices = choices

that did it.


Thanks for the help.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom form problem...

2009-05-06 Thread NicoEchániz

On May 6, 8:57 am, Daniel Roseman 
wrote:
> On May 6, 5:26 am, NicoEchániz  wrote:
> > Hello,
>
> > I have a model which has a ForeignKey to itself. I'm doing this to
> > represent a hierarchy which I then need to display in the
> > corresponding select field of my form.
>[]
> > You can find the corresponding code snippet 
> > here:http://dpaste.com/hold/41342/
>

> Your code in lines 22 onwards is being executed when the form class is
> defined. So the choices for robro_superior are being set at that
> point, and not updated.
>
> To fix this, put this code into an __init__() method. This is called
> when the form is *instantiated* - so each time, it will get the list
> fresh from the database.
>
> class RubroForm(ModelForm):
>     rubro_superior = ModelChoiceField(queryset=Rubro.objects.all(),
> required=False)
>
>     def __init__(self, *args, **kwargs)
>         super(RubroForm, self).__init__(*args, **kwargs)
>         r = Rubro.objects.all()
>         choices = [('', '- - - -')] + [(rubro.id, rubro.jerarquia) for
> rubro in r]
>         choices.sort(key=itemgetter(1))
>         rubro_superior.choices = choices
>
> --
> DR.

Daniel,

Thanks for your reply.
I had already tried this, but there's another problem whith this
solution. The class attribute rubro_superior seems inaccesible for
some reason.

I get the error:
global name 'rubro_superior' is not defined

I've tried changing the offending line:
rubro_superior.choices = choices

for:
RubroForm.rubro_superior.choices = choices
and for:
self.__class__.rubro_superior.choices = choices

to no avail...

so... the description of the problem seems correct to me, but I can't
find the way to solve it.


Thanks,

NicoEchániz

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom form problem...

2009-05-06 Thread Daniel Roseman

On May 6, 5:26 am, NicoEchániz  wrote:
> Hello,
>
> I have a model which has a ForeignKey to itself. I'm doing this to
> represent a hierarchy which I then need to display in the
> corresponding select field of my form.
>
> I've come up with a simple custom Form which represents my select
> choices like this:
> -
> level0.a
> level0.a > level1.a
> level0.a > level1.b
> level0.b
>
> etc.
>
> You can find the corresponding code snippet here:http://dpaste.com/hold/41342/
>
> It's all working well but I seem to have some sort of cache or class
> lifespan problem... the thing is that whenever I add a new item it
> does not get displayed in the select choices next time I visit the
> form. I need to reload the page a bunch of times for it to show up.
>
> So, what do I need to do to avoid this behaviour?
>
> Thank you all very much in advance,
> NicoEchániz

Your code in lines 22 onwards is being executed when the form class is
defined. So the choices for robro_superior are being set at that
point, and not updated.

To fix this, put this code into an __init__() method. This is called
when the form is *instantiated* - so each time, it will get the list
fresh from the database.

class RubroForm(ModelForm):
rubro_superior = ModelChoiceField(queryset=Rubro.objects.all(),
required=False)

def __init__(self, *args, **kwargs)
super(RubroForm, self).__init__(*args, **kwargs)
r = Rubro.objects.all()
choices = [('', '- - - -')] + [(rubro.id, rubro.jerarquia) for
rubro in r]
choices.sort(key=itemgetter(1))
rubro_superior.choices = choices

--
DR.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



custom form problem...

2009-05-05 Thread NicoEchániz

Hello,

I have a model which has a ForeignKey to itself. I'm doing this to
represent a hierarchy which I then need to display in the
corresponding select field of my form.

I've come up with a simple custom Form which represents my select
choices like this:
-
level0.a
level0.a > level1.a
level0.a > level1.b
level0.b

etc.

You can find the corresponding code snippet here:
http://dpaste.com/hold/41342/

It's all working well but I seem to have some sort of cache or class
lifespan problem... the thing is that whenever I add a new item it
does not get displayed in the select choices next time I visit the
form. I need to reload the page a bunch of times for it to show up.

So, what do I need to do to avoid this behaviour?

Thank you all very much in advance,
NicoEchániz


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Simple Dynamic Form Problem

2009-03-13 Thread Jacob Kaplan-Moss

On Fri, Mar 13, 2009 at 12:04 PM, Alex G  wrote:
> I knew it was going to be something like this.  I'm sorry to have
> troubled you :-/.

No worries at all. `super()` confuses the hell out of me, too :)

Jacob

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Simple Dynamic Form Problem

2009-03-13 Thread Alex G

/sigh

I knew it was going to be something like this.  I'm sorry to have
troubled you :-/.

Thank you, JKM.

On Mar 12, 9:31 pm, Jacob Kaplan-Moss 
wrote:
> On Wed, Mar 11, 2009 at 11:30 AM,Alex G wrote:
>
> > Having referencedhttp://www.b-list.org/weblog/2008/nov/09/dynamic-forms/,
> > I set about in an attempt to make a dynamic form through a simple
> > change to __init__, but not all is well...
>
> [snip]
> > .        super(RFSInputForm, self).__init__(self, *args, **kwargs)
>
> That's your bug -- you don't need `self` in there -- 
> seehttp://docs.python.org/library/functions.html#superfor more
> information on how `super()` works. That line should
> read`super(RFSInputForm, self).__init__(*args, **kwargs)`
>
> Jacob
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Simple Dynamic Form Problem

2009-03-12 Thread Jacob Kaplan-Moss

On Wed, Mar 11, 2009 at 11:30 AM, Alex G  wrote:
>
> Having referenced http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/,
> I set about in an attempt to make a dynamic form through a simple
> change to __init__, but not all is well...
>
[snip]
> .        super(RFSInputForm, self).__init__(self, *args, **kwargs)

That's your bug -- you don't need `self` in there -- see
http://docs.python.org/library/functions.html#super for more
information on how `super()` works. That line should
read`super(RFSInputForm, self).__init__(*args, **kwargs)`

Jacob

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Simple Dynamic Form Problem

2009-03-11 Thread Alex G

Having referenced http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/,
I set about in an attempt to make a dynamic form through a simple
change to __init__, but not all is well...

My code is simply:

.class RFSInputForm(forms.Form):
.def __init__(self, rfs, *args, **kwargs): #test init to add
add'tl field
.super(RFSInputForm, self).__init__(self, *args, **kwargs)
.self.fields['somefield'] = forms.CharField()

which seems simple enough, but when the form is printed:

.if __name__ == '__main__':
.rfs = RFSInputForm('simple_age')
.print rfs

I get the error:

.Traceback (most recent call last):
.  File "./process/forms.py", line 34, in 
.print rfs
.  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
line 30, in __str__
.return self.__unicode__().encode('utf-8')
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 94, in __unicode__
.return self.as_table()
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 190, in as_table
.return self._html_output(u'%(label)s%(errors)s%
(field)s%(help_text)s', u'%s', '', u'%s', False)
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 139, in _html_output
.top_errors = self.non_field_errors() # Errors that should be
displayed above all fields.
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 206, in non_field_errors
.return self.errors.get(NON_FIELD_ERRORS, self.error_class())
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 111, in _get_errors
.self.full_clean()
.  File "/Library/Python/2.5/site-packages/django/forms/forms.py",
line 225, in full_clean
.value = field.widget.value_from_datadict(self.data, self.files,
self.add_prefix(name))
.  File "/Library/Python/2.5/site-packages/django/forms/widgets.py",
line 170, in value_from_datadict
.return data.get(name, None)
.AttributeError: 'RFSInputForm' object has no attribute 'get'

I'm hoping someone could enlighten me as to what the problem might
be.  I've distilled my experiment to the simplest possible instance,
but the suggestion found at 
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/
does not seem to be working as advertised.  Can anyone detect where
I've gone wrong?

Thanks,

Alex.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



My uppload form problem?

2008-01-24 Thread makkalot

Hi all i use django 0.96.1 version and i'm trying to upload file to server. 
Actually that is not the problem here my dropdown menus gone crazy :)

I got an error that i have not entered a valid choice ! I have did that 
operation hundred times i can not understand whats wron!

Here is my code http://dpaste.com/32363/

If you understand the error help me please :)

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