本文整理汇总了Python中project.models.Project.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Project.get_by_id方法的具体用法?Python Project.get_by_id怎么用?Python Project.get_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project.models.Project
的用法示例。
在下文中一共展示了Project.get_by_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_like
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def add_like(cls, project_id, scientist_id):
project = yield Project.get_by_id(project_id)
project.likes += 1
scientist = yield Scientist.get_by_id(scientist_id)
scientist.liked_projects = list(set(scientist.liked_projects.append(project_id)))
yield project.save(fields=['likes'])
yield scientist.save(fields=['liked_projects'])
示例2: delete_like
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def delete_like(cls, project_id, scientist_id):
project = yield Project.get_by_id(project_id)
project.likes -= 1
scientist = yield Scientist.get_by_id(scientist_id)
scientist.liked_projects.remove(project_id)
yield project.save(fields=['likes'])
yield scientist.save(fields=['liked_projects'])
示例3: delete_participation
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def delete_participation(cls, scientist_id, data):
"""
:param scientist_id:
:param data: {role_id, project_id}
"""
scientist = yield Scientist.get_by_id(scientist_id)
project = yield Project.get_by_id(data[u'project_id'])
scientist.participating_projects.remove(dict(project_id=project.id, role_id=data[u'role_id']))
yield scientist.save(fields=[u'participating_projects'])
for i in xrange(len(project.participants)):
if project.participants[i][u'id'] == data[u'role_id']:
project.participants[i][u'status'] = globals.STATUS_DELETED
yield project.save(fields=[u'participants'])
示例4: add_response
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def add_response(cls, conn, data):
"""
Участник нажимает кнопку "Участвовать" у проекта. Добавляем втаблицу откликов новое значение.
Прописываем отклик у ученого и у проекта.
:param data: {scientist_id, project_id, vacancy_id, message}
:type data: dict
"""
project = yield Project.get_by_id(data[u'project_id'])
scientist = yield Scientist.get_by_id(data[u'scientist_id'])
sql_query = get_insert_query(globals.TABLE_RESPONSES, data, returning=u'')
try:
yield momoko.Op(conn.execute, sql_query)
except PSQLException, ex:
logging.exception(ex)
raise
示例5: delete_desired_project
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def delete_desired_project(cls, scientist_id, data):
"""
:param scientist_id:
:param data: {project_id, vacancy_id}
"""
scientist = yield Scientist.get_by_id(scientist_id)
project = yield Project.get_by_id(data[u'project_id'])
scientist.desired_vacancies = [scientist.desired_vacancies[i] for i in xrange(len(scientist.desired_vacancies))
if scientist.desired_vacancies[i][u'vacancy_id'] != data[u'vacancy_id']]
yield scientist.save(fields=[u'desired_vacancies'])
project.responses = [project.responses[i] for i in xrange(len(project.responses))
if (project.responses[i][u'scientist_id'] != scientist_id) and
(project.responses[u'vacancy_id'] != data[u'vacancy_id'])]
yield project.save(fields=[u'responses'])
示例6: delete
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def delete(cls, project_id):
"""
Удалить участников, удалить вакансии, поставить статус откликам - удаленные.
У ученого убрать из managing_project_ids.
"""
project = yield Project.get_by_id(project_id)
for participant_id in project.participants:
yield cls.delete_participant(participant_id)
for vacancy_id in project.vacancies:
yield cls.delete_vacancy(vacancy_id)
for response_id in project.responses:
yield cls.set_del_status_response(response_id)
scientist = yield Scientist.get_by_id(project.manager_id)
scientist.managing_project_ids.remove(project_id)
yield scientist.save(fields=[u'managing_project_ids'], columns=[u'managing_project_ids'])
yield Project.delete(project_id, tbl=Project.TABLE)
示例7: update
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
def update(cls, project_id, project_dict):
if not project_id:
raise Exception(u'No project id provided')
project = yield Project.get_by_id(project_id, load_data=True)
updated_data = project.get_updated_data(project_dict)
if u'vacancies' in updated_data.keys():
vacancies = updated_data.pop(u'vacancies', [])
del_vacancy_ids = set(project.vacancies) - set([v[u'id'] for v in vacancies if u'id' in v])
vacancy_ids = []
for vacancy in vacancies:
# новые вакансии
if not vacancy.get(u'id'):
vacancy.update(project_id=project_id)
v_id = yield cls.add_vacancy(vacancy)
# ищем те, которые изменились
elif vacancy.get(u'id') in project.vacancies:
v_id = yield cls.update_vacancy(vacancy)
else:
raise Exception(u'Strange vacancy id: {}'.format(vacancy[u'id']))
vacancy_ids.append(v_id)
for vacancy_id in del_vacancy_ids:
yield cls.delete_vacancy(vacancy_id)
logging.info(u'New ordered vacancies={}; '
u'Deleted vacancies={}'.format(vacancy_ids, del_vacancy_ids))
updated_data.update(vacancies=vacancy_ids)
if u'participants' in updated_data.keys():
participants = project_dict.pop(u'participants', [])
del_participant_ids = set(project.participants) - set([p[u'id'] for p in participants if u'id' in p])
participant_ids = []
for participant in participants:
# новые участники
if not participant.get(u'id'):
participant.update(project_id=project_id)
p_id = yield cls.add_participant(participant)
# ищем те, которые изменились
elif participant.get(u'id') in project.participants:
p_id = yield cls.update_participant(participant)
else:
raise Exception(u'Strange participant id: {}'.format(participant[u'id']))
participant_ids.append(p_id)
for participant_id in del_participant_ids:
yield cls.delete_participant(participant_id)
logging.info(u'New ordered participants={}; '
u'Deleted participants={}'.format(participant_ids, list(del_participant_ids)))
updated_data.update(participants=participant_ids)
project.populate_fields(updated_data)
if updated_data.keys():
yield project.save(fields=updated_data.keys())
raise gen.Return(dict(project_id=project_id))
示例8: get_select_query
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import get_by_id [as 别名]
sql_query = get_select_query(globals.TABLE_VACANCIES, columns=[u'vacancy_name'],
where=dict(column=u'id', value=data[u'vacancy_id']))
cursor = yield momoko.Op(conn.execute, sql_query)
vacancy_name = cursor.fetchone()[0]
scientist = yield Scientist.get_by_id(data[u'scientist_id'])
participant_data = dict(
project_id=data[u'project_id'],
scientist_id=data[u'scientist_id'],
role_name=vacancy_name,
first_name=scientist.first_name.decode('utf-8') if isinstance(scientist.first_name, str) else scientist.first_name,
last_name=scientist.last_name.decode('utf-8') if isinstance(scientist.last_name, str) else scientist.last_name,
middle_name=scientist.middle_name.decode('utf-8') if isinstance(scientist.middle_name, str) else scientist.middle_name,
)
project = yield Project.get_by_id(data[u'project_id'])
participant_id = yield cls.add_participant(participant_data)
project.participants.append(participant_id)
yield project.save(fields=[u'participants'], columns=[u'participants'])
@classmethod
@gen.coroutine
def delete_response(cls, response_id):
pass
@classmethod
@gen.coroutine
@psql_connection
def set_del_status_response(cls, conn, response_id):
sc_id, p_id, v_id = response_id.split(u':')
sql_query = get_update_query(globals.TABLE_RESPONSES, dict(status=globals.STATUS_DELETED),