Ejemplo n.º 1
0
 def read(self, request):
     """
     Return JSON serialized data.
     """
     from keops.views import db
     using = db.get_db(request)
     return HttpJsonResponse(db.prepare_read(request.GET, using))
Ejemplo n.º 2
0
 def submit(self, request, **kwargs):
     """
     Receive submit data.
     """
     from keops.views import db
     using = db.get_db(request)
     try:
         success, obj = self.save(request.POST, using)
         result = {
             'success': True,
             'msg': _('Record successfully saved!'),
             'data': db.prepare_read({'model': request.POST['model'], 'pk': obj.pk}, using)['items'][0]
         }
     except ValidationError as e:
         result = {
             'success': False,
             'msg': '<br>'.join(e.messages)
         }
     return HttpJsonResponse(result)