本文整理汇总了Python中models.Project.key方法的典型用法代码示例。如果您正苦于以下问题:Python Project.key方法的具体用法?Python Project.key怎么用?Python Project.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Project
的用法示例。
在下文中一共展示了Project.key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import key [as 别名]
def post(self):
action = self.request.get('action', 'add')
if action == 'add':
if len(self.request.get('name'))<2:
raise Exception("project name must be at least 2 characters long")
if len(self.request.get('currency'))<1:
raise Exception("project currency must be at least one character long")
# create the project and return the new location to go to
project = Project(name=self.request.get('name'), currency=self.request.get('currency'))
project.put()
# add access rights for this user to the new project
rights = ProjectRights(project=project, user=users.GetCurrentUser(), right=Security.Right_Owner)
rights.put()
# redirect to summary
self.response.out.write("/summary?project=%(key)s" % {'key':project.key()})
elif action == 'delete':
# remove me from the projects right list
project = Project.get(self.request.get('project', ''))
if (not project):
raise Exception("Unknown project!")
# check rights of current user for this project, and deny access if not permitable
rights = ProjectRights.gql("WHERE user=:user and project=:project", user=users.get_current_user(), project=project).get()
if rights:
rights.delete()
# redirect to my page
self.response.out.write("/")
else:
raise Exception("Unknown action '%(action)s'!" % {'action':action})
示例2: add_project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import key [as 别名]
def add_project(request, user):
if request.method=="POST":
# process form
# fail if the name is blank
name = request.POST['name'].strip()
if name == "":
return HttpResponseRedirect( "?error=the+name+needs+to+contain+letters" )
# make and put project
project = Project(user=user,name=name,updated=datetime.datetime.now())
project.put()
# increment project_count
nickname = Nickname.all().filter("user =", user).get()
nickname.project_count += 1
nickname.put()
logging.info( project.key().id() )
# return rendered project div
return render_to_response( "includes/project_div.html", {'project':{'name':project.name,'id':project.key().id()}} )
return render_to_response( "add_project.html", {'error':request.GET.get('error',None)} )
示例3: project_new
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import key [as 别名]
def project_new( self, name, settings ):
owner = current_handler.auth.user.auth_id
project = Project( name=name, owner=owner, settings=settings )
project.put()
return {
'key': str( project.key() )
}