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


Python meta.Session类代码示例

本文整理汇总了Python中inphosite.model.meta.Session的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _delete_evaluation

    def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None):
        if not h.auth.is_logged_in():
            abort(401)

        id2 = request.params.get('id2', id2)
        uid = request.params.get('uid', uid)
        username = request.params.get('username', username)
        evaluation = self._get_evaluation(id, id2, uid, username, autoCreate=False)
        
        if not evaluation:
            abort(404)

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

        setattr(evaluation, evaltype, -1)

        # Delete evaluation if this eliminates both settings, new db schema
        # will eliminate this need
        if evaluation.generality == -1 and evaluation.relatedness == -1:
            h.delete_obj(evaluation)
        else:
            # save change in evaluation
            Session.flush()
        Session.commit()
        response.status_int = 200
        return "OK"
开发者ID:camerontt2000,项目名称:inphosite,代码行数:28,代码来源:idea.py

示例2: submit

    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("[email protected]", 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'))
开发者ID:camerontt2000,项目名称:inphosite,代码行数:28,代码来源:account.py

示例3: _evaluate

    def _evaluate(self, evaltype, id, id2=None, uid=None, username=None, degree=-1, maxdegree=4):
        """
        Function to submit an evaluation. Takes a POST request containing the consequesnt id and 
        all or none of: generality, relatedness, hyperrank, hyporank.
        """
        if not h.auth.is_logged_in():
            abort(401)

        id2 = request.params.get('id2', id2)
        uid = request.params.get('uid', uid)
        username = request.environ.get('REMOTE_USER', username)

        print "grabbing eval for", username, uid

        if request.environ.get('REMOTE_USER', False):
            evaluation = self._get_evaluation(id, id2, None, username)
        else:
            evaluation = self._get_anon_evaluation(id, id2, request.environ.get('REMOTE_ADDR', '0.0.0.0'))

        # Populate proper generality, relatedness, hyperrank and hyporank values
        # Attempt to convert to integers, if unable, throw HTTP 400
        try: 
            setattr(evaluation, evaltype, 
                    int(request.params.get('degree', getattr(evaluation, evaltype))))
        except TypeError:
            abort(400)


        # Create and commit evaluation
        Session.flush()
        Session.commit()

        # Issue an HTTP success
        response.status_int = 200
        return "OK"
开发者ID:camerontt2000,项目名称:inphosite,代码行数:35,代码来源:idea.py

示例4: create

    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["ISSN", "noesisInclude", "URL", "source", 
                        "abbr", "language", "student", "active"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        journal = Journal(name, **params)
        Session.add(journal)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='journal',
                                                 action='view', id=journal.ID)
        return "Moved temporarily"
开发者ID:etboggs,项目名称:inphosite,代码行数:30,代码来源:journal.py

示例5: create

    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "searchstring", "searchpattern"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'label' in params:
            label = params['label']
            del params['label']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        idea = Idea(label)
        Session.add(idea)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='idea',
                                                 action='view', id=idea.ID)
        return "Moved temporarily"
开发者ID:camerontt2000,项目名称:inphosite,代码行数:29,代码来源:idea.py

示例6: evaluate

    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
        )


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

示例7: create

    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "wiki"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        thinker = Thinker(name, **params)
        Session.add(thinker)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='thinker',
                                                 action='view', id=thinker.ID)
        return "Moved temporarily"
开发者ID:etboggs,项目名称:inphosite,代码行数:29,代码来源:thinker.py

示例8: complete_mining

def complete_mining(entity_type=Idea, filename='graph.txt', root='./'):
    occur_filename = root + "graph-" + filename
    edge_filename = root + "edge-" + filename
    sql_filename = root + "sql-" + filename

    print "processing articles..."
    process_articles(entity_type, occur_filename)

    print "running apriori miner..."
    dm.apriori(occur_filename, edge_filename)
    
    print "processing edges..."
    edges = dm.process_edges(occur_filename, edge_filename)
    ents = dm.calculate_node_entropy(edges)
    edges = dm.calculate_edge_weight(edges, ents)
    
    print "creating sql files..."

    with open(sql_filename, 'w') as f:
        for edge, props in edges.iteritems():
            ante,cons = edge
            row = "%s::%s" % edge
            row += "::%(confidence)s::%(jweight)s::%(weight)s\n" % props
            f.write(row)

    print "updating term entropy..."

    for term_id, entropy in ents.iteritems():
        term = Session.query(Idea).get(term_id)
        if term:
            term.entropy = entropy

    Session.flush()
    Session.commit()
开发者ID:camerontt2000,项目名称:inphosite,代码行数:34,代码来源:sepmining.py

示例9: delete_obj

def delete_obj(obj):
    """
    Deletes any arbitrary object from the SQLAlchemy Session and cascades deletes to evaluations.

    :param obj: object to delete

    """
    Session.delete(obj)
    Session.flush()
开发者ID:etboggs,项目名称:inphosite,代码行数:9,代码来源:helpers.py

示例10: graph_all

 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:camerontt2000,项目名称:inphosite,代码行数:11,代码来源:idea.py

示例11: addlist

def addlist():
    #simply returns the list of published or about to be published sepentries that do not yet have sep_dir fields in the entity table
    entities_q = Session.query(Entity)
    entities_q = entities_q.filter(Entity.sep_dir != None)
    entities_q = entities_q.subquery()
    missing = Session.query(SEPEntry)
    missing = missing.outerjoin((entities_q, SEPEntry.sep_dir == entities_q.c.sep_dir))
    missing = missing.filter(entities_q.c.sep_dir == None)
    #suppress snark, sample
    missing = missing.filter(SEPEntry.title != "Snark")
    missing = missing.filter(SEPEntry.title != "Sample")
    missing = missing.filter(or_(SEPEntry.published == 1, SEPEntry.status == 'au_submit_proofread'))
    return missing.all()
开发者ID:camerontt2000,项目名称:inphosite,代码行数:13,代码来源:sepparse.py

示例12: _get_anon_evaluation

    def _get_anon_evaluation(self, id, id2, ip, autoCreate=True):
        idea1 = h.fetch_obj(Idea, id, new_id=True)
        idea2 = h.fetch_obj(Idea, id2, new_id=True)

        evaluation_q = Session.query(AnonIdeaEvaluation)
        evaluation = evaluation_q.filter_by(ante_id=id, cons_id=id2, ip=ip).first()

        # if an evaluation does not yet exist, create one
        if autoCreate and not evaluation:
            evaluation = AnonIdeaEvaluation(id, id2,ip)
            Session.add(evaluation)

        return evaluation
开发者ID:camerontt2000,项目名称:inphosite,代码行数:13,代码来源:idea.py

示例13: _delete_unary

    def _delete_unary(self, type, id, id2=None):
        thinker = h.fetch_obj(Thinker, id)

        id2 = request.params.get('id2', id2)
        obj = h.fetch_obj(unary_vars[type]['object'], id2)

        if obj in getattr(thinker, unary_vars[type]['property']):
            getattr(thinker, unary_vars[type]['property']).remove(obj)

        Session.commit()

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

示例14: list

    def list(self, filetype='html', redirect=False):
        thinker_q = Session.query(Thinker)
        c.query = ''
        c.sep = ''
        
        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'):
            c.query = request.params['q']
            thinker_q = thinker_q.filter(Thinker.name.like(u'%'+request.params['q']+'%'))
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)
        
        if request.params.get('sep'):
            thinker_q = thinker_q.filter(Thinker.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)

        c.thinkers = thinker_q.all()
        return render('thinker/thinker-list.' + filetype)
开发者ID:etboggs,项目名称:inphosite,代码行数:28,代码来源:thinker.py

示例15: fuzzymatch

def fuzzymatch(string1):
    #note:  fuzzymatch.php must be in php path, e.g.  /usr/lib/php/!!!
    #put in a cron job that runs every half hour for new entries?
    
    entities = Session.query(Entity)
    
    
    matches = []
    
    ##string1 = string1.decode('utf8')
    
    for entity in entities:
        php = PHP("require 'fuzzymatch.php';")
        #php = PHP()
        #print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"
        
        code = '$string1 = utf8_decode("' + string1.encode('utf8') + '");'
        
        #code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
        #code = code + "print $string1; print $string2;"
        #print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
        code = code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
        code = code + """print fuzzy_match($string1, $string2, 2);"""
        
        verdict = php.get_raw(code)
        #print "verdict is " + verdict + "\n"
    
        if float(verdict)>=.5:
            #print entity.label + " is a match!\n"
            entity.matchvalue = verdict
            matches.append(entity)
    
    return matches
开发者ID:camerontt2000,项目名称:inphosite,代码行数:33,代码来源:searchstring.py


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