本文整理汇总了Python中models.project.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prj_add
def prj_add():
values = json.loads(request.form['params'])
try:
prjid = Project.add(values)
except Exception as ex:
return jsonify(error=str(ex))
return jsonify(prjid=prjid, projects=Project.get_all())
示例2: doPivot
def doPivot(pivot_config):
# Shorthand
filter = pivot_config['filter']
pivot = pivot_config['pivot']
# Active Database Connection
session = get_database()
# Load project
project = Project(session, search_by= { 'name' : filter['project'] })
# Load project data
project_data = project.getData(filter['query'])
# Convert to data frame using specified function
toDataframe = Registry.r[pivot_config['toDataframe']]['f']
project_data_to_dataframe = toDataframe(project_data)
## apply pivot functions
for f in pivot:
function_name = f['function']
arguments = f['kwargs']
project_data_to_dataframe = Registry.r[function_name]['f'](project_data_to_dataframe, arguments)
return project_data_to_dataframe
示例3: post
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)
示例4: test_data_delete
def test_data_delete():
from models.account import Account
from models.project import Project
from models.report import Report
from models.variable import Variable
roles = {
'administrator':[],
'privileged_manager':[],
'manager':[],
'privileged_member':[],
'member':[],
}
rolesVariable = Variable.query.filter_by(name='roles', scope='permissions').first()
roles.update(rolesVariable.value or {})
for account in [account for account in Account.all() if account.id.startswith('test.')]:
for role_id, members in roles.items():
if account.id in members:
roles[role_id].remove(account.id)
Account.delete(account.id)
flash('account deleted: '+str(account))
rolesVariable.value = roles
rolesVariable.save()
for project in [project for project in Project.all() if project.id.startswith('TEST/')]:
Project.delete(project.id)
flash('project deleted: '+str(project))
return redirect(url_for('test_data_index'))
示例5: prj_drop
def prj_drop():
prjid = json.loads(request.args['prjid'])
success = Project.delete(prjid)
if not success:
msg = 'Record not deleted for unknown reason. Contact admin.'
return jsonify(error=msg)
data = Project.get_all()
return jsonify(projects=data)
示例6: project_edit
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)
示例7: prj_update
def prj_update():
values = json.loads(request.form['params'])
prjid = values['id']
try:
numrows = Project.update(values)
if numrows != 1:
msg = 'Record not updated for unknown reason. Contact admin.'
return jsonify(error=msg)
except Exception as ex:
return jsonify(error=str(ex))
return jsonify(prjid=prjid, projects=Project.get_all())
示例8: project
def project(session, name, **kwargs):
res = session.query(Project).filter(Project.name == name).first()
if res:
print '%s already exists' % res
if not res:
project = Project(name)
project.comment = kwargs.get('comment')
project.description = kwargs.get('description')
project.notes = kwargs.get('notes')
project.date_added = datetime.datetime.now()
session.add(project)
session.commit()
示例9: get
def get(self, *args, **kwargs):
if 'user' not in kwargs:
self.raise401()
user = kwargs['user']
if args:
path = parse_path(args[0])
task = Task.objects(id=path[0]).first()
if not task:
self.raise404()
if user not in task.project.members:
self.raise401()
task_data = document_to_json(task, filter_set=_FILTER)
else:
project_name = self.get_argument('project', None)
limit = self.get_argument('limit', None)
start = self.get_argument('start', None)
try:
limit = int(limit)
except:
limit = None
try:
start = int(start)
except:
start = None
try:
project_name = parse_path(project_name)[0]
except IndexError:
project_name = None
if project_name:
project = Project.objects(name=project_name).first()
if not project:
self.raise404()
if user not in project.members:
self.raise403()
tasks = Task.objects(project=project)
else:
projects = Project.objects(members__in=[user]).all()
tasks = []
for project in projects:
ts = Task.objects(project=project).all()
tasks += list(ts)
if limit and start:
tasks = tasks[start: start+limit]
elif limit:
tasks = tasks[:limit]
elif start:
tasks = tasks[start:]
task_data = query_to_json(tasks, filter_set=_FILTER)
self.write(task_data)
示例10: install_migration_projects
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()
示例11: set_project_env
def set_project_env():
form = request.form
project = form['project']
env = form['env']
content = {}
p = Project.get_by_name(project)
if not p.is_accessible(g.user):
return {'reason': '你没有操作这个项目的权限'}, 403
for line, i in enumerate(form['content'].split('\n')):
if not i.strip():
continue
kv = i.split('=', 1)
if len(kv) == 1:
raise ValueError('invalid env item %s at line %d' % (i, line + 1))
content[kv[0].strip()] = kv[1].strip()
try:
eru.set_app_env(project, env, **content)
except Exception as e:
print e.message
log = OPLog.create(g.user.id, OPLOG_ACTION.set_project_env)
log.data = content
log.project_name = project
示例12: listActiveReports
def listActiveReports(cls, start_date=None, end_date=None, accounts=None, components=None):
from models.account import Account
from models.project import Project, Component
from models.report import Report
query = Report.query\
.filter(~Report.status.in_(Report._r(Report.STATUS_DELETED)))\
.join(Report.account)\
.filter(~Account.status.in_(Account._r(Account.STATUS_DELETED)))\
.join(Report.component, aliased=True)\
.filter(~Component.status.in_(Component._r(Component.STATUS_DELETED)))\
.join(Report.project, aliased=True)\
.filter(~Project.status.in_(Project._r(Project.STATUS_DELETED)))
if start_date:
query = query.filter(Report.due_date>=start_date)
if end_date:
query = query.filter(Report.due_date<=end_date)
if accounts:
query = query.filter(Report.account_id.in_(accounts))
if components:
query = query.filter(Report.component_id.in_(components))
query = query.order_by(Account.first_name, Account.last_name, Account.alias, Report.due_date, Report.created)
return query.all()
示例13: deploy_container_api
def deploy_container_api():
form = request.form
project = form['project']
if project == APPNAME_ERU_LB:
raise ValueError('Unable to deploy eru-lb, do it on load balance page')
p = Project.get_by_name(project)
if not p.is_accessible(g.user):
return {'reason': '你没有操作这个项目的权限'}, 403
version = form['version']
eru.deploy_private(
group_name=g.user.group,
pod_name=form['pod'],
app_name=project,
ncore=form.get('ncore', type=float),
ncontainer=form.get('ncontainer', type=int),
version=version,
entrypoint=form['entrypoint'],
env=form['env'],
network_ids=form.getlist('network'),
host_name=form.get('host'),
args=form['extendargs'].split(' '),
)
log = OPLog.create(g.user.id, OPLOG_ACTION.create_container)
log.project_name = project
log.image = '%s:%s' % (project, version)
示例14: set_sub_items
def set_sub_items(self, api_count):
""" (int)
Set the projects for the organization
"""
# Get all of our projects in that organization and loop through them
project_list = self.api_organization.projects.get()
api_count = check_throttle(api_count)
for project in project_list:
# Print out the project name and slug
#print Fore.BLUE + "\t%s\t%s" % (project['name'],project['slug'])
new_project = Project(json = project, api = self.api_organization)
new_project.set_sub_items(api_count)
self.add_project(new_project)
示例15: put
def put(self, *args, **kwargs):
if 'user' not in kwargs or not args:
self.raise401()
update = {}
user = kwargs['user']
task_id = parse_path(args[0])[0]
task = Task.objects(id=task_id).first()
project = task.project
if not project or user not in project.members:
self.raise401()
category = self.get_argument('category', None)
description = self.get_argument('description', None)
project_name = self.get_argument('project', None)
status = self.get_argument('status', None)
priority = self.get_argument('priority', None)
assign_to = self.get_argument('assign_to', None)
due = self.get_argument('due', None)
tags = self.get_argument('tags', None)
if category:
update['set__category'] = category
if description:
update['set__description'] = description
if project_name:
project = Project.objects(name=project_name).first()
if not project or user not in project.members:
self.raise401()
update['set__project'] = project
if assign_to:
assign_to_list = []
for member in parse_listed_strs(assign_to):
u = User.objects(username=member).first()
if not u:
continue
assign_to_list.append(u)
update['set__assign_to'] = assign_to_list
if status:
update['set__status'] = status
if priority:
update['set__priority'] = priority
if due:
try:
due_day = int(due)
except ValueError:
due_day = 0
due_time = get_utc_time(due_day * 24 * 3600)
update['set__due'] = due_time
if tags:
tags_list = parse_listed_strs(tags)
update['set__tags'] = tags_list
try:
Task.objects(id=task_id).update_one(**update)
task = Task.objects(id=task_id).first()
task_data = document_to_json(task, filter_set=_FILTER)
self.set_status(201)
self.write(task_data)
except Exception as e:
reason = e.message
self.raise400(reason=reason)