def render_neems(): show_all = request.args.get('show_all', default=True, type=bool) per_page = request.args.get('limit', default=12, type=int) query = request.args.get('neem_query', default='', type=str) # compute pagination offset current_page = int(request.args.get('page', 1)) current_offset = (current_page - 1) * per_page next_offset = current_offset + per_page # get neems matching_neems = neem_hub.get_neem_ids(query, neem_hub.get_neem_visibility_flag()) neems = list( map(lambda (x): neem_hub.get_neem(x), matching_neems[current_offset:next_offset])) # TODO: what does this mean? search = False q = request.args.get('q') if q: search = True pagination = Pagination(page=current_page, per_page=per_page, offset=current_offset, total=len(matching_neems), css_framework='bootstrap4', search=search) if not USE_HOST_KNOWROB and not container_started(current_user.username): sql = get_neemhub_settings() docker_interface.start_user_container( current_user.username, json.dumps(sql, cls=AlchemyEncoder), "knowrob", "latest") return render_template('pages/neems.html', **locals())
def activate(self): app.logger.info('Activate neem') if not USE_HOST_KNOWROB and not container_started(current_user.username): sql = get_neemhub_settings() start_user_container(current_user.username, json.dumps(sql, cls=AlchemyEncoder), "knowrob", "latest")
def track_login(sender, user, **extra): app.logger.info("Logged in " + str(user.username)) # TODO: why not just use username key? session['user_container_name'] = user.username session['username'] = user.username session['api_token'] = user.api_token if not USE_HOST_KNOWROB: sql = get_neemhub_settings() docker_interface.start_user_container( user.username, json.dumps(sql, cls=AlchemyEncoder), "knowrob", "latest")
def store_settings(self): sql = get_neemhub_settings() sql.mongo_host = self.mongo_host sql.mongo_port = self.mongo_port sql.mongo_db = self.mongo_db_name sql.mongo_user = self.mongo_user sql.mongo_pass = self.mongo_pass sql.visibility_flag = self.visibility_flag sql.urdf_server = self.urdf_server sql.mesh_server = self.mesh_server self.mongo_db = None db.session.commit()
def __init__(self): # get the SQL settings object sql = get_neemhub_settings() self.mongo_host = sql.mongo_host self.mongo_port = int(sql.mongo_port) self.mongo_db_name = sql.mongo_db self.mongo_user = sql.mongo_user self.mongo_pass = sql.mongo_pass self.visibility_flag = sql.visibility_flag self.urdf_server = sql.urdf_server self.mesh_server = sql.mesh_server self.mongo_client = None self.mongo_db = None