Re: JSON serialization

2014-01-18 Thread Babatunde Akinyanmi
On 19 Jan 2014 00:18, "François Schiettecatte" wrote: > > Hi > > IANA says the JSON mime type be application/json, so you might want to use that. > > application/javascript should be for javascript. Yes thats true. My bad. > > > François > > On Jan 18, 2014, at 12:05 PM, Babatunde Akinyanmi wro

Re: JSON serialization

2014-01-18 Thread François Schiettecatte
Hi IANA says the JSON mime type be application/json, so you might want to use that. application/javascript should be for javascript. François On Jan 18, 2014, at 12:05 PM, Babatunde Akinyanmi wrote: > https://docs.djangoproject.com/en/1.6/ref/request-response/#usage > > Actually, Google is

Re: JSON serialization

2014-01-18 Thread Babatunde Akinyanmi
https://docs.djangoproject.com/en/1.6/ref/request-response/#usage Actually, Google is your friend. On 18 Jan 2014 19:48, "Igor Korot" wrote: > Hi, Babatunde, > > On Sat, Jan 18, 2014 at 8:32 AM, Babatunde Akinyanmi > wrote: > > Thats probably because you are returning the json as a context in a

Re: JSON serialization

2014-01-18 Thread Igor Korot
Hi, Babatunde, On Sat, Jan 18, 2014 at 8:32 AM, Babatunde Akinyanmi wrote: > Thats probably because you are returning the json as a context in a response > with the default "text/html" mime type. Your response should have mime type > as " application/javascript". > Your json data should be in the

Re: JSON serialization

2014-01-18 Thread Babatunde Akinyanmi
Thats probably because you are returning the json as a context in a response with the default "text/html" mime type. Your response should have mime type as " application/javascript". Your json data should be in the response On 18 Jan 2014 09:16, "Igor Korot" wrote: Hi, guys, On Sat, Jan 18, 2014

Re: JSON serialization

2014-01-18 Thread Igor Korot
Hi, guys, On Sat, Jan 18, 2014 at 12:02 AM, Babatunde Akinyanmi wrote: > > On 18 Jan 2014 08:32, "Mario Gudelj" wrote: >> >> In your template try {{usb_data|safe}} > > ...because django escapes everything in the template by default except > you ask not to. One of the methods of doing so if b

Re: JSON serialization

2014-01-18 Thread Babatunde Akinyanmi
On 18 Jan 2014 08:32, "Mario Gudelj" wrote: > > In your template try {{usb_data|safe}} ...because django escapes everything in the template by default except you ask not to. One of the methods of doing so if by using the `safe` filter like Mario suggested. You can read the documentation on ho

Re: JSON serialization

2014-01-17 Thread Mario Gudelj
In your template try {{usb_data|safe}} On 18/01/2014 4:53 pm, "Igor Korot" wrote: > Hi, ALL, > I'd like someone to help me understand this situation. > Looking at the page: > https://docs.djangoproject.com/en/dev/topics/serialization/ the part > which says "Serialization formats->JSON" there is a

Re: Json serialization help

2011-08-16 Thread Andre Terra
Thank you a lot for this snippet! I've wondered about how to export objects to excel in a "more natural way" and this seems to be a great approach, considering all the different gotchas. Thank you for taking the time to write this.. I've been postponing this little bit of research for the longest

Re: Json serialization help

2011-08-16 Thread Nate
Thank you for the suggestion. I actually ended up extending Django's json serializer. Here is the code in case you or someone else needs to do something like this. from django.core.serializers.json import Serializer as JsonSerializer from django.utils.encoding import is_protected_type class Displ

Re: Json serialization help

2011-08-14 Thread Landy Chapman
> The response is something like: > 'Content-Type: text/html; charset=utf-8\n\n[{"pk": 1, "model": > "MyApp.foo", "fields": {"choice_field": "db_name1"}}]' This is interesting.. But I think the serializer is working properly. the first element in the tuple is the value stored in the database, and

Re: json serialization question

2011-05-27 Thread Ian Clelland
On Tue, May 24, 2011 at 8:36 AM, Sells, Fred wrote: > My code looks like this > > records = models.Residents.objects.extra( where=[], params=[...]) > data = serializers.serialize('json', records, ensure_ascii=False, > fields=('fname','lname', 'pt')) > return HttpResponse(data) > > After experi

Re: Json serialization for use in JS

2011-05-20 Thread Jonas Geiregat
> > class Serializer(PythonSerializer): > def end_object(self, obj): > self.objects.append({ > "fields" : self._current > }) > self._current = None > > I've made a small mistake I was importing PythonSerializer while It should've been JsonSerializer C

Re: Json serialization for use in JS

2011-05-20 Thread Jonas Geiregat
> > Your idea of overriding the Serializer class sounds like a better idea to me. > It should be possible (and will be interesting) ,I'll think I'll look into > that tonight. Overwriting django's default serializers is possible. This is how I've done it: In the root of my django project: mkd

Re: Json serialization for use in JS

2011-05-20 Thread sebastien piquemal
Hi ! I have written a small library that (among other transformations) can serialize django objects to dict (then you can just use 'json' to make your dict to a json string) : Docs on readthedocs : http://readthedocs.org/docs/any2any/en/latest/doc_pages/djangocast.html Pypi page : http://pypi.py

Re: Json serialization for use in JS

2011-05-19 Thread Tom Evans
On Thu, May 19, 2011 at 1:23 PM, Jonas Geiregat wrote: > Hello, > I'm also finding the built in serialization a bit overhead. Me too! I use a simple HttpResponse subclass for generating JSON though: from django.http import HttpResponse from django.utils import simplejson class JsonResponse(Htt

Re: Json serialization for use in JS

2011-05-19 Thread Jonas Geiregat
Hello, I'm also finding the built in serialization a bit overhead. It puts to much information in your JSON string that can be modified such as the PK field. I often import json ( http://docs.python.org/library/json.html ) and serialize the data myself before passing it to the render method. Th

Re: JSON serialization of related records.

2009-09-03 Thread Amir Habibi
Thanks Mike. The issue is the inflexible handling of fk entries of a model by the django serializer or more accurately PythonSerializer. The behavior is inherited by json and xml serializers the same. I've eventually resorted to rewriting the whole serialization to make it a better fit for my aja

Re: JSON serialization of related records.

2009-09-01 Thread Mike Ramirez
On Tuesday 01 September 2009 12:29:56 pm Amir Habibi wrote: > How can I serialize a Queryset along with the related records. For > example, in Poll and Choice case, I need each poll to have the choices > encoded in json format. > > Thanks > you'll want to look at the docs on serialization [1], it

Re: json serialization error on arrays

2009-08-26 Thread John
When I have arrays of 100,000+ the performance of lists gets unacceptable in standard c python. That's why arrays exist in python! After doing research and testing, I have decided to rebuild the project in java with embedded jython. For some bizarre reason jython performance increases with large

Re: json serialization error on arrays

2009-08-25 Thread Peter Bengtsson
what's wrong with turning it into a list? If you gzip it it won't be that big. On Aug 25, 5:16 pm, John Baker wrote: > I need to json serialize some very large objects which include large > arrays. How can I do this in django? The arrays will be very big and > heavily processed before so need to

Re: JSON Serialization with ImageField

2009-08-24 Thread Lewis Taylor
The reason I'm trying it is due to a requirement, the data rather than being sent using a normal post request in a multienc form has to be sent over in a json string in the post request containing the base64 encoded image. On Mon, 2009-08-24 at 18:38 +0200, Maksymus007 wrote: > On Tue, Aug 4, 200

Re: JSON Serialization with ImageField

2009-08-24 Thread Maksymus007
On Tue, Aug 4, 2009 at 10:58 PM, scuzz wrote: > > Hi, > > I'm trying to receive a file encoded in a json string and store it in > an ImageField. I was hoping to use the standard Django deserialisation > like: > > serializers.deserialize("json", "...snip..., \"myImageField\": > \"base64encodedimage

Re: JSON Serialization with ImageField

2009-08-24 Thread Lewis Taylor
Did you find a way to do this? I'm having the same problem. Lewis On Aug 4, 9:58 pm, scuzz wrote: > Hi, > > I'm trying to receive a file encoded in a json string and store it in > an ImageField. I was hoping to use the standard Django deserialisation > like: > > serializers.deserialize("json",

Re: Json Serialization / Form Validation error

2009-04-02 Thread Bro
But before, is it possible to serialize a form in JSON ? Thanks --~--~-~--~~~---~--~~ 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

Re: Json Serialization / Form Validation error

2009-04-02 Thread Bro
But beforce, is it possible to serialise a form in JSON ? Thanks On 11 fév, 00:50, adrian wrote: > Thank you all for posting this.  You saved me probably hours of head > scratching. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

Re: Json Serialization / Form Validation error

2009-02-10 Thread adrian
Thank you all for posting this. You saved me probably hours of head scratching. --~--~-~--~~~---~--~~ 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

Re: Json Serialization / Form Validation error

2009-01-15 Thread Alex
I ran into this same problem but the code snippets you guys gave weren't working. In case anyone is reading this in the future, here is what you want: dict([(k, [unicode(e) for e in v]) for k,v in errors.items()]) The above line will give a dictionary of field names mapping to lists of errors.

Re: Json Serialization / Form Validation error

2008-12-17 Thread Rodrigue
Hi Russell, I bumped into the same issue today and was glad I found this post. However, I found that I had to use unicode() rather than str(), which turns your example into: content = dict((key, [unicode(v) for v in values]) \ for key, values in form.error

Re: Json Serialization / Form Validation error

2008-10-18 Thread Russell Keith-Magee
On Sun, Oct 19, 2008 at 12:58 AM, justind <[EMAIL PROTECTED]> wrote: > > Hello, > > No one has any ideas? Settle down, Tiger. You asked this question on a Friday night. You may need to wait a little more than 18 hours if you want a response. We're all volunteers here, and many of us have professi

Re: Json Serialization / Form Validation error

2008-10-18 Thread justind
Actually the test form is (I forgot to change the name) class MyForm(forms.Form): text = forms.CharField() link = forms.URLField() On Oct 18, 4:21 pm, justind <[EMAIL PROTECTED]> wrote: > I get exactly the same thing. > > Here's what I'm entering. > > >>> import simplejson > >>> simple

Re: Json Serialization / Form Validation error

2008-10-18 Thread justind
I get exactly the same thing. Here's what I'm entering. >>> import simplejson >>> simplejson >>> from myproject.app.models import MyForm >>> f = MyForm({'link': 'footext'}) >>> f.errors {'text': [u'This field is required.'], 'link': [u'Enter a valid URL.']} >>> simplejson.dumps(f.errors) Trace

Re: Json Serialization / Form Validation error

2008-10-18 Thread TiNo
Could you try this with simplejson not bundled with Django? If that works this is probably a bug in the version bundled with Django. On Sat, Oct 18, 2008 at 6:58 PM, justind <[EMAIL PROTECTED]> wrote: > > Hello, > > No one has any ideas? > > The code I'm actually using in my view is almost identic

Re: Json Serialization / Form Validation error

2008-10-18 Thread justind
Hello, No one has any ideas? The code I'm actually using in my view is almost identical to the validage_contact view from http://toys.jacobian.org/presentations/2007/oscon/tutorial/ (single slide: http://toys.jacobian.org/presentations/2007/oscon/tutorial/images/django-master-class.081.png) and

Re: json serialization without certain fields and with extra information?

2007-03-10 Thread shevken
Hey guys, How do you de-serialize the object back at the ajax response. class Cart(models.Model): ... def get_total_quantity(): return quantity; self.response = self.xmlhttp.responseText; // parse the response into a JSON object var json_data = self.response.parseJSON(); alert(jso

Re: json serialization without certain fields and with extra information?

2007-03-04 Thread Manoj Govindan
Hi Bram, Here is a possible mechanism to address your second point, i.e., hide certain fields while serializing. Consider this model: class Person(models.Model): ... # various fields here. @staticmethod def fields_for_serializing(): return [list of those field names that can

Re: json serialization without certain fields and with extra information?

2007-03-01 Thread Bram - Smartelectronix
Manoj Govindan wrote: > > >> The serializer in trunk has a fields option, which only serializes the >> fields supplied. >> >> Ex: >> serializers.serialize('json', my_user_set, fields=('username', 'id')) > > This doesn't work at the moment > http://code.djangoproject.com/ticket/3466 > > But luc

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Manoj Govindan
> The serializer in trunk has a fields option, which only serializes the > fields supplied. > > Ex: > serializers.serialize('json', my_user_set, fields=('username', 'id')) This doesn't work at the moment http://code.djangoproject.com/ticket/3466 But luckily there is also a patch ;) Regards, M

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Deryck Hodge
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > hey everyone, > > > 1. is there any way to serialize models and remove some fields? I.e. I > would like to serialize User for example, but I definitely don't want > the email to be there. > The serializer in trunk has a fields opti

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
My code will seem like: def _get_data(request, obj): if obj.icon: icon = '' % (obj.get_icon_url(), obj.title) else: icon = '' % obj.title authors = [x.username for x in obj.authors.all()] return ({'id':obj.id, 'icon':icon, 'title':obj.title, 'description':o

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Bram - Smartelectronix
limodou wrote: > django also uses simplejson to dump python variable, why you want to > avoid it? And I think using simplejson is more flexiable and simple. Because it's more generic and I don't want to recreate what's done in the models... In the end I did it like this: # MODEL --

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > limodou wrote: > > On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > >> hey everyone, > >> > >> > >> 1. is there any way to serialize models and remove some fields? I.e. I > >> would like to serialize User for example,

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Bram - Smartelectronix
limodou wrote: > On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: >> hey everyone, >> >> >> 1. is there any way to serialize models and remove some fields? I.e. I >> would like to serialize User for example, but I definitely don't want >> the email to be there. >> >> 2. is there a way

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > hey everyone, > > > 1. is there any way to serialize models and remove some fields? I.e. I > would like to serialize User for example, but I definitely don't want > the email to be there. > > 2. is there a way to provide "custom" pa

Re: JSON serialization and non-model classes

2006-10-18 Thread Stefán Freyr Stefánsson
rialize("json", data), mimetype="text/_javascript_")Any help would shure be appreciated.Kind regards, Stefan Freyr. -- Forwarded message ------From: Waylan Limberg <[EMAIL PROTECTED]>Date: Oct 18, 2006 4:06 PM Subject: Re: JSON serialization and non-model classesTo

Re: JSON serialization and non-model classes

2006-10-18 Thread Waylan Limberg
On 10/18/06, Stefán Freyr Stefánsson <[EMAIL PROTECTED]> wrote: > Hello. > > I'm creating a web application that monitors information on distributed > computers. This information (which is numerical; the sizes of queues running > in a process on each of the computers) is put into a single database

Re: json serialization

2006-08-01 Thread Jyrki Pulliainen
2006/7/31, Jyrki Pulliainen <[EMAIL PROTECTED]>: > I filed a ticket for this, see http://code.djangoproject.com/ticket/2460 Json serialization is now fixed in SVN Trunk version -- Jyrki // [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because

Re: json serialization

2006-08-01 Thread Jyrki Pulliainen
2006/7/31, Gábor Farkas <[EMAIL PROTECTED]>: > > Jyrki Pulliainen wrote: > > 2006/7/31, Gábor Farkas <[EMAIL PROTECTED]>: > >> > >> datetime.datetime inherits from datetime. > >> > > > > Definetly not > > > > > sorry, of course i meant > > "datetime.datetime inherits from datetime.time" My bad to

Re: json serialization

2006-07-31 Thread Gábor Farkas
Jyrki Pulliainen wrote: > 2006/7/31, Gábor Farkas <[EMAIL PROTECTED]>: >> >> datetime.datetime inherits from datetime. >> > > Definetly not > sorry, of course i meant "datetime.datetime inherits from datetime.time" gabor --~--~-~--~~~---~--~~ You received thi

Re: json serialization

2006-07-31 Thread Jyrki Pulliainen
I filed a ticket for this, see http://code.djangoproject.com/ticket/2460 -- Jyrki // [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to djan

Re: json serialization

2006-07-31 Thread Jyrki Pulliainen
2006/7/31, Gábor Farkas <[EMAIL PROTECTED]>: > > siniy wrote: > > Hi all, > > I've downloaded today a new release of Django and played with json > > serialization. I found that if you use DateTime field the resulting > > json string contains only date, but not all datetime. So I viewed a > > sourc

Re: json serialization

2006-07-31 Thread Gábor Farkas
siniy wrote: > Hi all, > I've downloaded today a new release of Django and played with json > serialization. I found that if you use DateTime field the resulting > json string contains only date, but not all datetime. So I viewed a > source code of django/core/serializers/json.py and found that: >

Re: json serialization

2006-07-31 Thread limodou
On 7/31/06, Jyrki Pulliainen <[EMAIL PROTECTED]> wrote: > > 2006/7/31, siniy <[EMAIL PROTECTED]>: > > I know that isinstance(o, datetime.date) returns "True" even "o" is a > > datetime object. But I don't know - may be it's a python bug? My python > > version 2.4.3 from Ubuntu Dapper. I think you

Re: json serialization

2006-07-31 Thread Jyrki Pulliainen
2006/7/31, siniy <[EMAIL PROTECTED]>: > I know that isinstance(o, datetime.date) returns "True" even "o" is a > datetime object. But I don't know - may be it's a python bug? My python > version 2.4.3 from Ubuntu Dapper. I can confirm this behaviour with Debian Testing's Python 2.3.5 too. -- Jy