Comment Framework and Session Variables

2011-09-21 Thread SixDegrees

I'm using the Django-supplied comment framework, and I would like to
initialize the email field of the comment form with a value stored in a
session variable. The forms, however, are created using template tags; they
aren't instantiated in the view, for example, where I could easily provide
the session value as part of the 'initial' dictionary. I don't see any way
in the template to pass this value along so the form can make use of it. How
can I do this?
-- 
View this message in context: 
http://old.nabble.com/Comment-Framework-and-Session-Variables-tp32503766p32503766.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

OK, thanks. I was on the verge of rolling my own solution anyway.

Form models won't work for me; although the ID I want to pass is a primary
key to a table, I need to rummage around in the database and track down
several bits and pieces; there's not a simple correspondence to one
particular model in this case, sadly. At least I don't think so; I may give
it another look.


Wayne Smith-4 wrote:
> 
> On Aug 19, 1:58 pm, SixDegrees <paulcarli...@comcast.net> wrote:
>> I'm no longer at the computer where my code resides. But "you are wanting
>> to
>> call formset_factory
>> and have it pass along a parameter to the Form that the formset
>> contains" is pretty much what I want to know how to do.
> 
> Well, the short answer is that you can't do that--formset_factory()
> does not accept kwargs.
> 
> Your other option is to basically write your own formset_factory().
> If you look at the source, you will see that it really doesn't do
> anything special--it's more of a convenience method that creates a
> basic FormSet.  You could also write your own Formset, with its own
> custom __init__ method, inherit from BaseFormSet, and pass that to the
> formset_factory() method.  Yeah, that's probably what I would do.
> 
> A good rule of thumb that I have found is that if you are trying to do
> something with Django, and it is either not possible or requires a
> good bit of hackery, then you are probably (although not always)
> "doing it wrong".  Most of Django is very flexible, but sometimes you
> just need to know where to look for the answer.  That's why I was
> inquiring about exactly what your code is doing and such--your use of
> a primary key makes me think (but doesn't guarantee) that you are
> using a form to represent an instance of a model, and if so, you want
> to be looking there.
> 
> Wayne
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32298409.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

I'm no longer at the computer where my code resides. But "you are wanting to
call formset_factory
and have it pass along a parameter to the Form that the formset
contains" is pretty much what I want to know how to do.


Wayne Smith-4 wrote:
> 
> On Aug 19, 12:41 pm, SixDegrees <paulcarli...@comcast.net> wrote:
>> The parameter in question is a primary key that is used to generate a
>> series
>> of fields within the form. It is passed to the form __init__ routine, and
>> can vary from one form to another. So, given a formset, I want to tell
>> the
>> formset "This is the parameter you should use when creating the next form
>> you create."
> 
> I think it might help if you could post a code snippet showing how you
> are creating the formset (not the __init__, but where you call the
> formset creation method) and the formset creation method itself (or
> just its name if you are using formset_factory or something else from
> Django).
> 
> If I understand you correctly, you are wanting to call formset_factory
> and have it pass along a parameter to the Form that the formset
> contains.  However, you talk about the parameter being a primary key,
> which would indicate to me that you are dealing with existing objects
> from models, in which case we should be talking about a ModelFormset.
> 
> Wayne
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32297690.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

The parameter in question is a primary key that is used to generate a series
of fields within the form. It is passed to the form __init__ routine, and
can vary from one form to another. So, given a formset, I want to tell the
formset "This is the parameter you should use when creating the next form
you create."


SixDegrees wrote:
> 
> I'm using formsets to implement a dynamic form as described 
> http://www.mancoosi.org/~abate/dynamic-forms-with-django here . However,
> the forms created by the formset want a parameter passed that determines
> the contents of the form during initialization. This parameter can be
> passed back through another form on the same page using Javascript, but I
> can't figure out how to tell the formset to create the next form using
> this parameter. How is this done?
> 
> As an alternative, I can create a new form manually. But there doesn't
> seem to be a way to add it to the formset.
> 
> I would much prefer to stay away from JavaScript and other client-side
> approaches, other than passing the single parameter used for
> initialization.
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32297251.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

I'm using formsets to implement a dynamic form as described 
http://www.mancoosi.org/~abate/dynamic-forms-with-django here . However, the
forms created by the formset want a parameter passed that determines the
contents of the form during initialization. This parameter can be passed
back through another form on the same page using Javascript, but I can't
figure out how to tell the formset to create the next form using this
parameter. How is this done?

As an alternative, I can create a new form manually. But there doesn't seem
to be a way to add it to the formset.

I would much prefer to stay away from JavaScript and other client-side
approaches, other than passing the single parameter used for initialization.
-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32296362.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Defunct Processes on Server

2011-08-12 Thread SixDegrees

Calling wait() on the processes freezes the form page until the process
completes. Since the process may take several minutes to run, this is not
acceptable. We need the process to run in the background and detach from the
server process, but when it is finished we need it to truly finish and not
become zombified.


aledema wrote:
> 
> 
> Probably you have to wait() for them.
> 
> The father process spawn a child process with Popen but it eventually
> must wait for its termination.
> Look at python doc about subprocess, wait() method.
> 
> bye
> 
> Ale
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32250402.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Defunct Processes on Server

2011-08-12 Thread SixDegrees

Yes, I'm familiar with celery, and eventually we would like to migrate to
that, or some other task scheduler. Right now, though, that's not in the
cards, and folks are griping about these zombies.


Brian Bouterse wrote:
> 
> You should look into projects called celery and django-celery instead of
> cron.
> 
> On Friday, August 12, 2011, Thomas Orozco <g.orozco.tho...@gmail.com>
> wrote:
>> You could avoid starting the child process in your view.
>>
>> If it's a long running process I would actually advocate doing so.
>> This might be due to limited understanding on my part, but what happens
> when Apache wants to kill its child process because MaxRequests was
> reached?
>>
>> If you don't need the job done ASAP, you could for example have a
> directory where you store 'job files' and have a Cron script look at them.
> You could obviously store this in a database too.
>>
>> Your script could then wait on the processes to collect the returncodes
> and avoid this defunct process phenomenom.
>>
>> This is of course just a suggestion, although I'm pretty sure it would
> work, I wouldn't say that it's the one and only way of doing what you
> want.
>>
>> Le 12 août 2011 13:19, "SixDegrees" <paulcarli...@comcast.net> a écrit :
>>
>> --
>> 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 <
> django-users%2bunsubscr...@googlegroups.com>.
>> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>>
> 
> -- 
> Brian Bouterse
> ITng Services
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32250150.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Defunct Processes on Server

2011-08-12 Thread SixDegrees

We are running a Django-driven site using Apache. Some of our forms launch a
time-consuming process by using Popen:

   p = subprocess.Popen(my_cmd, shell=True)

which works fine, in the sense that the command gets launched in the
background and doesn't hang the website while it processes.

These processes, though, don't terminate properly. Instead, I see an
ever-growing list of processes using 'ps -A' that look like

   15576 ?00:00:00 my_cmd 
   15962 ?00:00:00 my_cmd 
   16014 ?00:00:00 my_cmd 
   ...

I get another of these each time I submit a form, and they never go away
until I restart Apache.

This seems to be a common problem with Python. All the remedies, however,
suggest calling some form of wait() on the process to ensure that it has
completed. In our case, this isn't an option, because we don't want to make
Apache wait on what ought to be a reasonably quick form submission.

How can I avoid this problem, or otherwise deal with the resulting zombies?
-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32249402.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Customizing Form Field HTML Attributes

2011-07-31 Thread SixDegrees

Thank you.


Stuart MacKay wrote:
> 
> Take a look at the widgets used to display a form. From the
> documentation: https://docs.djangoproject.com/en/dev/ref/forms/widgets/
> 
> "On a real Web page, you probably don't want every widget to look the
> same. You might want a larger input element for the comment, and you
> might want the 'name' widget to have some special CSS class. To do this,
> you use the Widget.attrs argument when creating the widget:
> 
> For example:
> 
> class CommentForm(forms.Form):
> name = forms.CharField(
> widget=forms.TextInput(attrs={'class':'special'}))
> url = forms.URLField()
> comment = forms.CharField(
>widget=forms.TextInput(attrs={'size':'40'}))"
> 
> Regards,
> 
> Stuart MacKay
> Lisbon, Portugal
> 
> 
>> 
>> I would like to use the 'title' attribute of several form fields to hold
>> our
>> help_text, rather than displaying the text alongside the field. I don't
>> see
>> any way, though, to add or modify tag attributes on a form field. How
>> would
>> I do this?
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Customizing-Form-Field-HTML-Attributes-tp32164210p32164300.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Customizing Form Field HTML Attributes

2011-07-31 Thread SixDegrees

I would like to use the 'title' attribute of several form fields to hold our
help_text, rather than displaying the text alongside the field. I don't see
any way, though, to add or modify tag attributes on a form field. How would
I do this?
-- 
View this message in context: 
http://old.nabble.com/Customizing-Form-Field-HTML-Attributes-tp32164210p32164210.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.