本文整理汇总了Python中models.profile.Profile类的典型用法代码示例。如果您正苦于以下问题:Python Profile类的具体用法?Python Profile怎么用?Python Profile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_profile
def create_profile(cls, email=None, password=None, beta_tester=True,
is_admin=False, is_manager=False, is_editor=False,
activated=True, account=None):
# TODO: Move this into a top level function (testing.create_profile)
# Use defaults if anything here is missing.
UserModel = cls.get_auth().store.user_model
if not email:
# Generate an e-mail that should be unique...
email = '%s-%s' % (UserModel.query().count(), cls.DEFAULT_EMAIL)
password = password or cls.DEFAULT_PASSWORD
# Create the auth.user_model.
ok, user = UserModel.create_user(email, password_raw=password)
if not ok:
raise Exception('Error creating auth.User: %s' % email)
if not account:
account = cls.create_account()
# Create the profile.
profile = Profile(name=cls.DEFAULT_PROFILE_NAME, is_admin=is_admin,
is_manager=is_manager, is_editor=is_editor,
email=email, beta_tester=beta_tester,
activated=activated, auth_user_id=user.key.id(),
timezone='UTC', parent=account)
profile.put()
# Return the profile (we can get everything else with that)
return profile
示例2: get
def get(self, artist_id):
# artist_id may be a profile_unique_name or an application_user_id
profile_obj = Profile.get_profile_by_profile_unique_name(artist_id)
if profile_obj is not None:
application_user_id = profile_obj.application_user_id
user_obj = User.get_user_by_application_user_id(application_user_id)
if user_obj is None:
# TODO : All profiles should have a user associated with them. Log or handle the event where there is no User associated with a profile.
# There is no user associated with the profile!
pass
else:
user_obj = User.get_user_by_application_user_id(artist_id)
if user_obj is not None:
profile_obj = Profile.get_profile_by_application_user_id(user_obj.application_user_id)
if user_obj is not None:
self.template_values['user_exists'] = True
self.template_values['artist_name'] = user_obj.first_name + ' ' + user_obj.last_name
if profile_obj is not None:
self.template_values['profile_unique_name'] = profile_obj.profile_unique_name
if profile_obj.bio is not None and not re.match(r"^\s*$", profile_obj.bio):
self.template_values['profile_bio'] = profile_obj.bio
if profile_obj.profile_picture is not None:
self.template_values['profile_picture'] = profile_obj.profile_picture
art_objs = Art.get_art(user_obj.application_user_id)
art_list = list()
for art_obj in art_objs:
art_list.append({'art_obj': art_obj})
self.template_values['art_list'] = art_list
self.template_values['artist_image_count'] = len(self.template_values['art_list'])
else:
self.template_values['user_exists'] = False
template = self.get_template('templates/artist_content.html')
self.response.write(template.render(self.template_values))
示例3: get
def get(self, blip_key=None):
blip = Blip.get(blip_key)
if blip is None:
return self.error(404)
login_user = self.get_current_user()
if blip.meeting and not blip.meeting.has_member(login_user):
return self.error(401)
user = blip.user
_, profile = Profile.get_or_create_from_user(user)
is_self = user == login_user
has_followed = False
if not is_self:
has_followed = Follow.gql('WHERE from_user = :1 AND to_user = :2',
login_user, user).get() is not None
followers = Follow.who_subscribe_you(user)
follower_profiles = []
for f in followers:
c, p = Profile.get_or_create_from_user(f.from_user)
follower_profiles.append(p)
followees = Follow.your_subscribers(user)
followee_profiles = []
for f in followees:
c, p = Profile.get_or_create_from_user(f.to_user)
followee_profiles.append(p)
return self.render('blip_item.html', locals())
示例4: get
def get(self):
user = self.get_current_user()
created, profile = Profile.get_or_create_from_user(user)
followers = Follow.who_subscribe_you(user)
follower_profiles = []
for f in followers:
c, p = Profile.get_or_create_from_user(f.from_user)
follower_profiles.append(p)
followees = Follow.your_subscribers(user)
followee_profiles = []
for f in followees:
c, p = Profile.get_or_create_from_user(f.to_user)
followee_profiles.append(p)
try:
page = int(self.request.get('page', '1'))
except ValueError:
page = 1
pagesize = settings.BLIP_PAGE_SIZE
paginator = SimplePaginator(BlipLink.qs_for_user(user),
page, pagesize)
blips = each_profiles(paginator.object_list, field='author')
is_self = True
return self.render('home.html', locals())
示例5: test_signup_page_flow
def test_signup_page_flow(self):
# Check that things are empty
self.assertLength(0, Profile.all())
# Sign up with the form
response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA)
self.assertRedirects(response, self.uri_for('dashboard', tour=''))
# Check that we are actually logged in
response = self.app.get(response.location)
self.assertLoggedIn()
# Check that one of everything was created
self.assertLength(1, Profile.all())
profile = Profile.all().get()
# Check the basic data
self.assertEqual(self.SIGNUP_DATA['email'], profile.email)
self.assertEqual(self.SIGNUP_DATA['name'], profile.name)
# Logout and log back in to test that the password works
self.logout()
response = self.login(self.SIGNUP_DATA['email'],
self.SIGNUP_DATA['password'])
self.assertRedirects(response, self.uri_for('dashboard'))
示例6: test_signup_sends_welcome_email
def test_signup_sends_welcome_email(self):
# Sign up successfully
response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA)
self.assertRedirects(response, self.uri_for('dashboard', tour=''))
# Check that a profile was created
profile = Profile.get_by_email(self.SIGNUP_DATA['email'])
self.assertIsNotNone(profile)
# Check that a mail-sending task is in the queue
tasks = self.taskqueue_stub.GetTasks('mail')
self.assertLength(1, tasks)
# Run the task (it should be a deferred call) and check that an e-mail
# is sent
task, = tasks
deferred.run(base64.b64decode(task['body']))
messages = self.mail_stub.get_sent_messages()
self.assertLength(1, messages)
message, = messages
self.assertEqual('"%s" <%s>' % (profile.name, profile.email), message.to)
self.assertEqual('Welcome to Daily Meeting!', message.subject)
self.assertEqual('"Daily Meeting" <[email protected]>',
message.sender)
self.assertEqual('"Daily Meeting Support" <[email protected]>',
message.reply_to)
activation_key = Profile.all().get().activation_key
activation_url = self.uri_for('profile.activate', k=activation_key)
self.assertIn(activation_url, message.body.decode())
self.assertIn(activation_url, message.html.decode())
示例7: test_signup_with_existing_email
def test_signup_with_existing_email(self):
response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA)
self.assertRedirects(response)
self.assertLength(1, Profile.all())
response = self.app.post(self.uri_for('signup'), self.SIGNUP_DATA)
self.assertOk(response)
self.assertLength(1, Profile.all())
email_field = response.pyquery('input#email')
self.assertLength(1, email_field)
self.assertNotEqual('', email_field.attr['data-error'])
示例8: test_forgot_password_post_only_has_homepage_login_form
def test_forgot_password_post_only_has_homepage_login_form(self):
params = {'email': '[email protected]'}
self.assertIsNone(Profile.get_by_email(params['email']))
response = self.app.post(self.uri_for('forgot-password'), params)
self.assertOk(response)
self.assertTemplateUsed('forgot_password.haml')
self.assertLength(1, response.pyquery('form#login-form'))
示例9: test_forgot_password_post_sends_email
def test_forgot_password_post_sends_email(self):
self.assertNotLoggedIn()
profile = self.create_profile()
response = self.app.get(self.uri_for('forgot-password'))
form = response.forms['forgot-password']
form['email'] = profile.email
response = form.submit()
# Check the task was put on the mail queue.
tasks = self.taskqueue_stub.get_filtered_tasks(queue_names='mail')
self.assertIn('mail', tasks[0].headers['X-AppEngine-QueueName'])
task, = tasks
deferred.run(task.payload)
messages = self.mail_stub.get_sent_messages()
self.assertLength(1, messages)
message, = messages
profile = Profile.get(profile.key())
# Reload profile to get new activation key.
self.assertEqual('"%s" <%s>' % (profile.name, profile.email),
message.to)
self.assertEqual(constants.FULL_NO_REPLY_EMAIL, message.sender)
self.assertEqual(constants.FULL_SUPPORT_EMAIL, message.reply_to)
self.assertIn(profile.activation_key, message.body.decode())
self.assertIn(profile.activation_key, message.html.decode())
recover_uri = self.uri_for('forgot-password', k=profile.activation_key)
self.assertIn(recover_uri, message.body.decode())
self.assertIn(recover_uri, message.html.decode())
示例10: login
def login(self):
error = None
if self.request.method == "POST":
email = self.request.POST.get("email", "").strip()
password = self.request.POST.get("password", "").strip()
user = Profile.get_by_email(email)
if not user:
error = "User not found"
else:
try:
self.auth.get_user_by_password(email, password)
except auth.InvalidPasswordError:
error = "Invalid password!"
except auth.InvalidAuthIdError:
error = "Unknown e-mail address!"
if not user.beta_tester:
self.session.add_flash(value="Please ensure you are cleared for beta testing.", level="error")
return self.redirect_to("login")
if self.get_current_profile():
redirect = self.request.get("redirect")
return self.redirect(redirect or self.uri_for("home"))
else:
return self.render_to_response("login.haml", {"error": error})
示例11: verify_access
def verify_access(self, *args):
user = users.GetCurrentUser()
if user:
profile = Profile.gql("WHERE user = :1", user)
current_profile = profile.get()
if role == current_profile.role:
handler_method(self, *args)
return
self.response.out.write('<html><head></head><body>Access denied</body></html>')
示例12: post
def post(self):
user = self.get_current_user()
created, profile = Profile.get_or_create_from_user(user)
self.errors = []
try:
self.validate(profile)
except Exception, e:
self.errors = [str(e)]
return self.get()
示例13: delete
def delete(self, id):
editor = Profile.get_by_id(int(id))
if not editor or not editor.is_editor:
self.session.add_flash(messages.EDITOR_NOT_FOUND, level='error')
return self.redirect_to('editors.list')
editor.delete()
self.session.add_flash(messages.EDITOR_DELETE_SUCCESS)
return self.redirect_to('editors.list')
示例14: test_forgot_password_post_resets_activation_key
def test_forgot_password_post_resets_activation_key(self):
profile = self.create_profile()
old_activation_key = profile.activation_key
params = {'email': profile.email}
response = self.app.post(self.uri_for('forgot-password'), params)
self.assertOk(response)
profile = Profile.get(profile.key())
self.assertNotEqual(old_activation_key, profile.activation_key)
示例15: get
def get(self):
path = os.path.join(os.path.dirname(__file__),
'../views/admin/index.html')
template_values = {
'name': self.__class__.__name__,
'profiles': Profile.all(),
}
self.response.out.write(template.render(path, template_values))