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))
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)
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)
def __init__(self, model): self.model = model self.crudModel = helpers.getCrudClass(model)
def __init__(self, model, crudModel=None): self.model = model self.crudModel = crudModel or helpers.getCrudClass(model) self.tinyTemplate = None