Ejemplo 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
Ejemplo n.º 2
0
 def _getViewTemplate(self):
     if 'crudTemplate' not in internal:
         internal['crudTemplate'] = templateLookup.get_template('/crud/wrapper.mak')
         # internal['crudTemplate'] = Template(
         #     '<%inherit file="/site.mak" /><%include file="/crud/crud.mak" />',
         #     lookup=templateLookup,
         #     output_encoding="utf-8")
     return internal['crudTemplate']
Ejemplo n.º 3
0
    def render_view(self, request):
        obj = self.getRequestObject(request)
        if obj is None:
            template = templateLookup.get_template("/error_404.mak")
            return helpers.renderTemplateObj(request, template)

        return helpers.renderTemplateObj(request,
                                         self._getViewTemplate(),
                                         crud=self.crudModel(obj),
                                         subTemplate="view.mak")
Ejemplo n.º 4
0
    def render_view(self, request):
        obj = self.getRequestObject(request)
        if obj is None:
            template = templateLookup.get_template("/error_404.mak")
            return helpers.renderTemplateObj(request, template)

        return helpers.renderTemplateObj(request,
                                         self._getViewTemplate(),
                                         crud=self.crudModel(obj),
                                         subTemplate="form.mak")
Ejemplo n.º 5
0
    def render_edit(self, request):
        obj = self.getRequestObject(request)
        if obj is None:
            template = templateLookup.get_template("/error_404.mak")
            return helpers.renderTemplateObj(request, template)

        crud = self.crudModel(obj)

        return helpers.renderTemplateObj(request,
                                         self._getEditTemplate(),
                                         crud=crud,
                                         redirect=crud.saveRedirect(request),
                                         subTemplate="form.mak")
Ejemplo n.º 6
0
    def render_edit(self, request):
        obj = self.getRequestObject(request)
        if obj is None:
            template = templateLookup.get_template("/error_404.mak")
            return helpers.renderTemplateObj(request, template)

        crud = self.crudModel(obj)

        return helpers.renderTemplateObj(request,
                                         self._getEditTemplate(),
                                         crud=crud,
                                         redirect=crud.saveRedirect(request),
                                         subTemplate="form.mak")
Ejemplo n.º 7
0
    def render_create(self, request, template=None):

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

        if template is None:
            template = templateLookup.get_template("/crud/form.mak")

        fakeObj = self.model()

        fakeObj.fakeID = 'n%s' % fakeID
        fakeObj.noEdit = noEdit

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

        return helpers.renderTemplateObj(request, template, 
                                         crud=self.crudModel(fakeObj))
Ejemplo n.º 8
0
    def render_view(self, request):

        relation = self.obj.__class__.__dict__[self.col]._relation1
        refClass = relation.remote_cls
        remoteColName = relation.remote_key[0].name

        presets = '{"%s": %s}' % (remoteColName, self.obj.id)
        postData = "{'where': '%s', 'exclude': '[\"%s\"]'}" % (presets, remoteColName.rstrip("_id"))

        noEdit = '["%s"]' % remoteColName

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

        return renderTemplateObj(request, 
                                 template, 
                                 model=refClass.__warp_crud__,
                                 presets=presets,
                                 postData=postData,
                                 noEdit=noEdit,
                                 exclude=[remoteColName.rstrip("_id")])
Ejemplo n.º 9
0
    def render_create(self, request, template=None):

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

        if template is None:
            template = templateLookup.get_template("/crud/form.mak")

        fakeObj = self.model()

        fakeObj.fakeID = 'n%s' % fakeID
        fakeObj.noEdit = noEdit

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

        defaulter = getattr(fakeObj, "__warp_setdefaults__", None)
        if defaulter is not None:
            defaulter()

        return helpers.renderTemplateObj(request, template,
                                         crud=self.crudModel(fakeObj))
Ejemplo n.º 10
0
    def render_view(self, request):

        refset = self.obj.__class__.__dict__[self.col]

        relation = refset._relation1
        refClass = relation.remote_cls
        remoteColName = relation.remote_key[0].name

        presets = '{"%s": %s}' % (remoteColName, self.obj.id)
        postData = "{'where': '%s', 'exclude': '[\"%s\"]'}" % (
            presets, remoteColName.rstrip("_id"))

        noEdit = '["%s"]' % remoteColName

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

        return renderTemplateObj(request,
                                 template,
                                 model=getCrudClass(refClass),
                                 presets=presets,
                                 postData=postData,
                                 noEdit=noEdit,
                                 exclude=[remoteColName.rstrip("_id")],
                                 allowCreate=self.allowCreate)
Ejemplo n.º 11
0
 def _getViewTemplate(self):
     if 'crudTemplate' not in internal:
         internal['crudTemplate'] = templateLookup.get_template('/crud/wrapper.mak')
     return internal['crudTemplate']
Ejemplo n.º 12
0
 def render(self, request):
     request.node = None
     request.resource = self
     template = templateLookup.get_template("/accessdenied.mak")
     return helpers.renderTemplateObj(request, template)
Ejemplo n.º 13
0
 def render(self, request):
     request.node = None
     request.resource = self
     template = templateLookup.get_template("/accessdenied.mak")
     return helpers.renderTemplateObj(request, template)
Ejemplo n.º 14
0
 def _getViewTemplate(self):
     if 'crudTemplate' not in internal:
         internal['crudTemplate'] = templateLookup.get_template('/crud/wrapper.mak')
     return internal['crudTemplate']