예제 #1
0
파일: colproxy.py 프로젝트: bhomnick/warp
    def render_edit(self, request):

        # Make sure it's loaded
        getattr(self.obj, self.col)

        reference = self.obj.__class__.__dict__[self.col]
        idCol = reference._local_key[0].name
        noEdit = getattr(self.obj, 'noEdit', [])

        # We get the _id field here rather than the reference value
        # itself, because the reference works only on objects that
        # have been added to the store, and we want to avoid that
        # when creating things (since they may not satisfy constraints,
        # and will get added when the database gets flushed on e.g. a find())
        objID = getattr(self.obj, idCol)

        refClass = reference._relation.remote_cls
        crudClass = getCrudClass(refClass)

        if self.col in noEdit or idCol in noEdit:
            obj = request.store.get(refClass, objID)
            return '<input type="hidden" name="warpform-%s" value="%s" />%s' % (
                self.fieldName(), objID, crudClass(obj).name(request))

        allObjs = [(crudClass(o).name(request), o) 
                   for o in request.store.find(refClass, *self.conditions)]
        allObjs.sort()

        if objID is None:
            if self.default is not None:
                sel = lambda o: ' selected="selected"' if o.id == self.default.id else ''
            else:
                sel = lambda o: ""
        else:
            sel = lambda o: ' selected="selected"' if o.id == objID else ''

        options = []

        if self.allowNone:
            options.append('<option value="">[None]</option>')
        
        options.extend('<option value="%s"%s>%s</option>' % 
                       (o.id, sel(o), name)
                       for (name, o) in allObjs)

        return '<select name="warpform-%s">\n%s\n</select>' % (
            self.fieldName(), "\n".join(options))
예제 #2
0
    def render_edit(self, request):

        # Make sure it's loaded
        getattr(self.obj, self.col)

        reference = self.obj.__class__.__dict__[self.col]
        idCol = reference._local_key[0].name
        noEdit = getattr(self.obj, 'noEdit', [])

        # We get the _id field here rather than the reference value
        # itself, because the reference works only on objects that
        # have been added to the store, and we want to avoid that
        # when creating things (since they may not satisfy constraints,
        # and will get added when the database gets flushed on e.g. a find())
        objID = getattr(self.obj, idCol)

        refClass = reference._relation.remote_cls
        crudClass = getCrudClass(refClass)

        if self.col in noEdit or idCol in noEdit:
            obj = request.store.get(refClass, objID)
            return '<input type="hidden" name="warpform-%s" value="%s" />%s' % (
                self.fieldName(), objID, crudClass(obj).name(request))

        allObjs = [(crudClass(o).name(request), o)
                   for o in request.store.find(refClass, *self.conditions)]
        allObjs.sort()

        if objID is None:
            if self.default is not None:
                sel = lambda o: ' selected="selected"' if o.id == self.default.id else ''
            else:
                sel = lambda o: ""
        else:
            sel = lambda o: ' selected="selected"' if o.id == objID else ''

        options = []

        if self.allowNone:
            options.append('<option value="">[None]</option>')

        options.extend('<option value="%s"%s>%s</option>' %
                       (o.id, sel(o), name) for (name, o) in allObjs)

        return '<select name="warpform-%s">\n%s\n</select>' % (
            self.fieldName(), "\n".join(options))
예제 #3
0
파일: colproxy.py 프로젝트: bhomnick/warp
    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)
예제 #4
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)
예제 #5
0
파일: render.py 프로젝트: foamdino/warp
 def __init__(self, model):
     self.model = model
     self.crudModel = helpers.getCrudClass(model)
예제 #6
0
파일: render.py 프로젝트: bhomnick/warp
 def __init__(self, model, crudModel=None):
     self.model = model
     self.crudModel = crudModel or helpers.getCrudClass(model)
     self.tinyTemplate = None
예제 #7
0
파일: render.py 프로젝트: ubolonton/warp
 def __init__(self, model, crudModel=None):
     self.model = model
     self.crudModel = crudModel or helpers.getCrudClass(model)
     self.tinyTemplate = None