本文整理汇总了Python中models.Project.resp方法的典型用法代码示例。如果您正苦于以下问题:Python Project.resp方法的具体用法?Python Project.resp怎么用?Python Project.resp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Project
的用法示例。
在下文中一共展示了Project.resp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_post_project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import resp [as 别名]
def api_post_project():
# module_code, slug, token, scolaryear,
# module_title, module_code, instance_code,
# location, title, deadline, promo
# groups, students, resp, template_resp, assistants
from api import db, api_return_error
try:
datas = request.json
tpl = db.session.query(Template).filter_by(codemodule=datas["module_code"], slug=datas["slug"]).first()
if not tpl:
tpl = Template(codemodule=datas["module_code"], slug=datas["slug"])
# repository_name, call*, school, ...
db.session.add(tpl)
t = Project(template=tpl,
token=datas["token"],
scolaryear=datas["scolaryear"],
module_title=datas["module_title"],
module_code=datas["module_code"],
instance_code=datas["instance_code"],
location=datas["location"],
title=datas["title"],
deadline=datetime.strptime(datas["deadline"], "%Y-%m-%d %H:%M:%S"),
promo=datas["promo"],
last_update=datetime.now(),
groups=json.dumps(datas["groups"]))
resp = []
for user in datas["resp"]:
u = db.session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"], login=user["login"])
db.session.add(u)
resp.append(u)
t.resp = resp
template_resp = []
for user in datas["template_resp"]:
u = db.session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"], login=user["login"])
db.session.add(u)
template_resp.append(u)
t.template_resp = template_resp
assistants = []
for user in datas["assistants"]:
u = db.session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"], login=user["login"])
db.session.add(u)
assistants.append(u)
t.assistants = assistants
for user in datas["students"]:
u = db.session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"], login=user["login"])
db.session.add(u)
t.students.append(Project_Student(user=u, project=t))
db.session.add(t)
db.session.add(Task(type="auto", launch_date=t.deadline, project=t))
#db.session.add(Task(type="preliminary", launch_date=project.deadline - datetime.timedelta(days=1), project=project))
db.session.commit()
except IntegrityError as e:
db.session.rollback()
return api_return_error(409, "Conflict", str(e))
except KeyError as e:
return api_return_error(400, "Bad Request", "Field %s is missing" % str(e))
except Exception as e:
db.session.rollback()
logging.error(str(e))
return api_return_error(500, "Server error", str(e))
return jsonify(t.serialize), 201
示例2: fetch
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import resp [as 别名]
def fetch(token, task_id=None):
session = Session()
try:
obj = Fetch(token)
print(obj.result)
t = session.query(Project).filter_by(token=token).first()
print(t)
datas = obj.result
if not t:
logging.info("Create new project")
tpl = session.query(Template).filter_by(codemodule=datas["module_code"], slug=datas["slug"]).first()
if not tpl:
logging.info("Create new Template")
tpl = Template(codemodule=datas["module_code"], slug=datas["slug"])
# repository_name, call*, school, ...
session.add(tpl)
t = Project(template=tpl)
session.add(t)
t.token = datas["token"]
t.scolaryear = datas["scolaryear"]
t.module_title = datas["module_title"]
t.module_code = datas["module_code"]
t.instance_code = datas["instance_code"]
t.location = datas["location"]
t.title = datas["title"]
t.deadline = datetime.strptime(datas["deadline"], "%Y-%m-%d %H:%M:%S")
t.promo = datas["promo"]
t.groups = json.dumps(datas["groups"])
t.last_update = datetime.now()
resp = []
for user in datas["resp"]:
u = session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"],
login=user["login"], old_login=user["old_login"])
session.add(u)
resp.append(u)
t.resp = resp
template_resp = []
for user in datas["template_resp"]:
u = session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"],
login=user["login"], old_login=user["old_login"])
session.add(u)
template_resp.append(u)
t.template_resp = template_resp
assistants = []
for user in datas["assistants"]:
u = session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"],
login=user["login"], old_login=user["old_login"])
session.add(u)
assistants.append(u)
t.assistants = assistants
t.students = []
for user in datas["students"]:
u = session.query(User).filter_by(login=user["login"]).first()
if not u:
u = User(firstname=user["firstname"], lastname=user["lastname"],
login=user["login"], old_login=user["old_login"])
session.add(u)
t.students.append(Project_Student(user=u, project=t))
session.add(t)
need_new = True
for task in t.tasks:
if task.type == "auto":
need_new = False
if task.type == "auto" and task.status != "ongoing" and task.id != task_id and task_id != 0:
task.launch_date = t.deadline
task.status = "todo"
session.add(task)
if need_new:
session.add(Task(type="auto", launch_date=t.deadline, project=t))
session.commit()
return t.serialize
except IntegrityError as e:
session.rollback()
except Exception as e:
session.rollback()
logging.error(str(e))
finally:
session.close()
return False