当前位置: 首页>>代码示例>>Python>>正文


Python Session.query方法代码示例

本文整理汇总了Python中inpho.model.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inpho.model.Session的用法示例。


在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    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)
开发者ID:inpho,项目名称:inphosite,代码行数:33,代码来源:taxonomy.py

示例2: evaluate

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def evaluate(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)

        c.idea = h.fetch_obj(Idea, id, new_id=True)
        node_q = Session.query(Node).filter_by(concept_id=id)
        c.node = node_q.first()
        if request.environ.get('REMOTE_USER', False):
            user = h.get_user(request.environ['REMOTE_USER'])

            sq = Session.query(IdeaEvaluation.cons_id)
            sq = sq.filter(IdeaEvaluation.ante==c.idea)
            sq = sq.filter(IdeaEvaluation.uid==user.ID)
            sq = sq.subquery()

            to_evaluate = c.idea.related.outerjoin((sq, Idea.ID==sq.c.cons_id))
            to_evaluate = to_evaluate.filter(sq.c.cons_id==None)

        else:
            to_evaluate = c.idea.related

        c.paginator = paginate.Page(
            to_evaluate,
            page=int(request.params.get('page', 1)),
            items_per_page=10,
            controller='idea',
            action='edit',
            id=id
        )

        response.headers['Access-Control-Allow-Origin'] = '*' 

        return render('idea/idea-edit.html')
开发者ID:colinallen,项目名称:inphosite,代码行数:35,代码来源:idea.py

示例3: list

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    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)
开发者ID:inpho,项目名称:inphosite,代码行数:59,代码来源:entity.py

示例4: graph_all

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
 def graph_all(self, filetype='html', limit=False):
     sep_filter = request.params.get('sep_filter', False) 
     c.sep_filter = sep_filter
     idea_q = Session.query(Idea)
     c.ideas = idea_q.all()
     
     edge_q =\
     Session.query(IdeaGraphEdge).order_by(IdeaGraphEdge.jweight.desc()).limit(3*len(c.ideas))
     c.edges = edge_q.all()
     
     return render('idea/graph_all.' + filetype)
开发者ID:colinallen,项目名称:inphosite,代码行数:13,代码来源:idea.py

示例5: _inpho_token_generator

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
def _inpho_token_generator(document):
    if PUNC_TABLE.get(ord('-')):
        del PUNC_TABLE[ord('-')]
    PUNC_TABLE[ord('\n')] = ord(' ')
    
    rest = document.lower()
    rest = rehyph(rest)
    rest = strip_punc_word(rest)
    query = Session.query(Searchpattern)

    MIN_LEN = 6 
    short_patterns = Session.query(Searchpattern.searchpattern)
    short_patterns = short_patterns.filter(func.length(Searchpattern.searchpattern) < MIN_LEN)
    short_patterns = short_patterns.distinct().all()
    short_patterns = set(w[0] for w in short_patterns)

    while rest:
        if u' ' not in rest:
            yield rest
            return

        first, rest = rest.split(u' ', 1)
        rest = rest.strip()

        # always yield the raw string
        yield first

        # check if we can simply skip the short patterns
        if len(first) < MIN_LEN and first not in short_patterns:
            continue


       
        # search the database for keywords
        patterns = query.filter(Searchpattern.searchpattern.like(first + u' %')).all()
        
        exact_match = query.filter(Searchpattern.searchpattern==first).first()
        if exact_match is not None:
            patterns.append(exact_match)

        for p in patterns:
            # check if multi-phrase starts match in the rest of the phrase.
            if u' ' in p.searchpattern:
                first_pattern_word, longpattern = p.searchpattern.split(u' ',  1)
                if first == first_pattern_word and (rest == longpattern 
			or rest.startswith(longpattern + u' ')):
                    yield u"inpho:{}".format(p.entity.ID)
            elif first == p.searchpattern:
                yield u"inpho:{}".format(p.entity.ID)
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:51,代码来源:inpho.py

示例6: _delete_evaluation

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None):
        id2 = request.params.get('id2', id2)
        uid = request.params.get('uid', uid)
        username = request.params.get('username', username)

        # look for a specific user's feedback
        evaluation = self._get_evaluation(evaltype, id, id2, uid, username, 
                                          autoCreate=False)
        
        # if that feedback does not exist, unleash the nuclear option and delete
        # ALL evaluation facts for this relation, wiping it from the database.
        if h.auth.is_admin() and not evaluation:
            eval_q = Session.query(evaltype)
            eval_q = eval_q.filter_by(ante_id=id, cons_id=id2)
            evals = eval_q.all()

            # wipe them out. all of them.
            for evaluation in evals:
                h.delete_obj(evaluation)
            
            # return ok, with how many were deleted
            response.status_int = 200
            return "OK %d" % len(evals)

        elif not evaluation:
            abort(404) # simply return an error (not evaluated), if not admin

        current_uid = h.get_user(request.environ['REMOTE_USER']).ID
        if evaluation.uid != current_uid and not h.auth.is_admin():
            abort(401)

        h.delete_obj(evaluation)

        response.status_int = 200
        return "OK"
开发者ID:colinallen,项目名称:inphosite,代码行数:37,代码来源:thinker.py

示例7: _list_property

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
 def _list_property(self, property, id, filetype='html', limit=False, sep_filter=False, type='idea'):
     c.idea = h.fetch_obj(Idea, id)
      
     limit = int(request.params.get('limit', limit))
     start = int(request.params.get('start', 0))
     sep_filter = request.params.get('sep_filter', sep_filter)
     property = getattr(c.idea, property)
     if sep_filter:
         property = property.filter(Entity.sep_dir != '')
     
     # TODO: Fix hacky workaround for the AppenderQuery vs. Relationship
     # property issue - upgrading SQLAlchemy may fix this by allowing us to
     # use len() in a smart way.
     try:
         c.total = property.count()
     except TypeError:
         c.total = len(property)
         
      
     if limit:
         property = property[start:start+limit]
     
     c.entities = property
     c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
     return render('%s/%s-list.%s' %(type, type, filetype))
开发者ID:colinallen,项目名称:inphosite,代码行数:27,代码来源:idea.py

示例8: data_integrity

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def data_integrity(self, filetype="html", redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        idea_q = Session.query(Idea)
        c.ideas = list(idea_q)

        # Missing searchstring
        c.missing_string = [idea for idea in c.ideas
                            if not getattr(idea, 'searchstring')]
        
        # Missing searchpattern
        c.missing_pattern = [idea for idea in c.ideas
                             if not getattr(idea, 'searchpattern')]
        
        # Missing sep_dir
        c.missing_sep_dir = [idea for idea in c.ideas
                             if not getattr(idea, 'sep_dir')]
            
        # Duplicates
        c.duplicate = []
        c.sorted_ideas = sorted(c.ideas, key=lambda idea: idea.label)
        for i in range(len(c.sorted_ideas) - 1):
            if c.sorted_ideas[i].label == c.sorted_ideas[i+1].label:
                c.duplicate.append(c.sorted_ideas[i])
                c.duplicate.append(c.sorted_ideas[i+1])
                    
        return render('idea/data_integrity.%s' % filetype)
开发者ID:colinallen,项目名称:inphosite,代码行数:32,代码来源:idea.py

示例9: select_terms

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
def select_terms(entity_type=Idea):
    # process entities
    ideas = Session.query(entity_type)
    ideas = ideas.options(subqueryload('_spatterns'))
    # do not process Nodes or Journals
    ideas = ideas.filter(and_(Entity.typeID!=2, Entity.typeID!=4))
    return ideas.all()
开发者ID:etboggs,项目名称:inpho,代码行数:9,代码来源:sep.py

示例10: missing_entity_search

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def missing_entity_search(self, query):
        query = quote_plus(query)
        url = "http://plato.stanford.edu/cgi-bin/search/xmlSearcher.py?query=" + query

        results = multi_get([url])[0][1]
        json = None
        values_dict = []
        if results:
            tree = ET.ElementTree(ET.fromstring(results))
            root = tree.getroot()
            json = []
            for element in root.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Item"):
                dict = {}
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Location"):
                    dict["Location"] = iter.text
                json.append(dict)

            for j in range(len(json)):
                for key, value in json[j].iteritems():
                    values_dict.append(value)

        entities = Session.query(Entity).filter(Entity.sep_dir.in_(values_dict)).all()
        entities.sort(key=lambda entity: values_dict.index(entity.sep_dir))
        # raise Exception
        return entities
开发者ID:inpho,项目名称:inphosite,代码行数:27,代码来源:entity.py

示例11: get_subgraph

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
 def get_subgraph(ids, thresh=None):
     edge_q = Session.query(IdeaGraphEdge)
     edge_q = edge_q.order_by(IdeaGraphEdge.jweight.desc())
     edge_q = edge_q.filter(IdeaGraphEdge.cons_id.in_(ids))
     edge_q = edge_q.filter(IdeaGraphEdge.ante_id.in_(ids))
     if thresh:
         edge_q = edge_q.filter(IdeaGraphEdge.jweight > thresh)
     return edge_q.all()
开发者ID:camerontt2000,项目名称:inpho,代码行数:10,代码来源:graph.py

示例12: get_user

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
def get_user(login):
    """
    Returns the User object from the model.

    :rtype: :class:`inpho.model.User`
    """
    user = Session.query(User).filter(or_(User.email==login,
                                          User.username==login.lower())).first()
    return user
开发者ID:colinallen,项目名称:inphosite,代码行数:11,代码来源:helpers.py

示例13: make_list

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
def make_list():
    idea = Session.query(Idea).get(646)
    headings = ['Related', 'Instances', 'Hyponyms']
    termslist = zip(idea.related[:10],
                    idea.instances[:10],
                    idea.hyponyms[:10])

    template = Template(filename='lists.mako.html')
    print template.render(termslist=termslist, headings=headings)
开发者ID:inpho,项目名称:evaluations,代码行数:11,代码来源:lists.py

示例14: data_integrity

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def data_integrity(self, filetype='html', redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        journal_q = Session.query(Journal)
        
        # check for query
        if request.params.get('q'):
            journal_q = journal_q.filter(Journal.name.like(u'%'+request.params['q']+'%'))
        
        # get the list of journals
        c.journals = list(journal_q)

        c.missing_issn = []
        c.bad_issn = []
        for journal in c.journals:
            # Missing ISSN
            if not getattr(journal, 'ISSN') or journal.ISSN == '':
                c.missing_issn.append(journal)
            # Journal has bad ISSN format (xxxx-xxxx is good format)
            elif not re.match(r'[0-9]{4}-[0-9]{3}[0-9X]', journal.ISSN):
                c.bad_issn.append(journal)

        # Duplicates
        # It is set up for pairs. If there is more than 2 of the same journal it will have multiples
        c.duplicate = []
        c.sorted_journals = sorted(c.journals, key=lambda journal: journal.label)
        for i in range(len(c.sorted_journals) - 1):
            if c.sorted_journals[i].label == c.sorted_journals[i+1].label:
                c.duplicate.append(c.sorted_journals[i])
                c.duplicate.append(c.sorted_journals[i+1]) 

        # re-get the list of journals (only ones accessed in last 4 weeks)
        # Magic constant of 2419200 corresponds to 4 weeks in seconds
        c.journals = list(journal_q.filter(Journal.last_accessed < (time.time() -2419200)))

        # filter out results into different chunks
        # Valid URL, not found
        c.broken = [journal for journal in c.journals if journal.URL]
        
        # Journal is active, no URL set
        c.missing = [journal for journal in c.journals 
                     if journal.URL is None and journal.active]
        
        # Journal is active, URL is set to blank
        c.blank = [journal for journal in c.journals 
                   if journal.URL == '' and journal.active]
        
        # Jornal is inactive and missing URL
        c.inactive = [journal for journal in c.journals 
                      if journal.URL is None and not journal.active]
        
        return render('journal/data_integrity.' + filetype)
开发者ID:colinallen,项目名称:inphosite,代码行数:57,代码来源:journal.py

示例15: review

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import query [as 别名]
    def review(self):
        if not request.environ.get('REMOTE_USER', False):
            abort(401)
        
        c.user = h.get_user(request.environ['REMOTE_USER'])        

        ieq = Session.query(IdeaEvaluation).order_by(IdeaEvaluation.time.desc())
        c.evaluations = ieq.filter(and_(IdeaEvaluation.uid==c.user.ID,
                                   or_(IdeaEvaluation.generality>-1,
                                       IdeaEvaluation.relatedness>-1))).all()
        
        return render('account/review.html')
开发者ID:colinallen,项目名称:inphosite,代码行数:14,代码来源:account.py


注:本文中的inpho.model.Session.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。