def submit_changes(self): ''' This function validates the submitted profile edit form and commits the changes. Restricted to ``POST`` requests. If successful, redirects to the result action to prevent resubmission. ''' if not h.auth.is_logged_in(): abort(401) c.user = h.get_user(request.environ['REMOTE_USER']) if self.form_result['password'] != '': c.user.set_password(self.form_result['password']) # TODO: Enable area editing #c.user.first_area_id=self.form_result['first_area'], #user.first_area_level=self.form_result['first_area_level'], #if self.form_result['second_area']: # c.user.second_area_id=self.form_result['second_area'], # c.user.second_area_level=self.form_result['second_area_level'] c.user.fullname = self.form_result['fullname'] Session.flush() Session.commit() h.redirect(h.url(controller='account', action='profile', message='edited'))
def list(self, filetype='html'): c.nodes = Session.query(Node).all() entity_q = Session.query(Node) entity_q = entity_q.limit(request.params.get('limit', None)) c.query = request.params.get('q', '') c.sep = request.params.get('sep', '') if request.params.get('sep_filter', False): entity_q = entity_q.filter(Entity.sep_dir != '') if c.sep: entity_q = entity_q.filter(Entity.sep_dir == c.sep) if c.query: o = or_(Entity.label.like(c.query+'%'), Entity.label.like('% '+c.query+'%')) entity_q = entity_q.filter(o).order_by(func.length(Entity.label)) if filetype=='json': response.content_type = 'application/json' response.headers['Access-Control-Allow-Origin'] = '*' c.entities = entity_q.all() if request.params.get('redirect', False) and len(c.entities) == 1: h.redirect(h.url(controller=self._controller, action='view', filetype=filetype, id=c.entities[0].ID), code=302) else: return render('{type}/{type}-list.'.format(type=self._controller) + filetype)
def _reset(self, username=None): username = username or request.environ.get('REMOTE_USER', False) if not username: abort(401) try: user = h.get_user(username) except: abort(400) new_password = user.reset_password() msg = Message("*****@*****.**", user.email, "InPhO password reset") msg.plain = """ %(name)s, your password at the Indiana Philosophy Ontology (InPhO) has been changed to: Username: %(uname)s Password: %(passwd)s The Indiana Philosophy Ontology (InPhO) Team [email protected] """ % {'passwd' : new_password, 'uname' : user.username, 'name' : user.fullname or user.username or ''} msg.send() Session.commit() h.redirect(h.url(controller='account', action='reset_result'))
def submit(self): ''' This function validates the submitted registration form and creates a new user. Restricted to ``POST`` requests. If successful, redirects to the result action to prevent resubmission. ''' user = User(self.form_result['username'], self.form_result['password'], email=self.form_result['email'], first_area_id=self.form_result['first_area'], first_area_level=self.form_result['first_area_level'], second_area_id=self.form_result['second_area'], second_area_level=self.form_result['second_area_level']) Session.add(user) Session.commit() msg = Message("*****@*****.**", self.form_result['email'], "InPhO registration") msg.plain = """%s, thank you for registering with the Indiana Philosophy Ontology Project (InPhO). You can access your """ % self.form_result[ 'username'] msg.send() h.redirect(h.url(controller='account', action='result'))
def list(self, filetype="html"): c.nodes = Session.query(Node).all() entity_q = Session.query(Node) entity_q = entity_q.limit(request.params.get("limit", None)) c.query = request.params.get("q", "") c.sep = request.params.get("sep", "") if request.params.get("sep_filter", False): entity_q = entity_q.filter(Entity.sep_dir != "") if c.sep: entity_q = entity_q.filter(Entity.sep_dir == c.sep) if c.query: o = or_(Entity.label.like(c.query + "%"), Entity.label.like("% " + c.query + "%")) entity_q = entity_q.filter(o).order_by(func.length(Entity.label)) if filetype == "json": response.content_type = "application/json" response.headers["Access-Control-Allow-Origin"] = "*" c.entities = entity_q.all() if request.params.get("redirect", False) and len(c.entities) == 1: h.redirect( h.url(controller=self._controller, action="view", filetype=filetype, id=c.entities[0].ID), code=302 ) else: return render("{type}/{type}-list.".format(type=self._controller) + filetype)
def submit(self): ''' This function validates the submitted registration form and creates a new user. Restricted to ``POST`` requests. If successful, redirects to the result action to prevent resubmission. ''' user = User( self.form_result['username'], self.form_result['password'], email=self.form_result['email'], first_area_id=self.form_result['first_area'], first_area_level=self.form_result['first_area_level'], second_area_id=self.form_result['second_area'], second_area_level=self.form_result['second_area_level'] ) Session.add(user) Session.commit() msg = Message("*****@*****.**", self.form_result['email'], "InPhO registration") msg.plain = """%s, thank you for registering with the Indiana Philosophy Ontology Project (InPhO). You can access your """ % self.form_result['username'] msg.send() h.redirect(h.url(controller='account', action='result'))
def list(self, filetype='html'): entity_q = Session.query(self._type) #TODO: Remove the following line when Nodes are eliminated entity_q = entity_q.filter(Entity.typeID != 2) c.missing_entity = 0 # get the list of entities #c.entities = entity_q.all() c.nodes = Session.query(Node).filter(Node.parent_id == None) c.nodes = c.nodes.order_by("name").all() c.query = request.params.get('q', '') c.query = c.query.strip() c.sep = request.params.get('sep', '') c.wiki = request.params.get('wiki', '') if request.params.get('sep_filter', False): entity_q = entity_q.filter(Entity.sep_dir != '') if c.sep: entity_q = entity_q.filter(Entity.sep_dir == c.sep) if c.wiki: entity_q = entity_q.filter(Entity.wiki == c.wiki) if c.query: o = or_(Entity.label.like(c.query + '%'), Entity.label.like('% ' + c.query + '%'), Entity.label.like('%-' + c.query + '%')) entity_q = entity_q.filter(o).order_by(func.length(Entity.label)) c.total = entity_q.count() # limit must be the last thing applied to the query entity_q = entity_q.limit(request.params.get('limit', None)) c.entities = entity_q.all() if filetype == 'json': response.content_type = 'application/json' if request.params.get('redirect', False) and len(c.entities) == 1: h.redirect(h.url(controller=self._controller, action='view', filetype=filetype, id=c.entities[0].ID), code=302) else: #if there are no results, show the related SEP results if not c.entities: c.entities = self.missing_entity_search(c.query) if c.entities: c.missing_entity = 1 #raise Exception #render the page return render('{type}/{type}-list.'.format(type=self._controller) + filetype)
def list(self, filetype="html"): entity_q = Session.query(self._type) # TODO: Remove the following line when Nodes are eliminated entity_q = entity_q.filter(Entity.typeID != 2) c.missing_entity = 0 # get the list of entities # c.entities = entity_q.all() c.nodes = Session.query(Node).filter(Node.parent_id == None) c.nodes = c.nodes.order_by("name").all() c.query = request.params.get("q", "") c.query = c.query.strip() c.sep = request.params.get("sep", "") c.wiki = request.params.get("wiki", "") if request.params.get("sep_filter", False): entity_q = entity_q.filter(Entity.sep_dir != "") if c.sep: entity_q = entity_q.filter(Entity.sep_dir == c.sep) if c.wiki: entity_q = entity_q.filter(Entity.wiki == c.wiki) if c.query: o = or_( Entity.label.like(c.query + "%"), Entity.label.like("% " + c.query + "%"), Entity.label.like("%-" + c.query + "%"), ) entity_q = entity_q.filter(o).order_by(func.length(Entity.label)) c.total = entity_q.count() # limit must be the last thing applied to the query entity_q = entity_q.limit(request.params.get("limit", None)) c.entities = entity_q.all() if filetype == "json": response.content_type = "application/json" if request.params.get("redirect", False) and len(c.entities) == 1: h.redirect( h.url(controller=self._controller, action="view", filetype=filetype, id=c.entities[0].ID), code=302 ) else: # if there are no results, show the related SEP results if not c.entities: c.entities = self.missing_entity_search(c.query) if c.entities: c.missing_entity = 1 # raise Exception # render the page return render("{type}/{type}-list.".format(type=self._controller) + filetype)
def panel(self, id, id2): c.entity = h.fetch_obj(Entity, id) c.entity2 = h.fetch_obj(Entity, id2) # redirection for Idea-Idea panels if isinstance(c.entity, Node): c.entity = c.entity.idea id = c.entity.ID if isinstance(c.entity2, Node): c.entity2 = c.entity2.idea id = c.entity2.ID if isinstance(c.entity, Idea) and isinstance(c.entity2, Idea): h.redirect(c.entity.url(action='panel', id2=id2), code=303) return self.search(id, id2)
def panel(self, id, id2): c.entity = h.fetch_obj(Entity, id) c.entity2 = h.fetch_obj(Entity, id2) # redirection for Idea-Idea panels if isinstance(c.entity, Node): c.entity = c.entity.idea id = c.entity.ID if isinstance(c.entity2, Node): c.entity2 = c.entity2.idea id = c.entity2.ID if isinstance(c.entity, Idea) and isinstance(c.entity2, Idea): h.redirect(c.entity.url(action="panel", id2=id2), code=303) return self.search(id, id2)
def list(self, filetype="html", redirect=False): node_q = Session.query(Node) # check for query if request.params.get("q"): node_q = node_q.filter(Node.name.like(u"%" + request.params["q"] + "%")) # if only 1 result, go ahead and view that node if redirect and node_q.count() == 1: h.redirect(h.url(controller="taxonomy", action="view", id=node_q.first().ID, filetype=filetype)) if filetype == "html": c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all() return render("taxonomy/node-list.html") else: c.nodes = node_q.all() return render("taxonomy/node-list.%s" % filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) entity_q = model.meta.Session.query(model.Entity) entity_q = entity_q.filter(model.Entity.typeID != 2) c.nodes = model.meta.Session.query(model.Node).filter( model.Node.parent_id == None).order_by("name").all() c.query = '' c.sep = '' if filetype == 'json': response.content_type = 'application/json' if request.params.get('sep_filter'): entity_q = entity_q.filter(model.Entity.sep_dir != '') if request.params.get('sep'): entity_q = entity_q.filter( model.Entity.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that entity if redirect and entity_q.count() == 1: h.redirect(h.url(controller='entity', action='view', filetype=filetype, id=entity_q.first().ID), code=302) # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(model.Entity.label.like(q + '%'), model.Entity.label.like('% ' + q + '%')) entity_q = entity_q.filter(o).order_by( func.length(model.Entity.label)) # if only 1 result, go ahead and view that idea if redirect and entity_q.count() == 1: return self.view(entity_q.first().ID, filetype) else: c.entities = entity_q.limit(limit) return render('entity/entity-list.' + filetype) c.entities = entity_q.limit(limit) return render('entity/entity-list.' + filetype)
def view(self, id=None, filetype='html'): if filetype == 'html': redirect = request.params.get('redirect', True) else: redirect = request.params.get('redirect', False) sep_filter = request.params.get('sep_filter', False) c.sep_filter = sep_filter c.idea = h.fetch_obj(Idea, id, new_id=True) c.count = len(c.idea.nodes) + len(c.idea.instance_of) + len(c.idea.links_to) if len(c.idea.nodes) > 0: c.node = c.idea.nodes[0] elif len(c.idea.instance_of) > 0: c.node = c.idea.instance_of[0] else: c.node = None c.evaluations = defaultdict(lambda: (-1, -1)) identity = request.environ.get('repoze.who.identity') if identity: c.uid = identity['user'].ID #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.idea.ID, uid=uid).all() eval_q = Session.query(IdeaEvaluation.cons_id, IdeaEvaluation.generality, IdeaEvaluation.relatedness) eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.idea.ID) evals = eval_q.all() evals = map(lambda x: (x[0], (x[1], x[2])), evals) c.evaluations.update(dict(evals)) else: c.uid = None if redirect and len(c.idea.nodes) == 1: h.redirect(h.url(controller='taxonomy', action='view', id=c.idea.nodes[0].ID,filetype=filetype), code=303) if filetype=='json': response.content_type = 'application/json' return render('idea/idea.' + filetype)
def view(self, id=None, filetype="html", format=None): c.sep_filter = request.params.get("sep_filter", False) # Get entity and render template c.entity = h.fetch_obj(self._type, id, new_id=True) if filetype == "rdf": response.content_type = "text/xml" return c.entity.graph().serialize(format=format) # Set MIME type of json files if filetype == "json": response.content_type = "application/json" return c.entity.json() if self._type == Entity: h.redirect(c.entity.url(filetype), code=303) else: return render("{type}/{type}.".format(type=self._controller) + filetype)
def submit(self): ''' This function validates the submitted registration form and creates a new user. Restricted to ``POST`` requests. If successful, redirects to the result action to prevent resubmission. ''' user = User( self.form_result['username'], fullname=self.form_result['fullname'], email=self.form_result['email'], first_area_id=self.form_result['first_area'], first_area_level=self.form_result['first_area_level'], second_area_id=self.form_result['second_area'], second_area_level=self.form_result['second_area_level'] ) Session.add(user) password = user.reset_password() Session.commit() msg = Message("*****@*****.**", self.form_result['email'], "InPhO registration") msg.plain = """Dear %(name)s, Thank you for registering with the Indiana Philosophy Ontology Project (InPhO). You can sign in at https://inpho.cogs.indiana.edu/signin with the following information: Username: %(uname)s Password: %(passwd)s You may change your password at https://inpho.cogs.indiana.edu/account/edit . The Indiana Philosophy Ontology Project (InPhO) Team [email protected] """ % {'passwd' : password, 'uname' : user.username, 'name' : user.fullname or user.username or ''} msg.send() h.redirect(h.url(controller='account', action='result'))
def view(self, id=None, filetype='html', format=None): c.sep_filter = request.params.get('sep_filter', False) # Get entity and render template c.entity = h.fetch_obj(self._type, id, new_id=True) if filetype=='rdf': response.content_type = 'text/xml' return c.entity.graph().serialize(format=format) # Set MIME type of json files if filetype=='json': response.content_type = 'application/json' return c.entity.json() if self._type == Entity: h.redirect(c.entity.url(filetype), code=303) else: return render('{type}/{type}.'.format(type=self._controller) + filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) entity_q = model.meta.Session.query(model.Entity) entity_q = entity_q.filter(model.Entity.typeID != 2) c.nodes = model.meta.Session.query(model.Node).filter(model.Node.parent_id == None).order_by("name").all() c.query = '' c.sep = '' if filetype=='json': response.content_type = 'application/json' if request.params.get('sep_filter'): entity_q = entity_q.filter(model.Entity.sep_dir != '') if request.params.get('sep'): entity_q = entity_q.filter(model.Entity.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that entity if redirect and entity_q.count() == 1: h.redirect(h.url(controller='entity', action='view', filetype=filetype, id=entity_q.first().ID), code=302) # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(model.Entity.label.like(q+'%'), model.Entity.label.like('% '+q+'%')) entity_q = entity_q.filter(o).order_by(func.length(model.Entity.label)) # if only 1 result, go ahead and view that idea if redirect and entity_q.count() == 1: return self.view(entity_q.first().ID, filetype) else: c.entities = entity_q.limit(limit) return render('entity/entity-list.' + filetype) c.entities = entity_q.limit(limit) return render('entity/entity-list.' + filetype)
def update(self, id, terms=None): if not h.auth.is_logged_in(): response.status_int = 401 return "Unauthorized" if not h.auth.is_admin(): response.status_int = 403 return "Forbidden" # if no whitelist is passed in, go with default if terms is None: terms = ["sep_dir", "searchstring", "label"] entity = h.fetch_obj(self._type, id) h.update_obj(entity, terms, request.params) # Check for redirect if request.params.get("redirect", False): h.redirect(h.url(controller=self._controller, action="view", id=entity.ID)) else: # Issue an HTTP success response.status_int = 200 return "OK"
def list(self, filetype='html', redirect=False): node_q = Session.query(Node) # check for query if request.params.get('q'): node_q = node_q.filter( Node.name.like(u'%' + request.params['q'] + '%')) # if only 1 result, go ahead and view that node if redirect and node_q.count() == 1: h.redirect( h.url(controller='taxonomy', action='view', id=node_q.first().ID, filetype=filetype)) if filetype == 'html': c.nodes = Session.query(Node).filter( Node.parent_id == None).order_by("name").all() return render('taxonomy/node-list.html') else: c.nodes = node_q.all() return render('taxonomy/node-list.%s' % filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) idea_q = Session.query(Idea) c.query = '' c.sep = '' #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all() if request.params.get('sep_filter'): idea_q = idea_q.filter(Idea.sep_dir != '') # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%')) idea_q = idea_q.filter(o).order_by(Idea.entropy.desc()) # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) else: c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype) #TODO: Error handling - we shouldn't have multiple results if request.params.get('sep'): idea_q = idea_q.filter(Idea.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) elif idea_q.count() == 0: h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect)) else: c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype) all_param = request.params.get('all', False) node_param = request.params.get('nodes', True) instance_param = request.params.get('instances', True) node_q = idea_q.join((Node,Node.concept_id==Idea.ID)) instance_q = idea_q.join(Instance.idea) if all_param: idea_q = idea_q if not node_param: idea_q = idea_q.except_(node_q) if not instance_param: idea_q = idea_q.except_(instance_q) elif node_param: idea_q = node_q if instance_param: idea_q = idea_q.union(instance_q) elif instance_param: idea_q = instance_q c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype)
def update(self, id, terms=None): if not h.auth.is_logged_in(): response.status_int = 401 return "Unauthorized" if not h.auth.is_admin(): response.status_int = 403 return "Forbidden" #if no whitelist is passed in, go with default if terms is None: terms = ['sep_dir', 'searchstring', 'label'] entity = h.fetch_obj(self._type, id) h.update_obj(entity, terms, request.params) # Check for redirect if request.params.get('redirect', False): h.redirect( h.url(controller=self._controller, action='view', id=entity.ID)) else: # Issue an HTTP success response.status_int = 200 return "OK"
def view(self, id=None, filetype='html'): if filetype == 'html': redirect = request.params.get('redirect', True) else: redirect = request.params.get('redirect', False) sep_filter = request.params.get('sep_filter', False) c.sep_filter = sep_filter # IDEA GETTIN' c.entity = h.fetch_obj(Idea, id, new_id=True) if filetype=='json': response.content_type = 'application/json' return c.entity.json() c.count = len(c.entity.nodes) + len(c.entity.instance_of) + len(c.entity.links_to) c.nodes = list() if c.entity.nodes: c.nodes.extend(c.entity.nodes[:]) for idea in c.entity.instance_of: for node in idea.nodes: c.nodes.append(node) for idea in c.entity.links_to: for node in idea.nodes: c.nodes.append(node) if c.entity.nodes: c.node = c.entity.nodes[0] elif c.entity.instance_of: c.node = c.entity.instance_of[0] # just in case of data corruption # instance_of points to idea, need node if c.node.nodes: c.node = c.node.nodes[0] elif c.entity.links_to: c.node = c.entity.links_to[0] # just in case of data corruption # links_to point to idea, need node if c.node.nodes: c.node = c.node.nodes[0] else: c.node = None # EVALUATION PROCESSING c.evaluations = defaultdict(lambda: (-1, -1)) identity = request.environ.get('repoze.who.identity') if identity: c.uid = identity['user'].ID #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.entity.ID, uid=uid).all() eval_q = Session.query(IdeaEvaluation.cons_id, IdeaEvaluation.generality, IdeaEvaluation.relatedness) eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.entity.ID) evals = eval_q.all() evals = map(lambda x: (x[0], (x[1], x[2])), evals) c.evaluations.update(dict(evals)) else: c.uid = None # REDIRECTING if redirect and len(c.entity.nodes) == 1: h.redirect(h.url(controller='taxonomy', action='view', id=c.entity.nodes[0].ID,filetype=filetype), code=303) return render('idea/idea.' + filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) idea_q = Session.query(Idea) c.query = '' c.sep = '' #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all() if request.params.get('sep_filter'): idea_q = idea_q.filter(Idea.sep_dir != '') if filetype=='json': response.content_type = 'application/json' # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%')) idea_q = idea_q.filter(o).order_by(Idea.entropy.desc()) # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) #TODO: Error handling - we shouldn't have multiple results if request.params.get('sep'): idea_q = idea_q.filter(Idea.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) elif idea_q.count() == 0: h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect)) ''' ### This block of code filters out nodes and instances, reduces occurances of 'ism's ### It is not currently necessary and causes an error in the middle 'elif' block. all_param = request.params.get('all', False) node_param = request.params.get('nodes', True) instance_param = request.params.get('instances', True) node_q = idea_q.join((Node,Node.concept_id==Idea.ID)) instance_q = idea_q.join(Instance.idea) if all_param: idea_q = idea_q if not node_param: idea_q = idea_q.except_(node_q) if not instance_param: idea_q = idea_q.except_(instance_q) elif node_param: idea_q = node_q if instance_param: # ISSUE!!! This union causes an error when executing the query!... why? idea_q = idea_q.union(instance_q) elif instance_param: idea_q = instance_q ''' c.total = idea_q.count() c.entities = idea_q.limit(limit) return render('idea/idea-list.' + filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) idea_q = Session.query(Idea) c.query = '' c.sep = '' #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all() if request.params.get('sep_filter'): idea_q = idea_q.filter(Idea.sep_dir != '') if filetype=='json': response.content_type = 'application/json' # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%')) idea_q = idea_q.filter(o).order_by(Idea.entropy.desc()) # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) else: c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype) #TODO: Error handling - we shouldn't have multiple results if request.params.get('sep'): idea_q = idea_q.filter(Idea.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype)) elif idea_q.count() == 0: h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect)) else: c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype) all_param = request.params.get('all', False) node_param = request.params.get('nodes', True) instance_param = request.params.get('instances', True) node_q = idea_q.join((Node,Node.concept_id==Idea.ID)) instance_q = idea_q.join(Instance.idea) if all_param: idea_q = idea_q if not node_param: idea_q = idea_q.except_(node_q) if not instance_param: idea_q = idea_q.except_(instance_q) elif node_param: idea_q = node_q if instance_param: idea_q = idea_q.union(instance_q) elif instance_param: idea_q = instance_q c.ideas = idea_q.limit(limit) return render('idea/idea-list.' + filetype)
def list(self, filetype='html'): redirect = request.params.get('redirect', False) limit = request.params.get('limit', None) idea_q = Session.query(Idea) c.query = '' c.sep = '' #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all() if request.params.get('sep_filter'): idea_q = idea_q.filter(Idea.sep_dir != '') if filetype == 'json': response.content_type = 'application/json' # Check for query if request.params.get('q'): q = request.params['q'] c.query = q o = or_(Idea.label.like(q + '%'), Idea.label.like('% ' + q + '%')) idea_q = idea_q.filter(o).order_by(Idea.entropy.desc()) # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect( h.url(controller='idea', action='view', id=idea_q.first().ID, filetype=filetype)) #TODO: Error handling - we shouldn't have multiple results if request.params.get('sep'): idea_q = idea_q.filter(Idea.sep_dir == request.params['sep']) c.sep = request.params['sep'] # if only 1 result, go ahead and view that idea if redirect and idea_q.count() == 1: h.redirect( h.url(controller='idea', action='view', id=idea_q.first().ID, filetype=filetype)) elif idea_q.count() == 0: h.redirect( h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect)) ''' ### This block of code filters out nodes and instances, reduces occurances of 'ism's ### It is not currently necessary and causes an error in the middle 'elif' block. all_param = request.params.get('all', False) node_param = request.params.get('nodes', True) instance_param = request.params.get('instances', True) node_q = idea_q.join((Node,Node.concept_id==Idea.ID)) instance_q = idea_q.join(Instance.idea) if all_param: idea_q = idea_q if not node_param: idea_q = idea_q.except_(node_q) if not instance_param: idea_q = idea_q.except_(instance_q) elif node_param: idea_q = node_q if instance_param: # ISSUE!!! This union causes an error when executing the query!... why? idea_q = idea_q.union(instance_q) elif instance_param: idea_q = instance_q ''' c.total = idea_q.count() c.entities = idea_q.limit(limit) return render('idea/idea-list.' + filetype)
def view(self, id=None, filetype='html'): if filetype == 'html': redirect = request.params.get('redirect', True) else: redirect = request.params.get('redirect', False) sep_filter = request.params.get('sep_filter', False) c.sep_filter = sep_filter # IDEA GETTIN' c.entity = h.fetch_obj(Idea, id, new_id=True) if filetype == 'json': response.content_type = 'application/json' return c.entity.json() c.count = len(c.entity.nodes) + len(c.entity.instance_of) + len( c.entity.links_to) c.nodes = list() if c.entity.nodes: c.nodes.extend(c.entity.nodes[:]) for idea in c.entity.instance_of: for node in idea.nodes: c.nodes.append(node) for idea in c.entity.links_to: for node in idea.nodes: c.nodes.append(node) if c.entity.nodes: c.node = c.entity.nodes[0] elif c.entity.instance_of: c.node = c.entity.instance_of[0] # just in case of data corruption # instance_of points to idea, need node if c.node.nodes: c.node = c.node.nodes[0] elif c.entity.links_to: c.node = c.entity.links_to[0] # just in case of data corruption # links_to point to idea, need node if c.node.nodes: c.node = c.node.nodes[0] else: c.node = None # EVALUATION PROCESSING c.evaluations = defaultdict(lambda: (-1, -1)) identity = request.environ.get('repoze.who.identity') if identity: c.uid = identity['user'].ID #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.entity.ID, uid=uid).all() eval_q = Session.query(IdeaEvaluation.cons_id, IdeaEvaluation.generality, IdeaEvaluation.relatedness) eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.entity.ID) evals = eval_q.all() evals = map(lambda x: (x[0], (x[1], x[2])), evals) c.evaluations.update(dict(evals)) else: c.uid = None # REDIRECTING if redirect and len(c.entity.nodes) == 1: h.redirect(h.url(controller='taxonomy', action='view', id=c.entity.nodes[0].ID, filetype=filetype), code=303) return render('idea/idea.' + filetype)