Re: Need a tip on how to architect this code to be more extensible
Hi.
There's a really good talk by James Bennett at the Google I/O 2008
that may help you. James talk mostly about the best practices when
writing a "Reusable App".
http://www.youtube.com/watch?v=A-S0tqpPga4
I'm sorry for my rusty english.
-- Rodrigo Chacon
On Dec 5, 3:53 am, Sontek <son...@gmail.com> wrote:
> I still haven't came up with a creative solution on this, is there
> anyone that might be able to give me some ideas?
>
> On Nov 29, 12:25 am, Sontek <son...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I wrote this open source project that allows you to use the django
> > admin pop-ups in your own views but I want to give it the ability to
> > have the view extended so they can pass excludes and instances to the
> > form before its display... currently the code looks like this:
>
> > from django.contrib.auth.decorators import login_required
> > from django.shortcuts import render_to_response
> > from django.template import RequestContext
> > from django.http import HttpResponse
> > from django.utils.html import escape
> > from tekextensions.forms import get_model_form, normalize_model_name
>
> > def add_new_model(request, model_name, form=None):
> > normal_model_name = normalize_model_name(model_name)
>
> > if not form:
> > form = get_model_form(normal_model_name)
>
> > if request.method == 'POST':
> > form = form(request.POST)
> > if form.is_valid():
> > try:
> > new_obj = form.save()
> > except forms.ValidationError, error:
> > new_obj = None
>
> > if new_obj:
> > return HttpResponse('<script type="text/
> > javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</
> > script>' % \
> > (escape(new_obj._get_pk_val()), escape(new_obj)))
>
> > else:
> > form = form()
>
> > page_context = {'form': form, 'field': normal_model_name}
> > return render_to_response('popup.html', page_context,
> > context_instance=RequestContext(request))
>
> > So I'd still like to allow them to get the automatic adding of the
> > javascript httpresponse and autocreation of the form using the
> > model_form_factory but would allow them to get the form and pass
> > instance=... and exclude = ('whatever', ) so that they can
> > customize/tweak the generated form
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home