Models as remote API: High-level questions

2010-04-28 Thread Thomas Allen
Hi everyone, I am building an application where many of the models reside on another server, being served by a PHP application (we needed to do that because many clients can only host PHP). What facilities does Django provide for this sort of interaction, and how might you consider implementing i

Re: Models as remote API: High-level questions

2010-04-28 Thread Thomas Allen
That looks excellent, thank you. I like that it integrates with the admin, which means I can test the interaction with the remote app very easily. Of course I'm still interested in any other opinions :^) Thomas On Apr 28, 2:08 pm, Tom Evans wrote: > On Wed, Apr 28, 2010 at 6:37 PM

Template composition: Rendering based on permissions

2010-04-28 Thread Thomas Allen
Hi everyone, I have two questions about rendering specific design elements, and the second ties in somewhat with the first. How do you make a variable available in multiple views (multiple templates)? For instance, maybe I want the active user object to be available on each page so that I can ren

Re: Template composition: Rendering based on permissions

2010-04-28 Thread Thomas Allen
I think that template context processors are the answer to my first question. As for my second question, I could certainly check for permission membership in the provided PermWrapper, but I'm very interested in a way to check this based on the view permission requirement (implicitly). Thomas --

Template lookup order not behaving as expected

2010-04-28 Thread Thomas Allen
Hi everyone, In my "pages" app, I have the following view function which renders index.html: @login_required def index(req): return render_to_response( 'index.html', context_instance=RequestContext(req) ) What really has me stuck here is that it doesn't render pages/ template

Re: Template lookup order not behaving as expected

2010-04-28 Thread Thomas Allen
g the "index.html" filename? Thanks, Thomas On Apr 28, 5:19 pm, Thomas Allen wrote: > Hi everyone, > > In my "pages" app, I have the following view function which renders > index.html: > > @login_required > def index(req): >     return render_to_response

Re: Models as remote API: High-level questions

2010-04-28 Thread Thomas Allen
I'm sorry, I should've specified that I am using Django 1.1 (Django- ROA is compatible with 1.2 only according to its documentation). Thomas -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googl

Re: Template lookup order not behaving as expected

2010-04-28 Thread Thomas Allen
On Apr 28, 6:41 pm, creecode wrote: > You could add a "pages" directory to your templates directory. > Something like... > > ./pages > ./pages/templates > ./pages/templates/pages > > And then you would do... > > return render_to_response( 'pages/index.html'... Thanks! It looks like that is also h

contrib.auth: Email address instead of username as identifier

2010-04-29 Thread Thomas Allen
Hi everyone, I am looking for a way to replace the username with the email address as the unique key for user accounts. Is there a setting in contrib.auth to allow this? The solutions I've seen so far are hacks, validating email uniqueness via a form rather than as a model field, etc. In my mind a

Decode a JSON object?

2010-05-03 Thread Thomas Allen
How can I parse a simple JSON object in Django? I would like to parse the response: {"totalspace": 243862.672,"freespace":94053.564} django.core.serializers.deserialize('json', packet) seems to have trouble parsing such a simple string. Thomas -- You received this message because you are subsc

Re: Decode a JSON object?

2010-05-03 Thread Thomas Allen
Thanks, I poked around some more and simplejson.loads() was what I needed. Thomas -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to

Set field value for ChoiceField

2010-05-03 Thread Thomas Allen
If I'm instantiating a form, how do I set a ChoiceField value in it? I have a form with an attribute "role" which I am setting to the user's current role, like so: form = EditUserForm({ 'last_name': user.last_name, 'first_name': user.first_name, 'email': user.email, 'role': user.get_profi

Re: Set field value for ChoiceField

2010-05-03 Thread Thomas Allen
The field was being set correctly, but my template did not show this until now for some reason. Thomas On May 3, 5:34 pm, Thomas Allen wrote: > If I'm instantiating a form, how do I set a ChoiceField value in it? > > I have a form with an attribute "role" which I am

Models: Dynamic field names for open content types

2010-05-07 Thread Thomas Allen
Hi everyone, I have a model which has unpredictable field names. I am using Django- ROA to retrieve records of this model remotely, so I lose some flexibility in terms of how I can query the data: node = Node.objects.get(id=node_id) [{ "pk": "1", "model": "pages.Node", "fields":{ "id":

Cannot concatenate context list. Bizarre.

2010-05-18 Thread Thomas Allen
I would like to be able to allow any template file to add its own JavaScript. Seemed like an easy implementation: class AddScriptNode(Node): def __init__(self, scripts=[]): self.scripts = scripts def render(self, context): context['scripts'] = self.scripts + context['scripts'] ret

Re: Cannot concatenate context list. Bizarre.

2010-05-18 Thread Thomas Allen
And the following ugly loop adds scripts as I hoped simple concatenation would: def render(self, context): for i in range(0, len(self.scripts)): context['scripts'].insert(i, self.scripts[i]) return '' Thomas On May 18, 2:31 pm, Thomas Allen wrote: > I would like

reverse() with multiple possibilities: Is there a way to retrieve all?

2010-05-18 Thread Thomas Allen
If I have two URLs which resolve to the same view. Is there any way to get both? I rely on reverse() for some "active page" logic and the trouble is that it will only return a single URL, the first match it has encountered. Thomas -- You received this message because you are subscribed to the Go

Line continuation in block tag?

2010-05-21 Thread Thomas Allen
Is that possible in a Django template? If my tag spans more than one line, it is rendered as plaintext. Thomas -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe fr

Re: Line continuation in block tag?

2010-05-24 Thread Thomas Allen
Thomas Allen wrote: > Is that possible in a Django template? If my tag spans more than one > line, it is rendered as plaintext. Is this not possible? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

form.as_p, as_table variation

2010-06-03 Thread Thomas Allen
How can I create my own form renderer, like as_p, as_table, etc? I see that the form class provides _html_output to assist in formatting markup like this, but that substitution technique does not provide enough control for what I am doing, where certain properties of the field in question affect th

Re: form.as_p, as_table variation

2010-06-03 Thread Thomas Allen
On Jun 3, 12:00 pm, Bill Freeman wrote: > If you can't use _html_output, then you have to duplicate a lot of > it's functionality. I'm able to get pretty far with the template tag approach. The trouble is that BoundForms offer no way to directly add attributes, which I think can only be included

Re: form.as_p, as_table variation

2010-06-03 Thread Thomas Allen
On Jun 3, 12:05 pm, Thomas Allen wrote: > I'm able to get pretty far with the template tag approach. The trouble > is that BoundForms offer no way to directly add attributes, which I > think can only be included when defining the form field in question. Actually if I bypass uni

Loading more than one templatetag library at a time

2010-06-07 Thread Thomas Allen
Hi everyone, I have a template tag directory: templatetags/ |-__init__.py |-all.py |-contrib.py |-forms.py |-menus.py |-sites.py `-utils.py And I tried to use all.py "{% load all %}" as a shortcut for including all of these: # all.py from contrib import * from forms import * from menus import *

Re: Loading more than one templatetag library at a time

2010-06-08 Thread Thomas Allen
Is there no way to use a single template library to include many? Thomas -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-u

Re: Line continuation in block tag?

2010-06-14 Thread Thomas Allen
tagbody = ' '.join(self.nodelist[0].render(context).splitlines()) token = template.Token(template.TOKEN_BLOCK, tagbody) return '' Thomas Allen On May 24, 1:52 pm, Dennis Kaarsemaker wrote: > On ma, 2010-05-24 at 07:15 -0700, Thomas Allen wrote: > > > Thoma

Validation of dependent form fields

2010-06-14 Thread Thomas Allen
essible' ) try: urllib2.urlopen('%s%s?%s' % (loc, 'test/', urllib.urlencode({ KEY_PARAM: key }))) except urllib2.HTTPError: raise forms.ValidationError( 'The API location rejects this key.' ) return key