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


Python Session.add方法代码示例

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


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

示例1: create

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    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 '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)

        school_of_thought = SchoolOfThought(name, **params)
        Session.add(school_of_thought)
        Session.flush()

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

示例2: _get_anon_evaluation

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    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:colinallen,项目名称:inphosite,代码行数:15,代码来源:idea.py

示例3: submit

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    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("[email protected]", 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'))
开发者ID:colinallen,项目名称:inphosite,代码行数:45,代码来源:account.py

示例4: date

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    def date(self, id, id2, filetype="json"):
        """
        Creates a date object, associated to the id with the relation type of
        id2.
        """
        try:
            date = self._get_date(id, id2)
        except DateException as e:
            # TODO: Cleanup this workaround for the Pylons abort function not
            # passing along error messages properly to the error controller.
            response.status = 400
            return str(e)

        try:
            Session.add(date)
            Session.commit()
        except IntegrityError:
            # skip over data integrity errors, since if the date is already in
            # the db, things are proceeding as intended.
            pass

        return "OK"
开发者ID:inpho,项目名称:inphosite,代码行数:24,代码来源:entity.py

示例5: _get_evaluation

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    def _get_evaluation(self, id, id2, uid=None, username=None, 
                        autoCreate=True):
        idea1 = h.fetch_obj(Idea, id, new_id=True)
        idea2 = h.fetch_obj(Idea, id2, new_id=True)

        # Get user information
        if uid:
            uid = h.fetch_obj(User, uid).ID
        elif username:
            user = h.get_user(username)
            uid = user.ID if user else abort(403)
        else:
            uid = h.get_user(request.environ['REMOTE_USER']).ID

        evaluation_q = Session.query(IdeaEvaluation)
        evaluation = evaluation_q.filter_by(ante_id=id, cons_id=id2, uid=uid).first()

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

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

示例6: create

# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import add [as 别名]
    def create(self, entity_type=None, filetype="html", valid_params=None):
        # check if user is logged in
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        sep_dir = None
        params = request.params.mixed()
        if entity_type is None:
            entity_type = int(params["entity_type"])
            del params["entity_type"]

        if valid_params is None:
            if entity_type == 1:  # Idea
                valid_params = ["sep_dir", "searchstring", "searchpattern", "wiki"]
            elif entity_type == 3 or entity_type == 5:  # Thinker or Work
                valid_params = ["sep_dir", "wiki"]
            elif entity_type == 4:  # Journal
                valid_params = [
                    "ISSN",
                    "noesisInclude",
                    "URL",
                    "source",
                    "abbr",
                    "language",
                    "student",
                    "active",
                    "wiki",
                ]
            elif entity_type == 6:  # School of Thought
                valid_params = ["sep_dir", "wiki"]

        if "_method" in params:
            del params["_method"]
        if "redirect" in params:
            del params["redirect"]

        if "sep_dir" in params:
            sep_dir = params["sep_dir"]
            del params["sep_dir"]
        if "label" in params:
            label = params["label"]
            del params["label"]
        elif "name" in params:
            label = params["name"]
            del params["name"]
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        # If entity exists, redirect and return HTTP 302
        c.entity = Session.query(Entity).filter(Entity.label == label).first()
        if c.entity:
            redirect(c.entity.url(filetype, action="view"), code=302)
        else:
            # Entity doesn't exist, create a new one.
            if entity_type == 1:
                c.entity = Idea(label, sep_dir=sep_dir)
            elif entity_type == 3:
                c.entity = Thinker(label, sep_dir=sep_dir)
            elif entity_type == 4:
                c.entity = Journal(label, sep_dir=sep_dir)
            elif entity_type == 5:
                c.entity = Work(label, sep_dir=sep_dir)
            elif entity_type == 6:
                c.entity = SchoolOfThought(label, sep_dir=sep_dir)
            else:
                raise NotImplementedError

            Session.add(c.entity)
            Session.commit()
            if redirect:
                sleep(5)  # TODO: figure out database slowness so this can be removed
                redirect(c.entity.url(filetype, action="view"), code=303)
            else:
                return "200 OK"
开发者ID:inpho,项目名称:inphosite,代码行数:81,代码来源:entity.py


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