本文整理汇总了Python中vilya.models.project.CodeDoubanProject.add_watch方法的典型用法代码示例。如果您正苦于以下问题:Python CodeDoubanProject.add_watch方法的具体用法?Python CodeDoubanProject.add_watch怎么用?Python CodeDoubanProject.add_watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vilya.models.project.CodeDoubanProject
的用法示例。
在下文中一共展示了CodeDoubanProject.add_watch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fork_and_watch_project
# 需要导入模块: from vilya.models.project import CodeDoubanProject [as 别名]
# 或者: from vilya.models.project.CodeDoubanProject import add_watch [as 别名]
def test_fork_and_watch_project(self):
p6 = CodeDoubanProject.add('project6', owner_id="admin_user",
summary="test", product="fire")
p7 = CodeDoubanProject.add('project7', owner_id="other_user",
summary="test", product="fire")
fork_count = CodeDoubanProject.get_forked_count(p6.id)
p6fork = p6.fork('project6_other_user', 'other_user')
fork_count2 = CodeDoubanProject.get_forked_count(p6.id)
ok_(fork_count2 == fork_count + 1)
ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 0)
p6fork2 = p6fork.fork('project6_fork_other_user', 'other_user')
ok_(CodeDoubanProject.get_forked_count(p6.id) == fork_count + 2)
ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 1)
ok_(CodeDoubanProject.get_forked_count(p6fork2.id) == 0)
watch_count = CodeDoubanProject.get_watched_count(p7.id)
CodeDoubanProject.add_watch(p7.id, 'admin_user')
watch_count2 = CodeDoubanProject.get_watched_count(p7.id)
ok_(watch_count2 == watch_count + 1)
ok_(len(p7.get_watch_users()) == watch_count2)
p6.delete()
p7.delete()
示例2: watch
# 需要导入模块: from vilya.models.project import CodeDoubanProject [as 别名]
# 或者: from vilya.models.project.CodeDoubanProject import add_watch [as 别名]
def watch(request):
user = request.user
if not user:
return request.redirect("/")
errors = ""
if request.method == "POST":
proj_id = request.get_form_var('proj_id')
CodeDoubanProject.add_watch(proj_id, user.name)
project = CodeDoubanProject.get(proj_id)
return request.redirect('/%s/' % project.name)
proj_id = request.get_form_var('proj_id') or ""
project = CodeDoubanProject.get(proj_id)
action = "watch"
return st('watch.html', **locals())
示例3: create
# 需要导入模块: from vilya.models.project import CodeDoubanProject [as 别名]
# 或者: from vilya.models.project.CodeDoubanProject import add_watch [as 别名]
#.........这里部分代码省略.........
mirror = None
def add_people_project(project):
name = "%s/%s" % (project.owner_id, project.name)
_project = CodeDoubanProject.add(
name=name, owner_id=project.owner_id,
summary=project.summary, product=project.product,
intern_banned=project.intern_banned)
return _project
def add_org_project(project):
_project = CodeDoubanProject.add(
name=name, owner_id=project.owner_id,
summary=project.summary, product=project.product,
intern_banned=project.intern_banned)
return _project
def add_mirror_project(project):
name = "mirror/%s" % (project.name)
_project = CodeDoubanProject.add(
name=name, owner_id='mirror', summary=project.summary,
product=project.product, intern_banned=project.intern_banned,
mirror=project.mirror_url)
if _project:
CodeDoubanMirror.add(url=project.mirror_url,
state=MIRROR_STATE_CLONING,
project_id=_project.id,
with_proxy=project.mirror_proxy)
return _project
def add_fork_project(project):
name = "%s/%s" % (project.owner_id, project.name)
_project = CodeDoubanProject.add(
name=name, owner_id=project.owner_id, summary=project.summary,
product=project.product, fork_from=project.fork_from,
intern_banned=project.intern_banned)
if _project:
fork_from_project = CodeDoubanProject.get(project.fork_from)
_project.update(project.summary,
project.product,
name,
fork_from_project.intern_banned)
return _project
def validate_project(project_type, project):
error = ''
if project_type in (PEOPLE_PROJECT, ORGANIZATION_PROJECT):
error = project.validate()
elif project_type == MIRROR_PROJECT:
error = project.validate()
if not error:
error = CodeDoubanMirror.validate(project.mirror_url)
else:
error = project.validate()
return error
def add_project(project):
_project = None
if project_type == PEOPLE_PROJECT:
_project = add_people_project(project)
elif project_type == ORGANIZATION_PROJECT:
_project = add_org_project(project)
elif project_type == MIRROR_PROJECT:
_project = add_mirror_project(project)
else:
_project = add_fork_project(project)
return _project
project = CodeDoubanProject(None, name, user.username, summary,
datetime.now(), product, None, None,
fork_from=fork_from,
intern_banned=intern_banned,
mirror_url=repo_url,
mirror_proxy=with_proxy)
# FIXME: rename org_proj of html
project_type = org_proj
errors = validate_project(project_type, project)
if errors:
return st(template_filename, **locals())
project = add_project(project)
if not project:
fork_from = ''
errors = 'project exists'
return st(template_filename, **locals())
CodeDoubanProject.add_watch(project.id, user.name)
return request.redirect('/%s/' % project.name)
fork_from = ''
if request.get_form_var('fork_from'):
fork_from = CodeDoubanProject.get(request.get_form_var('fork_from'))
name = "%s/%s" % (user.name, fork_from.realname)
if CodeDoubanProject.exists(name):
return request.redirect('/%s/' % name)
projects = CodeDoubanProject.gets_by_owner_id(user.name)
for p in projects:
if p.origin_project_id == fork_from.id and '/' in p.name:
return request.redirect('/%s/' % p.name)
return st(template_filename, **locals())
示例4: new
# 需要导入模块: from vilya.models.project import CodeDoubanProject [as 别名]
# 或者: from vilya.models.project.CodeDoubanProject import add_watch [as 别名]
def new(request, proj_id):
user = request.user
CodeDoubanProject.add_watch(proj_id, user.name)
return json.dumps({"ok": 1})