Rendering Group Labels for Checkboxes and Radio Groups
Hi, When I render a CheckBoxGroup or a Radiobox group and I apply a label to whole widget (independent of the labels for each of the choices), I get something like this: Group Label The problem is that because the top label has the attribute "for='element_0'" if you click on it, it activates the first check box (id='element_0'). I'd like to stop this functionality from happening, but I can't find where to change the rendering for the group label, without affecting the labeling of each individual input. Any ideas or suggestions? Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
PID/processes for runserver
I've written a script to launch a server, run some tests and then kill the server afterwards. The problem I'm having is that the PID returned from the subprocess call is not the same as the PID needed to kill the server. Is there any way to get the runserver command to run with a single process? Other potential solutions are welcome. Thanks, Mike --~--~-~--~~~---~--~~ 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: Load Templates from outside TEMPLATE_DIRS
The template in question is to format my test results, and I didn't want to have lump it in with the production templates, or have the template directory permanently attached to the TEMPLATE_DIR So instead I've just loaded a new settings file with a modified TEMPLATE_DIR before I do my tests. Works pretty well. Thanks. On Sep 11, 8:58 pm, Kenneth Gonsalves wrote: > On Saturday 12 Sep 2009 9:26:15 ammviamariwrote: > > > I'm trying to load a template file from outside of TEMPLATE_DIRS, i.e. > > the template file does not reside in any of the template directories > > specified in TEMPLATE_DIRS. > > > Does anyone know if this is possible? I tried just specifying a path: > > i.e.'../../new_dir/template.html' but that doesn't seem to be working. > > > Any suggestions? > > what is the problem in specifying the directory in TEMPLATE_DIRS? > -- > regards > kghttp://lawgon.livejournal.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 -~--~~~~--~~--~--~---
Load Templates from outside TEMPLATE_DIRS
I'm trying to load a template file from outside of TEMPLATE_DIRS, i.e. the template file does not reside in any of the template directories specified in TEMPLATE_DIRS. Does anyone know if this is possible? I tried just specifying a path: i.e.'../../new_dir/template.html' but that doesn't seem to be working. Any suggestions? Thanks, Mike --~--~-~--~~~---~--~~ 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 Choices for ChoiceField
On Jul 31, 7:37 pm, Malcolm Tredinnick wrote: > On Fri, 2009-07-31 at 16:31 -0700,mviamariwrote: > > Hello, > > > I'm trying to make a form for data entry into my database that uses > > ChoiceFields for foreign keys. Obviously, the ideal choice would be > > ModelChoiceField, however I'm not using the django ORM, so I've > > assumed that's not going to work (I'm using Elixir/SQLAlchemy). > > > I originally set the choices parameter in the ChoiceField declaration > > to be derived from a query result from SQLAlchemy (returned as an > > array of tuples). The problem is that the choices don't update when > > the database changes. They are fixed to whatever was present when the > > server is initialized (or at least it appears to be). > > If you have specified the choices field as a parameter to a Field > subclass in a Form class, then it will be evaluated whenever that Form > class is parsed (probably at import time). That's normal Python > behaviour. > > > I'm looking for suggestions/advice on to get the ChoiceField choices > > to update when the form is the used. > > "Used" is probably a bit ambiguous here. It's probably easier to think > in terms of "when an instance of the form class is created." The > solution is to update the choices attribute on the appropriate field in > the Form subclass's __init__() method. For example > > class MyForm(forms.Form): > options = forms.ChoiceField() > > def __init__(self, *args, **kwargs): > super(MyForm, self).__init__(*args, **kwargs) > choices = ... # <-- create a sequence of 2-tuples > self.fields["options"].choices = choices > > You can do whatever you like to populate the "choices" variable in the > above fragment. The only requirement is that you end up with a sequence > of pairs which are the submitted form value and the human readable text > for the form element. > > Regards, > Malcolm Thanks Malcom. That appears to have worked. Mike --~--~-~--~~~---~--~~ 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 Choices for ChoiceField
Hello, I'm trying to make a form for data entry into my database that uses ChoiceFields for foreign keys. Obviously, the ideal choice would be ModelChoiceField, however I'm not using the django ORM, so I've assumed that's not going to work (I'm using Elixir/SQLAlchemy). I originally set the choices parameter in the ChoiceField declaration to be derived from a query result from SQLAlchemy (returned as an array of tuples). The problem is that the choices don't update when the database changes. They are fixed to whatever was present when the server is initialized (or at least it appears to be). I've worked around this by using CharFields and implementing my own validation method that checks for the value in the aforesaid query result. Unforunately, that doesn't help me if i want to use the forms.as_ methods. I'm looking for suggestions/advice on to get the ChoiceField choices to update when the form is the used. Thanks, Mike --~--~-~--~~~---~--~~ 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 Manage.py Commands
On Jul 30, 5:24 pm, Malcolm Tredinnick wrote: > On Thu, 2009-07-30 at 17:18 -0700, mviamari wrote: > > I'm trying to create a custom manage.py command for my project. The > > example in the documentation only shows how to do this for custom > > commands inside of an app. Is it possible to do the same at the > > project level? > > The concept doesn't particularly make sense, since Django is app-based. > "Projects" are a bit of a convenient way of grouping things, but they're > just a settings file, a root URL conf and some apps. Which is a way of > saying that isn't supported. > > It's fairly logical, however, to create an app that only provides your > support for things like that this. Lots of people have apps that just > contain template tags or just contain templates or even management > commands. They don't need to contain models or anything like that. > > Regards, > Malcolm The problem I had was that the commands weren't specific to a given app, and I didn't want to have to replicate them in each one. A special app just for additional commands makes much more sense. Thanks. Mike --~--~-~--~~~---~--~~ 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 Manage.py Commands
I'm trying to create a custom manage.py command for my project. The example in the documentation only shows how to do this for custom commands inside of an app. Is it possible to do the same at the project level? I'm currently specifying a Command class in a module file within a management/commands package as suggested in the documentation, but it doesn't seem to be finding the command. Any help would be appreciated. Mike --~--~-~--~~~---~--~~ 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: Help with Test Client, Templates and Context
On Jul 30, 12:40 am, Karen Tracey wrote: > On Thu, Jul 30, 2009 at 12:06 AM, mviamari wrote: > > > I'm trying to use the test client to verify my views, but when I check > > the templates and contexts I get 'None' returned instead of the > > context dict or the template. I do get the correct content and status > > code however. I was hoping someone could give me some tips. Here is > > some example code: > > > [snip] > > > I'm attempting to access the response as follows: > > > from django.test.client import Client > > c=Client() > > r = c.get("/url/to/home") #Access views.home > > r.content #Returns correct content > > r.context #returns None > > r.template #returns None > > > r = c.post("/url/to/add/product", > > {'name':'testProd','units':'testUnits','notes':'no notes'}) > > r.status_code #returns 201 correctly > > r.content #Returns correct content > > r.context #returns None > > r.template #returns None > > # This post adds testProd to the product table correctly > > > I would greatly appreciate any suggestions, tips, hints or help of any > > kind. > > Are you doing this from a manage.py shell session? Setting these attributes > relies on a signal > (http://docs.djangoproject.com/en/dev/ref/signals/#template-rendered) that is > only sent when running tests. So your test code run from manage.py test > should be able to interrogate these values, but they won't be set when you > are manually trying out the test Client in a shell session. > > Karen That's the problem. I was running them from the shell. I appreciate your help. Thanks, Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help with Test Client, Templates and Context
I'm trying to use the test client to verify my views, but when I check the templates and contexts I get 'None' returned instead of the context dict or the template. I do get the correct content and status code however. I was hoping someone could give me some tips. Here is some example code: #views def home(request): t = Template("{{info}}") c = Context({'info':'Sales Home Page'}) return HttpResponse(t.render(c)) def addProduct(request): if request.method == 'POST': form = forms.ProductForm(request.POST) if form.is_valid(): try: p = db.models.Product(**form.cleaned_data) db.session.commit() c = Context({'type': 'Product', 'entry': p, 'time': datetime.datetime.now().strftime ("%Y-%m-%d %H:%M:%S")}) t = loader.get_template("product_added.html") return HttpResponse(t.render(c), status=201) except: db.session.rollback() status=206 else: status=204 else: status=200 c = Context({'title': 'New Product', }) t = loader.get_template("newproduct.html") return HttpResponse(t.render(c), status=status) Notes: I'm not using the django DRM (I'm using SQLAlchemy), but to me that seems irrelevant (I may be wrong). I'm attempting to access the response as follows: from django.test.client import Client c=Client() r = c.get("/url/to/home") #Access views.home r.content #Returns correct content r.context #returns None r.template#returns None r = c.post("/url/to/add/product", {'name':'testProd','units':'testUnits','notes':'no notes'}) r.status_code #returns 201 correctly r.content #Returns correct content r.context #returns None r.template#returns None # This post adds testProd to the product table correctly I would greatly appreciate any suggestions, tips, hints or help of any kind. Thanks, Mike --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---