本文整理汇总了Python中models.project.Project.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Project.objects方法的具体用法?Python Project.objects怎么用?Python Project.objects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.project.Project
的用法示例。
在下文中一共展示了Project.objects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
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)
示例2: put
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
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)
示例3: delete
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
def delete(self, *args, **kwargs):
"""Delete a project by its name provided in URL.
"""
if 'user' not in kwargs or not args:
self.raise401()
user = kwargs['user']
path = parse_path(args[0])
project = Project.objects(name=path[0], members__in=[user])
if not project:
self.raise401()
try:
project.delete()
self.set_status(204)
self.finish()
except Exception as e:
reason = e.message
self.raise400(reason=reason)
示例4: post
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
def post(self, *args, **kwargs):
if 'user' not in kwargs or args:
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) # days or date
tags = self.get_argument('tags', None)
user = kwargs['user']
project = Project.objects(name=project_name).first()
if not project or user not in project.members:
self.raise401()
try:
due_day = int(due)
except ValueError:
due_day = 0
try:
assign_to_list = []
if assign_to:
for member in parse_listed_strs(assign_to):
u = User.objects(username=member).first()
if not u:
continue
assign_to_list.append(u)
due_time = get_utc_time(due_day * 24 * 3600)
tags_list = parse_listed_strs(tags)
task = Task(
category=category, description=description, project=project,
status=status, priority=priority, assign_to=assign_to_list,
due=due_time, tags=tags_list)
task.save()
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)
示例5: get
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
def get(self, *args, **kwargs):
"""Retrieve the resources of projects for the current user.
If `*args` is provided by matching the URL pattern, the first element
in the args is considered as a project name, then the project data will
be retrieved from Database and send back to the client and the source
owner in the format of JSON.
Otherwise, it responses with a list of projects parcipated by the
user. The request can provide three arugments: `team`, `limit` and
`start`. `team` is used for querying the projects of one team by
its name, which the user is one of its memebers. `limit` is
the max number of items sent back to the client. `start` is the
starting index of the querying results.
Only authenticated user/resouce owner can access by using access_token,
and his/her scopes must include `projects`.
The retrieved resource should always be related to the user, and it is
not allowed to access others' projects or other teams' projects.
.. todo::
restrict the response data and add default limits
"""
if 'user' not in kwargs:
self.raise401()
user = kwargs['user']
if args:
path = parse_path(args[0])
project = Project.objects(name=path[0]).first()
if not project:
self.raise404()
if project and user not in project.members:
self.raise401()
project_data = document_to_json(project, filter_set=_FILTER)
else:
team_name = self.get_argument('team', None)
limit = self.get_argument('limit', None)
start = self.get_argument('start', None)
try:
team_name = parse_path(team_name)[0]
except IndexError:
team_name = None
try:
limit = int(limit)
except Exception:
limit = None
try:
start = int(start)
except Exception:
start = None
if team_name:
team = Team.objects(name=team_name).first()
if not team:
self.raise404()
if user not in team.members:
self.raise403()
project = Project.objects(teams__in=[team])
else:
project = Project.objects(members__in=[user])
if limit and start:
project = project[start:start + limit]
elif limit:
project = project[:limit]
elif start:
project = project[start:]
project_data = query_to_json(project, filter_set=_FILTER)
self.write(project_data)
示例6: put
# 需要导入模块: from models.project import Project [as 别名]
# 或者: from models.project.Project import objects [as 别名]
def put(self, *args, **kwargs):
"""Update a project by its name and other information.
"""
if 'user' not in kwargs or not args:
self.raise401()
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)
user = kwargs['user']
path = parse_path(args[0])
project = Project.objects(name=path[0]).first()
if not project or user not in project.members:
self.raise401()
project_leader = project.leader
update = {}
if name:
update['set__name'] = name
if description:
update['set__description'] = description
if url:
update['set__url'] = url
if leader:
project_leader = User.objects(username=leader).first()
update['set__leader'] = project_leader
if members:
members_list = []
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)
members_list.append(project_leader)
update['set__members'] = members_list
if teams:
teams_list = []
for team in parse_listed_strs(teams):
t = Team.objects(name=team).first()
if not t:
continue
teams_list.append(t)
update['set__teams'] = teams_list
if repos:
repos_list = []
for repo in parse_listed_strs(repos):
r = Repo.objects(name=repo).first()
if not r:
continue
repos_list.append(r)
update['set__repos'] = repos_list
if tags:
tags_list = parse_listed_strs(tags)
update['set__tags'] = tags_list
try:
Project.objects(name=path[0]).update_one(**update)
project = Repo.objects(name=name or path[0]).first()
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)