svgui/pyjs/jsonrpc/django/jsonrpc.py
changeset 1783 3311eea28d56
parent 1769 4665ba25a0ba
child 1850 614396cbffbf
equal deleted inserted replaced
1782:5b6ad7a7fd9d 1783:3311eea28d56
     1 # jsonrpc.py
     1 # jsonrpc.py
     2 #   original code: http://trac.pyworks.org/pyjamas/wiki/DjangoWithPyJamas
     2 #   original code: http://trac.pyworks.org/pyjamas/wiki/DjangoWithPyJamas
     3 #   also from: http://www.pimentech.fr/technologies/outils
     3 #   also from: http://www.pimentech.fr/technologies/outils
       
     4 from datetime import date
       
     5 import datetime
       
     6 import sys
       
     7 
     4 from django.utils import simplejson
     8 from django.utils import simplejson
     5 from django.http import HttpResponse
     9 from django.http import HttpResponse
     6 import sys
    10 from django import forms
       
    11 from django.core.serializers import serialize
       
    12 
     7 
    13 
     8 from pyjs.jsonrpc import JSONRPCServiceBase
    14 from pyjs.jsonrpc import JSONRPCServiceBase
     9 # JSONRPCService and jsonremote are used in combination to drastically
    15 # JSONRPCService and jsonremote are used in combination to drastically
    10 # simplify the provision of JSONRPC services.  use as follows:
    16 # simplify the provision of JSONRPC services.  use as follows:
    11 #
    17 #
    61 #
    67 #
    62 # this will result in a JSONRPC service being created with two
    68 # this will result in a JSONRPC service being created with two
    63 # RPC functions.  dump "processor" into urlpatterns to make it
    69 # RPC functions.  dump "processor" into urlpatterns to make it
    64 # part of the app:
    70 # part of the app:
    65 #  (r'^formsservice/$', 'djangoapp.views.processor'),
    71 #  (r'^formsservice/$', 'djangoapp.views.processor'),
    66 
       
    67 from django import forms
       
    68 
    72 
    69 
    73 
    70 def builderrors(form):
    74 def builderrors(form):
    71     d = {}
    75     d = {}
    72     for error in form.errors.keys():
    76     for error in form.errors.keys():
   206 # dump jsonservice into urlpatterns to make the two RPC functions,
   210 # dump jsonservice into urlpatterns to make the two RPC functions,
   207 # list_some_model and list_another_model part of the django app:
   211 # list_some_model and list_another_model part of the django app:
   208 #  (r'^service1/$', 'djangoapp.views.jsonservice'),
   212 #  (r'^service1/$', 'djangoapp.views.jsonservice'),
   209 
   213 
   210 
   214 
   211 from django.core.serializers import serialize
       
   212 import datetime
       
   213 from datetime import date
       
   214 
       
   215 
       
   216 def dict_datetimeflatten(item):
   215 def dict_datetimeflatten(item):
   217     d = {}
   216     d = {}
   218     for k, v in item.items():
   217     for k, v in item.items():
   219         k = str(k)
   218         k = str(k)
   220         if isinstance(v, datetime.date):
   219         if isinstance(v, datetime.date):