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


Python Session.add方法代码示例

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


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

示例1: get_or_create

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import add [as 别名]
 def get_or_create( cls, username ):
     session = Session()
     authentication = session.query( cls ).filter_by( username = username ).first()
     if not authentication:
         authentication = cls( username = username )
         session.add( authentication )
         session.flush()
     return authentication
开发者ID:maurodoglio,项目名称:Camelot,代码行数:10,代码来源:authentication.py

示例2: model_run

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import add [as 别名]
    def model_run(self, model_context):
        from camelot.view.action_steps import (SelectFile,
                                               UpdateProgress,
                                               Refresh,
                                               FlushSession)

        select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)')
        select_files.single = False
        file_names = yield select_files
        file_count = len(file_names)

        import os
        from camelot.core.orm import Session
        from rms.Model.Orar import Orar

        session = Session()

        for i, file_name in enumerate(file_names):
            yield UpdateProgress(i, file_count)
            title = os.path.splitext(os.path.basename(file_name))[0]
            print(file_name)
            for line in open(file_name):
                vals = line.split(';')[:-1]
                if len(vals) != 8:
                    raise ImportException("Fisierul nu e dat bine")
                if vals[2] not in ['0', '1', '2']:
                    raise ImportException("Frecventa nu e data bine")
                print(vals)
                orar = Orar(*vals)
                print(orar)
                session.add(orar)
                disc = session.query(Discipline).filter(Discipline.disc==orar.disc).first()
                if disc:
                    orar.disciplina = disc
                    session.flush()

        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
开发者ID:rolisz,项目名称:proiect_colectiv,代码行数:42,代码来源:import_orar.py

示例3: model_run

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import add [as 别名]
    def model_run(self, model_context):
        from camelot.view.action_steps import (SelectFile,
                                               UpdateProgress,
                                               Refresh,
                                               FlushSession)

        select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)')
        select_files.single = False
        file_names = yield select_files
        file_count = len(file_names)

        import os
        from camelot.core.orm import Session
        from rms.Model.ResurseUmane import ResurseUmane
        from rms.Model.Discipline import Discipline
        from rms.Model.OreSuplimentare import OreSuplimentare

        session = Session()

        for i, file_name in enumerate(file_names):
            yield UpdateProgress(i, file_count)
            f = open(file_name)
            info_prof = f.readline().split(";")[:-1]
            if session.query(Profesor).filter(Profesor.username == info_prof[0]).first() != None:
                raise UserException("Exista deja profesorul "+info_prof[2])
            prof = Profesor(*info_prof)
            session.add(prof)
            for line in f:
                if line[-1] == ';':
                    vals = line[:-1].split(',')
                else:
                    vals = line[:-2].split(',')


                print(vals)
                try:
                    vals[0] = int(vals[0])
                    oresup = OreSuplimentare(*vals)
                    oresup.profesor = prof
                    session.add(oresup)
                except ValueError:
                    disc = Discipline(*vals)
                    disc.titular = prof
                    session.add(disc)
        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
开发者ID:rolisz,项目名称:proiect_colectiv,代码行数:50,代码来源:import_state.py

示例4: import

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import add [as 别名]
from gradebook.model import (Course,
        Student, StudentContactInfo)
course, = session.query(Course).all()

import csv
with open('class-list.csv', 'rb') as csvfile:
    reader = csv.DictReader(csvfile, delimiter=";")
    for row in reader:
        print row
        ln = row["Last"]
        fn = row["First"]
        student = Student(first_name=unicode(fn.strip()),
                last_name=unicode(ln.strip()),
                user_name=unicode(row["NetID"]),
                course=course)

        session.add(student)
        session.add(StudentContactInfo(
            student=student,
            kind="email",
            value=row["NetID"]+"@illinois.edu",
            ))

        print unicode(student)

#from gradebook.model import Course
#for name in session.query(Course.name):
    #print name

session.flush()
开发者ID:inducer,项目名称:gradebook,代码行数:32,代码来源:import-students.py


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