本文整理汇总了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
示例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
示例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
示例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()