本文整理汇总了Python中gae_django.auth.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_email
def delete_email(request, username, email):
# the ID we are to delete
auth_id = 'email:%s' % email
user = User.get_by_auth_id('own:%s' % username)
e_user = User.get_by_auth_id(auth_id)
if user is None or e_user is None:
raise Http404("User not found")
if user != request.user or user != e_user:
http403 = HttpResponse("This ain't you!")
http403.status = 403
return http403
if request.method == "POST":
# delete the email from the user
user.auth_ids.remove(auth_id)
user.unique_model.delete_multi(['User.auth_id:%s' % auth_id])
user.put()
return HttpResponseRedirect(
reverse('member-profile', kwargs={'username':request.user.username})
)
return render_to_response('people/delete_email.html',
{'email': email},
context_instance=RequestContext(request))
示例2: post
def post(self):
"""Create a project from the api.
Example::
{
"url": "http://github.com/defunkt/github",
"name": "github",
"description": "You're lookin' at it.",
"watchers": 5,
"forks": 2,
"private": 1,
"email": "[email protected]",
"account": "twitter_name",
},
"""
form = self.parse_form()
if not form.is_valid():
return self.respond_json(form.errors, status_code=400)
# Lookup the user by email or account
email = form.cleaned_data.pop('email', None)
account = form.cleaned_data.pop('account', None)
user = None
if email:
user = User.get_by_auth_id('email:%s' % email)
elif account:
user = User.get_by_auth_id('twitter:%s' % account)
created = False
project_url = form.cleaned_data['url']
project_key = Project.make_key(project_url)
project = project_key.get()
if project is None:
created = True
project = Project(key=project_key, **form.cleaned_data)
project.put()
@ndb.transactional
def txn():
count = getattr(user, 'total', 0)
projects = set(getattr(user, 'projects', []))
user.total = count + 10
user.projects = list(projects.add(project_url))
user.put()
return user
if created and user:
txn()
self.respond_json({'project': self.serialize(project)}, status_code=201 if created else 200)
示例3: edit_address
def edit_address(request, username, template_name='people/edit_address.html'):
from forms import EditAddressForm
user = User.get_by_auth_id('own:%s' % username)
if user == None:
raise Http404("User not found")
if user.key != request.user.key:
http403 = HttpResponse("This ain't you!")
http403.status = 403
return http403
form = EditAddressForm(request.POST or None, user=user)
if form.is_valid():
for key, value in form.cleaned_data.iteritems():
setattr(user,key,value)
user.put()
return HttpResponseRedirect(
reverse('member-profile',
kwargs={'username':request.user.username}
)
)
return render_to_response(template_name,
{'form':form},
context_instance=RequestContext(request))
示例4: edit_profile
def edit_profile(request, username, template_name='people/edit.html'):
from forms import EditUserForm
user = User.get_by_auth_id('twitter:%s' % username)
if user == None:
raise Http404("User not found")
if user.key != request.user.key:
http403 = HttpResponse("This ain't you!")
http403.status = 403
return http403
form = EditUserForm(request.POST or None, user=request.user)
if form.is_valid():
for key in form.cleaned_data:
if key == 'email':
continue
setattr(user, key, form.cleaned_data.get(key))
slugify(user.location)
user.put()
return HttpResponseRedirect(
reverse('member-profile',
kwargs={'username':request.user.username}
)
)
return render_to_response(template_name,
{'form':form},
context_instance=RequestContext(request))
示例5: project_details
def project_details(request, slug, template_name='projects/details.html'):
project_key = ndb.Key('Project', slug)
project = project_key.get()
if project is None:
raise Http404("Project Not Found.")
limit = 100
cursor = request.GET.get('cursor')
if cursor:
cursor = Cursor(urlsafe=cursor)
# TODO: pagination
user_future = User.query().filter(ndb.GenericProperty('projects') == project.url).fetch_async(100)
query = Commit.query().filter(Commit.project_slug == slug).order(-Commit.timestamp)
commit_future = query.fetch_page_async(limit, start_cursor=cursor)
commits, next_cursor, more = commit_future.get_result()
users = user_future.get_result()
if next_cursor is not None:
next_cursor = next_cursor.urlsafe()
return render_to_response(template_name,
{'project': project, 'users': users, 'commits': commits,
'next': next_cursor, 'more': more},
context_instance=RequestContext(request))
示例6: test_testing_mode_off_user_points
def test_testing_mode_off_user_points(self):
settings.TESTING = False
user = self.make_user('marcus')
user.add_auth_id('email:[email protected]')
self.app.post('/api/v1/bitbucket', self.POST)
u = User.get_by_auth_id('email:[email protected]')
total = getattr(u, 'total', None)
self.assertEqual(total, None)
示例7: fix_player_counts
def fix_player_counts(auth_id):
"""Fix a single user counts."""
user = User.get_by_auth_id(auth_id)
ranges = _get_date_ranges()
for start, end in ranges:
count = Commit.query(ancestor=user.key).filter(Commit.timestamp >= start, Commit.timestamp < end).count(1000)
Accumulator.add_count('own:%s' % user.username, start, count, reset=True)
示例8: test_testing_mode_off
def test_testing_mode_off(self):
settings.TESTING = False
user = self.make_user('marcus')
user.add_auth_id('email:[email protected]')
self.app.post('/api/v1/bitbucket', self.POST)
u = User.get_by_auth_id('email:[email protected]')
p_key = Project.make_key('https://bitbucket.org/marcus/project-x/')
# project should not be created
self.assertEqual(p_key.get(), None)
示例9: user_profile
def user_profile(request, username):
user = User.get_by_auth_id('own:%s' % username)
if user == None:
raise Http404("User not found")
commits = Commit.query(ancestor=user.key).order(-Commit.timestamp).fetch(100)
return render_to_response('people/profile.html',
{"commits":commits, 'profile':user},
context_instance=RequestContext(request))
示例10: users_by_location
def users_by_location(request, location_slug,
template_name='people/people_list.html'):
users = User.query(User.location_slug == location_slug)
users.order(-ndb.GenericProperty('total')).fetch(1000)
location = Location.get_by_id(location_slug)
return render_to_response(template_name,
{'users':users, 'location': location, 'slug': location_slug},
context_instance=RequestContext(request))
示例11: wrapper
def wrapper(self, *args, **kwargs):
if login_required:
if self.auth is None:
abort(401)
if registration_required:
# check to see if the user is registered.
user = User.get_by_auth_id(self.auth)
if not user:
abort(403)
return func(self, *args, **kwargs)
示例12: project_details
def project_details(request, slug, template_name='projects/details.html'):
project_key = ndb.Key('Project', slug)
project = project_key.get()
if project is None:
raise Http404("Project Not Found.")
# TODO: pagination
users = User.query().filter(ndb.GenericProperty('projects') == project.url).fetch(1000)
return render_to_response(template_name,
{'project': project, 'users': users},
context_instance=RequestContext(request))
示例13: fix_team
def fix_team(slug, cursor=None, total=0):
# Don't try to lookup slugs that are the empty string.
# hint they don't exist!
if not slug:
return
team_slug = slug
team = Team.get_or_insert(team_slug)
projects = set([])
if cursor:
# we are looping Grab the existing project list so we don't
# wipe out the earlier runs work
team_p = getattr(team, 'projects', [])
projects = set(team_p)
cursor = Cursor(urlsafe=cursor)
people = User.query().filter(ndb.GenericProperty('team_slug') == team_slug)
# Go through the users in chucks
models, next_cursor, more = people.fetch_page(100, start_cursor=cursor)
for model in models:
user_projects = getattr(model, 'projects', [])
user_total = getattr(model, 'total', 0)
# Do a little math to figure out how many commits they have
commits = user_total - (len(user_projects) * 10)
if commits > 0:
logging.info('Adding %s to %s', commits, team_slug)
total += commits
# Add the users projects to the project set (this filters duplicates)
projects.update(user_projects)
# Run update in a transaction
projects = list(projects)
total = total + (len(projects) * 10)
@ndb.transactional
def txn():
team = Team.get_or_insert(team_slug)
team.total = total
team.projects = projects
team.put()
txn()
if more:
# We have more people to loop through!!
return deferred.defer(fix_team, team_slug,
cursor=next_cursor.urlsafe(), total=total)
示例14: leaderboard
def leaderboard(request, template_name='people/leaderboard.html'):
limit = 100
cursor = request.GET.get('cursor')
if cursor:
cursor = Cursor(urlsafe=cursor)
query = User.query().order(-ndb.GenericProperty('total'))
models, next_cursor, more = query.fetch_page(limit, start_cursor=cursor)
return render_to_response(template_name,
{'next':next_cursor, 'more':more,
'users':models},
context_instance=RequestContext(request))
示例15: fix_players
def fix_players(cursor=None):
"""Fix all the players"""
if cursor:
cursor = Cursor(urlsafe=cursor)
query = User.query()
models, next_cursor, more = query.fetch_page(15, start_cursor=cursor)
for model in models:
deferred.defer(fix_player_counts, 'own:%s' % model.username)
if more:
deferred.defer(fix_players, cursor=next_cursor.urlsafe())