Ejemplo n.º 1
0
	def _handle_request(self, request):
		klass = get_entity_class(self._get_param("entity_type"))
		
		try:
			page = int(self._get_param("page")) - 1
		except (TypeError, ValueError, MissingParameter):
			page = 0
			
		try:
			rows = int(self._get_param("rows"))
		except (TypeError, ValueError, MissingParameter):
			rows = 10
			
		repo = get_repo()
		filterargs = request.REQUEST.getlist("owns[]")
		owns = {}
		for f in filterargs:
			key, _, valuestr = f.partition("=")
			valklass, _, valid = valuestr.split("-")
			if key and valklass and valuestr:
				try:
					value = repo.get_entity(valklass, valid)
				except NoEntityFound:
					self.logger.exception("error filtering result according to %s", f)
					continue
				owns[key] = value
				
		if klass.__name__ == "ResourceSpec":
			try:
				ptm_id = request.REQUEST["ptm"]
				ptm = repo.get_entity( Ptm, id = ptm_id)
#				entities = ptm.resourceSpecs#needs sorting
				ptm_info = ptm.describedByPtmInfo
				owns["supportedBy"] = ptm_info
			except KeyError:
				pass
		
		entities = repo.list_entities(klass, order_by = request.REQUEST.get("sidx"), order_desc = request.REQUEST.get("sord", "").lower() == "desc", owns = owns)
		records = len(entities)
		
		offset = rows * page
		if offset >= records:
			offset = 0
					
		rowdata = [ {
					"id": str(e.id),
					"cell": [ self._convert_value(getattr(e, f.name)) for f in get_grid_fields(klass )],
				} for e in entities[offset:offset + rows] ]

		result = {
			"total": str(int(ceil(float(records) / float(rows)))),
			"records": str(records),
			"page": str(page + 1),
			"rows": rowdata
		}
				
		return dumps(result)
Ejemplo n.º 2
0
	def repo(self):
		return get_repo()
Ejemplo n.º 3
0
	def __init__(self, name = "repoactions", *args, **kw):
		super(RepoActionsController, self).__init__(name = name, *args, **kw)
		self.repo = get_repo()
		self.__forms = get_form_manager() 
		self.perms = PermissionsHelper()
Ejemplo n.º 4
0
 def __init__(self, *args, **kw):
     super(TeagleAuthBackend, self).__init__(*args, **kw)
     
     self.__api = get_repo()