本文整理汇总了Python中models.project.Project.save方法的典型用法代码示例。如果您正苦于以下问题:Python Project.save方法的具体用法?Python Project.save怎么用?Python Project.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.project.Project
的用法示例。
在下文中一共展示了Project.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import save [as 别名]
def post(self, *args, **kwargs):
"""Create a new project by providing the details about the project.
If the validation and saving are successful, it response with the
project data and 201 status.
Otherwise, it gives 4XX status and error messages.
"""
name = self.get_argument('name', None)
description = self.get_argument('description', None)
url = self.get_argument('url', None)
leader = self.get_argument('leader', None)
members = self.get_argument('members', None)
teams = self.get_argument('teams', None)
repos = self.get_argument('repos', None)
tags = self.get_argument('tags', None)
if 'user' not in kwargs:
self.raise401()
try:
# todo - better arguments handler
url = url.strip()
url = url if url else None
members_list = []
repos_list = []
teams_list = []
project_leader = kwargs['user']
if leader:
project_leader = User.objects(username=leader).first()
if repos:
for repo in parse_listed_strs(repos):
r = Repo.objects(name=repo).first()
if not r:
continue
repos_list.append(r)
if members:
for member in parse_listed_strs(members):
u = User.objects(username=member).first()
if not u or u == project_leader:
continue
members_list.append(u)
if teams:
for team in parse_listed_strs(teams):
t = Team.objects(name=team).first()
if not t:
continue
teams_list.append(t)
members_list.append(project_leader)
tags_list = parse_listed_strs(tags)
project = Project(
name=name, description=description,
url=url, repos=repos_list,
leader=project_leader, members=members_list,
teams=teams_list, tags=tags_list)
project.save()
project_data = document_to_json(project, filter_set=_FILTER)
self.set_status(201)
self.write(project_data)
except Exception as e:
reason = e.message
self.raise400(reason=reason)
示例2: install_migration_projects
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import save [as 别名]
def install_migration_projects():
"""Migrate the projects data from the old CouchDB storage"""
from models.account import Account
from models.project import Project, Component, Label, Role
for row in __couchdb().view('_design/projects/_view/list'):
value = row['value']
value['_id'] = value.get('_id', '').replace(':', '/')
# resolve the labels INT or EXT
value['labels'] = []
if value.get('_id', '').startswith('INT'):
value['labels'].append(Label.LABEL_INTERNAL)
elif value.get('_id', '').startswith('EXT'):
value['labels'].append(Label.LABEL_EXTERNAL)
elif value.get('_id', '').startswith('MGM') or value.get('_id', '').startswith('OUT'):
value['labels'].append(Label.LABEL_VACATION)
elif value.get('_id', '') == 'NOKIA/OFFICIAL':
value['labels'].append(Label.LABEL_VACATION)
value['_id'] = value.get('_id', '').replace('EXT/', '').replace('INT/', '')
project = Project.query.filter_by(alias=value.get('_id', '')).first()
if not project:
project = Project()
project.alias = value.get('_id', '')
project.title = value.get('title')
project.info = value.get('description')
if value.get('deleted', False):
project.status = Project.STATUS_ACTIVE | Project.STATUS_DELETED
project.save()
print '[MIGRATION:PROJECT]', project.__str__()
items = [(None, value.get('title'))]
for k,v in value.get('partitions', {}).items():
treeRecursion(k, v, None, items)
for component_alias, component_title in items:
if not component_alias:
continue
component = Component.query.filter_by(project=project, alias=component_alias).first()
if not component:
component = Component()
component.alias = component_alias
component.title = component_title
component.project = project
component.save()
print '[MIGRATION:COMPONENT]', project.__str__(), component.__str__()
for labelItem in value.get('labels', []):
label = Label.query.filter_by(title=labelItem, project=project).first()
if not label:
label = Label()
label.title = labelItem
label.project = project
label.save()
示例3: project_edit
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import save [as 别名]
def project_edit(project_id=None):
from models.account import Account
from models.project import Project, Label
project = None
if not project_id:
project = Project()
project.status = Project.STATUS_ACTIVE
if not app.access('project', action='create'):
abort(403)
else:
project_id = urllib.unquote_plus(project_id)
project = Project.query.filter_by(id=project_id).first()
if not project:
abort(404)
elif not app.access('project', action='update', project=project):
abort(403)
validationErrors = []
if request.method == 'POST' and request.form.get('csrf_token', None):
project.alias = request.form.get('project_alias', project.alias).strip()
project.title = request.form.get('project_title', project.title).strip()
project.info = request.form.get('project_info', project.info).strip()
project.status = int(request.form.get('project_status', project.status).strip())
validationErrors.extend(project.validate())
if not validationErrors:
project.save()
if not Label.query.filter_by(project_id=project.id, title=Label.LABEL_DEFAULT).first():
label = Label()
label.project_id = project.id
label.title = Label.LABEL_DEFAULT
label.save()
flash(g._t('project submit success'))
return redirect(url_for('project_view', project_id=urllib.quote_plus(str(project.id))))
if project_id:
title = g._t('edit project')
else:
title = g._t('add project')
if project_id:
breadcrumbs = (
(g._t('projects'), url_for('project_index')),
(project.__str__(), url_for('project_view', project_id=urllib.quote_plus(str(project_id)))),
(title, "#")
)
else:
breadcrumbs = (
(g._t('projects'), url_for('project_index')),
(title, "#")
)
return render_template('project/edit.html', project_id=project_id, project=project, errors=validationErrors, title=title, breadcrumbs=breadcrumbs)
示例4: install_project_data
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import save [as 别名]
def install_project_data():
"""Create all the required projects if not defined"""
from application import db
from models.project import Project, Component, Label
projectList = [
{
'alias': 'MGM',
'title': 'Management records',
'info': None,
'components': [
{
'alias': 'VAC',
'title': 'Vacation',
'info': None
},
{
'alias': 'VAC/KZOT',
'title': 'Vacation. Days off by KZoT',
'info': None
},
{
'alias': 'VAC/NP',
'title': 'Vacation. Unpaid Leave',
'info': None
},
{
'alias': 'VAC/EDU',
'title': 'Vacation. Education',
'info': None
}
],
'labels': [Label.LABEL_GENERAL, Label.LABEL_VACATION]
},
{
'alias': 'OUT',
'title': 'N/A Time',
'info': """Hours sink for time that an employee was available in XMPP but was neither doing work or in stand-by""",
'components': [],
'labels': [Label.LABEL_GENERAL, Label.LABEL_VACATION]
},
{
'alias': 'EDU',
'title': 'Self Education',
'info': """Self Education. Report summary is obligatory!""",
'components': [],
'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL]
},
{
'alias': 'IDLE',
'title': 'Idle Time',
'info': """Hours sink for time that an employee is online and available but doesn't have a specific task""",
'components': [],
'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL]
},
{
'alias': 'PP',
'title': 'P-Product internal tasks',
'info': None,
'components': [],
'labels': [Label.LABEL_GENERAL, Label.LABEL_INTERNAL]
},
{
'alias': 'OFFICE',
'title': 'Office Tasks',
'info': """Shopping for Office, Psychotherapy, Interviews, etc.""",
'components': [],
'labels': [Label.LABEL_INTERNAL]
}
]
for projectItem in projectList:
project = Project.query.filter_by(alias=projectItem['alias']).first()
if not project:
project = Project()
project.alias = projectItem['alias']
project.title = projectItem['title']
project.info = projectItem['info']
project.save()
for componentItem in projectItem['components']:
component = Component.query.filter_by(alias=componentItem['alias'], project=project).first()
if not component:
component = Component()
component.alias = componentItem['alias']
component.title = componentItem['title']
component.info = componentItem['info']
component.project = project
component.save()
for labelItem in projectItem['labels']:
label = Label.query.filter_by(title=labelItem, project=project).first()
if not label:
label = Label()
label.title = labelItem
label.project = project
label.save()
示例5: test_data_create
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import save [as 别名]
def test_data_create():
from models.account import Account
from models.project import Project
from models.report import Report
from models.variable import Variable
data = {'accounts':[], 'projects':[]}
roles = {
'administrator':[],
'privileged_manager':[],
'manager':[],
'privileged_member':[],
'member':[],
}
rolesVariable = Variable.query.filter_by(name='roles', scope='permissions').first()
roles.update(rolesVariable.value or {})
# administrator
administrator_1 = Account({'id':'test.administrator_1', 'email':'[email protected]'})
administrator_1.save()
roles['administrator'].append(administrator_1.id)
data['accounts'].append(administrator_1)
# privileged manager to see everything, manage a project and share management with other manager on a second project
privileged_manager_1 = Account({'id':'test.privileged_manager_1', 'email':'[email protected]'})
privileged_manager_1.save()
roles['privileged_manager'].append(privileged_manager_1.id)
data['accounts'].append(privileged_manager_1)
# managers, one for a single project to manage, another to manage 2 more projects
manager_1 = Account({'id':'test.manager_1', 'email':'[email protected]'})
manager_1.save()
roles['manager'].append(manager_1.id)
data['accounts'].append(manager_1)
manager_2 = Account({'id':'test.manager_2', 'email':'[email protected]'})
manager_2.save()
roles['manager'].append(manager_2.id)
data['accounts'].append(manager_2)
# privileged members aka leads
privileged_member_1 = Account({'id':'test.privileged_member_1', 'email':'[email protected]'})
privileged_member_1.save()
roles['privileged_member'].append(privileged_member_1.id)
data['accounts'].append(privileged_member_1)
privileged_member_2 = Account({'id':'test.privileged_member_2', 'email':'[email protected]'})
privileged_member_2.save()
roles['privileged_member'].append(privileged_member_2.id)
data['accounts'].append(privileged_member_2)
# members - developers
member_1 = Account({'id':'test.member_1', 'email':'[email protected]'})
member_1.save()
roles['member'].append(member_1.id)
data['accounts'].append(member_1)
member_2 = Account({'id':'test.member_2', 'email':'[email protected]'})
member_2.save()
roles['member'].append(member_2.id)
data['accounts'].append(member_2)
member_3 = Account({'id':'test.member_3', 'email':'[email protected]'})
member_3.save()
roles['member'].append(member_3.id)
data['accounts'].append(member_3)
member_4 = Account({'id':'test.member_4', 'email':'[email protected]'})
member_4.save()
roles['member'].append(member_4.id)
data['accounts'].append(member_4)
member_5 = Account({'id':'test.member_5', 'email':'[email protected]'})
member_5.save()
roles['member'].append(member_5.id)
data['accounts'].append(member_5)
rolesVariable.value = roles
rolesVariable.save()
# projects
project_1 = Project({'id':'TEST/PROJECT_1', 'title':'project_1',
'partitions':{'ONE':{'': 'number one', '1': 'first'}},
'members':{
administrator_1.id:'admin'
}})
project_1.save()
data['projects'].append(project_1)
project_2 = Project({'id':'TEST/PROJECT_2', 'title':'project_2',
'partitions':{'TWO':{'': 'number two', '1': 'first', '2':'second'}},
'members':{
manager_1.id:Project.MANAGER_MEMBER,
privileged_member_1.id:'lead',
member_1.id:'markup',
member_2.id:'db_admin',
member_3.id:'developer'
#.........这里部分代码省略.........