Models as remote API: High-level questions
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 it? I have taken a brief look at django-pipes which seems promising and I'd be curious as to the experience users here have had with that library. The remote application is flexible enough that it will not be difficult to refactor its URL scheme to match whichever approach I take. Right now it is configured to handle requests based on HTTP methods, with the idea of integrating with Rails' ActiveResource which sadly proved to be very buggy for me (so I'm happily back with good old Django). Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Models as remote API: High-level questions
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, Thomas Allen wrote: > > 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 it? I have taken a brief look at > > django-pipes which seems promising and I'd be curious as to the > > experience users here have had with that library. > > > The remote application is flexible enough that it will not be > > difficult to refactor its URL scheme to match whichever approach I > > take. Right now it is configured to handle requests based on HTTP > > methods, with the idea of integrating with Rails' ActiveResource which > > sadly proved to be very buggy for me (so I'm happily back with good > > old Django). > > > Thanks, > > Thomas > > I'm not aware of anything built-in - > tryhttp://code.welldev.org/django-roa/wiki/Home > > Cheers > > Tom > > -- > 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-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Template composition: Rendering based on permissions
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 render a link as "Sign Out (the_username)". How do you specify the display of a design element based on user permissions? For instance, a link like that one would display as "Sign In" and point to the auth login view rather than the logout view if a user were not logged in. Similarly, I would like to display links only if the user passes the view in question's @has_permission test. Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Template composition: Rendering based on permissions
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 -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Template lookup order not behaving as expected
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/ templates/index.html, instead it renders dashboard/templates/ index.html. This is not consistent with the lookup order I have seen in backtraces for missing templates, where the calling app's directory is the first one checked. I have verified that the correct view function is being called, so this doesn't seem like a URL issue to me. Up to this point, all of my templates have been located as I would expect them to be, so hopefully this is a minor rather than a major issue with my application. Here is my directory structure: % find . -type d . ./accounts ./accounts/templates ./ads ./ads/templates ./dashboard ./dashboard/templates ./db ./media ./media/templates ./pages ./pages/templates ./static ./static/css ./templates ./templates/layouts ./templates/registration And here are some settings which I think might be relevant: INSTALLED_APPS = ( 'pnc.accounts', 'pnc.dashboard', 'pnc.ads', 'pnc.media', 'pnc.pages', 'django.contrib.admin', 'django.contrib.admindocs', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites' ) TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source' ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware' ) TEMPLATE_DIRS = ( os.path.join(BASEDIR, 'templates') ) Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Template lookup order not behaving as expected
I have noticed that the first app in my INSTALLED_APPS tuple overrides all of the others for an ambiguous template name. "accounts" does not have one, but "dashboard" does, which is why I am seeing what I am seeing (if I place "ads" above "dashboard", the "ads" template precedes all others). I thought that an app's view would check its own templates directory before any others but I guess I was wrong...is there a way to override this default top-down lookup behavior? Or some way to specify my template with greater precision while keeping 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( > 'index.html', > context_instance=RequestContext(req) > ) > > What really has me stuck here is that it doesn't render pages/ > templates/index.html, instead it renders dashboard/templates/ > index.html. This is not consistent with the lookup order I have seen > in backtraces for missing templates, where the calling app's directory > is the first one checked. I have verified that the correct view > function is being called, so this doesn't seem like a URL issue to me. > > Up to this point, all of my templates have been located as I would > expect them to be, so hopefully this is a minor rather than a major > issue with my application. > > Here is my directory structure: > > % find . -type d > . > ./accounts > ./accounts/templates > ./ads > ./ads/templates > ./dashboard > ./dashboard/templates > ./db > ./media > ./media/templates > ./pages > ./pages/templates > ./static > ./static/css > ./templates > ./templates/layouts > ./templates/registration > > And here are some settings which I think might be relevant: > > INSTALLED_APPS = ( > 'pnc.accounts', > 'pnc.dashboard', > 'pnc.ads', > 'pnc.media', > 'pnc.pages', > > 'django.contrib.admin', > 'django.contrib.admindocs', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites' > ) > > TEMPLATE_LOADERS = ( > 'django.template.loaders.filesystem.load_template_source', > 'django.template.loaders.app_directories.load_template_source' > ) > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware' > ) > > TEMPLATE_DIRS = ( > os.path.join(BASEDIR, 'templates') > ) > > Thanks, > 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-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Models as remote API: High-level questions
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...@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: Template lookup order not behaving as expected
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 how the popular open-source Django apps structure their templates. 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
contrib.auth: Email address instead of username as identifier
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 clean, acceptable way to do this would result in no username field at all in the User model. Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Decode a JSON object?
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 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Decode a JSON object?
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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Set field value for ChoiceField
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_profile().role, 'client': user.get_profile().client.id }) I output the form with form.as_p, but the corresponding option is not selected. What do I need to do for it to be selected? 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Set field value for ChoiceField
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 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_profile().role, > 'client': user.get_profile().client.id > > }) > > I output the form with form.as_p, but the corresponding > option is not selected. What do I need to do for it to be selected? > > 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-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Models: Dynamic field names for open content types
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": "1", "child_count": "3", "template_id": "1", "active": "0", "title": "Home", "created_at": "2010-05-06 19:15:33", "updated_at": "2010-05-06 19:15:33", "lft": "1", "rgt": "12", "level": "0", "version": "7", "node_id": "1", "field_body": "Sample Body" } }] On the remote server, the matching record is joined with a table representing a dynamic content type (variable fields), creating the full node record. Here is the Node model: class Node(django_roa.Model): created_at = models.DateTimeField() updated_at = models.DateTimeField() template_id = models.IntegerField() child_count = models.IntegerField() parent_id = models.IntegerField() active = models.BooleanField() title = models.CharField(max_length=200) rgt = models.IntegerField() lft = models.IntegerField() level = models.IntegerField() version = models.IntegerField() I'm having a big problem with this, because Django's deserializer uses models to vivify the JSON, and there will always be fields in the returned object that are not defined in Node. In this sample packet, "field_body" is a text field. This isn't all in the air however. I can readily determine a given node's additional fields by querying the server for fields in the node's template: Field.objects.all().filter(template_id=1) [{ "pk": "1", "model": "pages.Field", "fields": { "id": "1", "type": "longtext", "name": "body", "label": "Body", "required":null, "options":null, "row_id": "1", "created_at": "2010-05-06 19:15:32", "updated_at": "2010-05-06 19:15:32" } }] So based on that data, I presume could make Django aware, somehow, that this model has an additional longtext "body" field, stored in the database as "field_body." I just don't know what to do with this data. I feel like I have a chicken-and-egg problem here: I cannot parse returned JSON without a compliant model, and I cannot build that model in memory without a returned JSON packet identifying the additional fields. That makes me think that I will separate remote queries to make all of this happen: 1. Get the base node data and include field data in the response 2. Build a new model and request the full model instance Altogether, I expect that to get pretty expensive in this application, but it will work as a last resort. I have two other ideas that I find more appealing: 1. Include field metadata in the remote JSON response, and build a model that can handle this data during the Django request. 2. Define a "dynamic" field allowing Django to access "field_*", with this field always being a CharField so that it can accept any JSON data. Perform type-specific casting and operations where necessary, explicitly. What are my other options? Has anyone set up something like this before? Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Cannot concatenate context list. Bizarre.
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'] return '' @register.tag def add_scripts(parser, token): bits = list(token.split_contents()) if len(bits) > 1: return AddScriptNode(bits[1:]) else: return AddScriptNode() {% add_scripts moo moo-more nativelib pnc %} Note that I add the existing scripts to the end of the added scripts because templates seem to be evaluated bottom-to-top, meaning a simple extend() call would cause the sub-template scripts to be at the beginning of the list (no good). The trouble is that this code clobbers context['scripts'] each time render() is called. I have no idea why that is, because if I replace that line with: context['scripts'].extend(self.scripts) then the scripts are added to the end, and nothing is clobbered. The same goes for the equivalent: context['scripts'] += self.scripts This makes no sense to me. What's going on here? 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Cannot concatenate context list. Bizarre.
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 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'] > return '' > > @register.tag > def add_scripts(parser, token): > bits = list(token.split_contents()) > if len(bits) > 1: > return AddScriptNode(bits[1:]) > else: > return AddScriptNode() > > {% add_scripts moo moo-more nativelib pnc %} > > Note that I add the existing scripts to the end of the added scripts > because templates seem to be evaluated bottom-to-top, meaning a simple > extend() call would cause the sub-template scripts to be at the > beginning of the list (no good). > > The trouble is that this code clobbers context['scripts'] each time > render() is called. I have no idea why that is, because if I replace > that line with: > > context['scripts'].extend(self.scripts) > > then the scripts are added to the end, and nothing is clobbered. The > same goes for the equivalent: > > context['scripts'] += self.scripts > > This makes no sense to me. What's going on here? > > 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-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
reverse() with multiple possibilities: Is there a way to retrieve all?
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 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Line continuation in block tag?
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 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: Line continuation in block tag?
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 email to django-us...@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.as_p, as_table variation
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 the ordering of elements and not just the value of element attributes or content. I am tempted to write a template tag that renders a form to my standards, but unfortunately _html_output handles a lot more than just formatting a template string, so I think that I would have to maintain a copy of a good bit of _html_output's logic in such a template tag. 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: form.as_p, as_table variation
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 when defining the form field in question. # from ... import format as form_format @register.simple_tag def format_form(form): html = '' field_maps = { forms.CharField: form_format.text, forms.ChoiceField: form_format.select } for name, field in form.fields.items(): for cls, handler in field_maps.items(): if isinstance(field, cls): html += handler(name, forms.forms.BoundField(form, field, name)) return html # in format.py def flatten(items): return ''.join(items) def wrapper(name, field, type, wrapped): return '%s' % (type, flatten(wrapped)) def label(name, field): # First bit of duplication if not field.label.endswith(':'): field.label += ':' return field.label_tag() def text(name, field): return wrapper(name, field, 'text', ( label(name, field), unicode(field) )) def select(name, field): return wrapper(name, field, 'select', ( label(name, field), unicode(field) )) 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: form.as_p, as_table variation
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 unicode() and use as_widget directly, I can provide attrs. 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Loading more than one templatetag library at a time
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 * from sites import * from utils import * However, none of the template tags are available. I imagine this has something to do {% load %} using the module's register variable to load in tags (if the error raised by omitting "register" is any indication), and here the register variables would clash. Is there some way to use a single template library to include many? Thanks, 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Loading more than one templatetag library at a time
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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Line continuation in block tag?
I have written certain custom tags that accept HTML attributes (typically id and class), so they can often be verbose in usage. My small idea was to write a tag that renders its contents as a tag, but the trouble is that I cannot figure out how to parse the tag body. For multi-line use of a tag "formtag," this wrapper would be used as follows: {% tag %} formtag accounts.views.login id='test' classes='this is a lengthy list of css classes' {% endtag %} As opposed to {% formtag accounts.views.login id='test' classes='this is a lengthy list of css classes' %} In render() below, what might I do with the built token to parse it normally? Parser.parse seems to contain the logic necessary to find the tag function and create the correct Node type, but I'm not sure how to use it on its own. @register.tag(name='tag') def do_tag(parser, token): nodelist = parser.parse('endtag',) parser.delete_first_token() return TagNode(parser, nodelist) class TagNode(template.Node): def __init__(self, parser, nodelist): self.parser = parser self.nodelist = nodelist def render(self, context): 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: > > > 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? > > Correct. Tags should be on one line. > > -- > Dennis K. > > They've gone to plaid! > > -- > 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-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Validation of dependent form fields
Hi everyone, Is there a way to assume one field to be invalid if another is? In the form below, api_key can never be valid if location is not. import urllib, urllib2 from django import forms from websites.models import * KEY_PARAM = 'key' class WebsiteForm(forms.ModelForm): api_key = forms.CharField(label='API key') location = forms.URLField() class Meta: model = Website def clean_location(self): loc = self.cleaned_data.get('location') try: urllib2.urlopen(loc) except urllib2.URLError: raise forms.ValidationError('This location is inaccessible') return loc def clean_api_key(self): key = self.cleaned_data.get('api_key') loc = self.cleaned_data.get('location') if loc is None: raise forms.ValidationError( 'Could not test key, the location is inaccessible' ) 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 Thomas Allen -- 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-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.