Esempio n. 1
0
    def render_create(self, request):

        presets = json.loads(request.args.get('presets', [''])[0] or '{}')
        noEdit = json.loads(request.args.get('noedit', [''])[0] or '[]')

        template = templateLookup.get_template("/crud/form.mak")

        fakeObj = self.model()

        # XXX TODO - Take a counter argument from the request here, 
        # so Javascript can product lots of these which don't conflict.
        fakeObj.fakeID = '*1'
        fakeObj.noEdit = noEdit

        for (k,v) in presets.iteritems():
            setattr(fakeObj, k, v)

        # We do an add/rollback dance here to work around some strange Storm
        # behaviour, where references don't get a value unless their object
        # is added, even if it isn't committed.
        store.add(fakeObj)

        rv =  helpers.renderTemplateObj(request, template, 
                                        obj=self.crudModel(fakeObj))

        store.rollback()

        return rv
Esempio n. 2
0
    def render_save(self, request):
        objects = json.load(request.content)
        (success, info) = form.applyForm(objects, request)
    
        if not success:
            store.rollback()
            return json.dumps({
                    'success': False,
                    'errors': info
                    })

        else:
            store.commit()

            results = dict((k, [o.id for o in v])
                           for (k,v) in info.iteritems())

            return json.dumps({
                    "success": True,
                    "results": results,
                    })
Esempio n. 3
0
 def finish(self):
     rv = Request.finish(self)
     store.rollback()
     store.commit()
     return rv
Esempio n. 4
0
 def processingFailed(self, reason):
     rv = Request.processingFailed(self, reason)
     store.rollback()
     store.commit()
     return rv