def listing(self, **kwargs): """listing page""" page = self.get_page(**kwargs) fs = self.get_grid() fs = fs.bind(instances=page, request=self.request) fs.readonly = True event = events.BeforeRenderEvent(self.request.model_class(), self.request, fs=fs, page=page) alsoProvides(event, events.IBeforeListingRenderEvent) zope.component.event.objectEventNotify(event) if self.request.format == 'json': values = [] request = self.request for item in page: pk = _pk(item) fs._set_active(item) value = dict(id=pk, absolute_url=request.fa_url(request.model_name, pk)) if 'jqgrid' in request.GET: fields = [_stringify(field.render_readonly()) for field in fs.render_fields.values()] value['cell'] = [pk] + fields else: value.update(fs.to_dict(with_prefix=bool(request.params.get('with_prefix')))) values.append(value) return self.render_json_format(rows=values, records=len(values), total=page.page_count, page=page.page) if 'pager' not in kwargs: pager = page.pager(**self.pager_args) else: pager = kwargs.pop('pager') return self.render_grid(fs=fs, id=None, pager=pager)
def listing(self, **kwargs): """listing page""" page = self.get_page() fs = self.get_grid() fs = fs.bind(instances=page) fs.readonly = True if self.request.format == 'json': values = [] request = self.request for item in page: pk = _pk(item) fs._set_active(item) value = dict(id=pk, item_url=self.route_url(request.model_name, pk)) if 'jqgrid' in request.GET: fields = [_stringify(field.render_readonly()) for field in fs.render_fields.values()] value['cell'] = [pk] + fields else: value.update(dict([(field.key, field.model_value) for field in fs.render_fields.values()])) values.append(value) return self.render_json_format(rows=values, records=len(values), total=page.page_count, page=page.page) if 'pager' not in kwargs: pager = page.pager(**self.pager_args) else: pager = kwargs.pop('pager') return self.render_grid(fs=fs, id=None, pager=pager)
def index(self, format='html', **kwargs): """REST api""" page = self.get_page() fs = self.get_grid() fs = fs.bind(instances=page) fs.readonly = True if format == 'json': values = [] for item in page: pk = _pk(item) fs._set_active(item) value = dict(id=pk, item_url=model_url(self.member_name, id=pk)) if 'jqgrid' in request.GET: fields = [_stringify(field.render_readonly()) for field in fs.render_fields.values()] value['cell'] = [pk] + fields else: value.update(dict([(field.key, field.model_value) for field in fs.render_fields.values()])) values.append(value) return self.render_json_format(rows=values, records=len(values), total=page.page_count, page=page.page) if 'pager' not in kwargs: pager = page.pager(**self.pager_args) else: pager = kwargs.pop('pager') return self.render_grid(format=format, fs=fs, id=None, pager=pager)
def __init__(self, context=None, **kwargs): if context is None: self.context = dict(**kwargs) else: self.context = context if getattr(self, 'uuid', None): uuid = self.uuid if isinstance(uuid, UUID): self._pk = str(int(uuid)) else: self._pk = _stringify(self.uuid) else: self._pk = None
def render(self, options, **kwargs): if callable(options): L = fields._normalized_options(options(self.field.parent)) if not self.field.is_required() and not self.field.is_collection: L.insert(0, self.field._null_option) else: L = list(options) if len(L) > 0: if len(L[0]) == 2: L = sorted([(k, self.stringify_value(v)) for k, v in L], key=lambda x:unicodelower(x[0])) else: L = sorted([fields._stringify(k) for k in L], key=unicodelower) return h.select(self.name, self.value, L, class_='i-can-haz-chzn-select', **kwargs) + \ h.literal("<script>$('#%s').chosen()</script>" % self.name)
def _validate(self): if self.is_readonly(): return True valide = BaseField._validate(self) if not valide: return False value = self._deserialize() if isinstance(self.type, fatypes.Unicode) and not isinstance(value, unicode): value = _stringify(value) field = self.parent.iface[self.name] bound = field.bind(self.model) try: bound.validate(value) except schema.ValidationError, e: self.errors.append(e.doc())
def listing(self, **kwargs): """listing page""" page = self.get_page(**kwargs) fs = self.get_grid() fs = fs.bind(instances=page, request=self.request) fs.readonly = True event = events.BeforeRenderEvent(self.request.model_class(), self.request, fs=fs, page=page) alsoProvides(event, events.IBeforeListingRenderEvent) zope.component.event.objectEventNotify(event) if self.request.format == 'json': values = [] request = self.request for item in page: pk = _pk(item) fs._set_active(item) value = dict(id=pk, absolute_url=request.fa_url( request.model_name, pk)) if 'jqgrid' in request.GET: fields = [ _stringify(field.render_readonly()) for field in fs.render_fields.values() ] value['cell'] = [pk] + fields else: value.update( fs.to_dict(with_prefix=bool( request.params.get('with_prefix')))) values.append(value) return self.render_json_format(rows=values, records=len(values), total=page.page_count, page=page.page) if 'pager' not in kwargs: pager = page.pager(**self.pager_args) else: pager = kwargs.pop('pager') return self.render_grid(fs=fs, id=None, pager=pager)
def render(self, options, **kwargs): optional_js = '' prf = self.project_related_form() if prf and self.field.relation_type() == Project: optional_js = """\n$("#%(project_id)s").chosen().change(function(){ var $project_id = $(this).val(); $.getJSON('/admin/Project/'+$project_id+'/list_customer_requests.json', function(data){ var items = []; """ prf_names = [a.renderer.name for a in prf] for n in prf_names: optional_js += "$('#%s option').remove();" % n optional_js += """$.each(data, function(cr) { items.push("<option value='" + data[cr]['id'] + "'>" + data[cr]['name'] + "</option>"); }); $('#%s').append(items.join(""));""" % n optional_js += "$('#%s').trigger('chosen:updated');" % n optional_js += "})});" optional_js = optional_js % {'project_id':self.name} if callable(options): L = fields._normalized_options(options(self.field.parent)) if not self.field.is_required() and not self.field.is_collection: L.insert(0, self.field._null_option) else: L = list(options) if len(L) > 0: if len(L[0]) == 2: L = sorted([(k, self.stringify_value(v)) for k, v in L], key=lambda x:unicodelower(x[0])) else: L = sorted([fields._stringify(k) for k in L], key=unicodelower) return h.select(self.name, self.value, L, class_='i-can-haz-chzn-select', **kwargs) + \ h.literal("<script>$('#%s').chosen();%s</script>" % (self.name, optional_js))
def index(self, format="html", **kwargs): """REST api""" page = self.get_page() fs = self.get_grid() fs = fs.bind(instances=page) fs.readonly = True if format == "json": values = [] for item in page: pk = _pk(item) fs._set_active(item) value = dict(id=pk, item_url=model_url(self.member_name, id=pk)) if "jqgrid" in request.GET: fields = [_stringify(field.render_readonly()) for field in fs.render_fields.values()] value["cell"] = [pk] + fields else: value.update(dict([(field.key, field.model_value) for field in fs.render_fields.values()])) values.append(value) return self.render_json_format(rows=values, records=len(values), total=page.page_count, page=page.page) if "pager" not in kwargs: pager = page.pager(**self.pager_args) else: pager = kwargs.pop("pager") return self.render_grid(format=format, fs=fs, id=None, pager=pager)
def _query_options(L): if User in L._mapper_adapter_map.keys(): L = L.filter_by(active=True) return [(fields._stringify(item), fields._pk(item)) for item in L]