Re: A little refactoring help please

2008-10-02 Thread Brandon Taylor

Thanks guys, I appreciate it.

On Oct 2, 3:29 am, bruno desthuilliers <[EMAIL PROTECTED]>
wrote:
> On 2 oct, 07:33, Travis Parker <[EMAIL PROTECTED]> wrote:
>
> > Instead of calling render_to_response on an empty template file you
> > could simply return an empty django.http.HttpResponse and avoid the
> > templating system overhead.
>
> > I would generally send *something* in the response, even if just
> > {"success": true}, to leave space for specific error reporting later.
>
> And since this is ajax, better to send this back as json.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A little refactoring help please

2008-10-02 Thread bruno desthuilliers



On 2 oct, 07:33, Travis Parker <[EMAIL PROTECTED]> wrote:
> Instead of calling render_to_response on an empty template file you
> could simply return an empty django.http.HttpResponse and avoid the
> templating system overhead.
>
> I would generally send *something* in the response, even if just
> {"success": true}, to leave space for specific error reporting later.

And since this is ajax, better to send this back as json.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A little refactoring help please

2008-10-01 Thread Travis Parker

Instead of calling render_to_response on an empty template file you
could simply return an empty django.http.HttpResponse and avoid the
templating system overhead.

I would generally send *something* in the response, even if just
{"success": true}, to leave space for specific error reporting later.

Travis

On Oct 1, 6:13 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I have a view to do some re-ordering of a list via ajax:
>
> @staff_member_required
> def reorder(request):
>     collections = Collection.objects.all()
>
>     if request.method == 'POST':
>         pk_ids = request.POST['pk_ids'].split(',')
>         length = len(pk_ids)
>
>         for collection in collections:
>             for i in xrange(length):
>                 id = pk_ids[i]
>                 if str(collection.id) == str(id):
>                     collection.position = (i + 1)
>                     collection.save()
>
>         return render_to_response('empty.html')
>     else:
>         return render_to_response('admin/portfolio/collection/
> reorder.html', {'collections' : collections})
>
> When I call "reorder" via ajax and post data, Django complains if I
> don't return an HttpResponse object. So, I've just been returning an
> empty html file. Is there a more elegant way to handle this?
>
> TIA,
> Brandon
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



A little refactoring help please

2008-10-01 Thread Brandon Taylor

Hi everyone,

I have a view to do some re-ordering of a list via ajax:

@staff_member_required
def reorder(request):
collections = Collection.objects.all()

if request.method == 'POST':
pk_ids = request.POST['pk_ids'].split(',')
length = len(pk_ids)

for collection in collections:
for i in xrange(length):
id = pk_ids[i]
if str(collection.id) == str(id):
collection.position = (i + 1)
collection.save()

return render_to_response('empty.html')
else:
return render_to_response('admin/portfolio/collection/
reorder.html', {'collections' : collections})


When I call "reorder" via ajax and post data, Django complains if I
don't return an HttpResponse object. So, I've just been returning an
empty html file. Is there a more elegant way to handle this?

TIA,
Brandon
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---