當前位置: 首頁>>代碼示例>>Python>>正文


Python Profile.get方法代碼示例

本文整理匯總了Python中models.profile.Profile.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Profile.get方法的具體用法?Python Profile.get怎麽用?Python Profile.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.profile.Profile的用法示例。


在下文中一共展示了Profile.get方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

# 需要導入模塊: from models.profile import Profile [as 別名]
# 或者: from models.profile.Profile import get [as 別名]
  def create(self):
    form = ProfileForm(self.request.POST)

    if self.request.method == 'POST' and form.validate():
      name = ' '.join([form.first_name.data,
                       form.last_name.data])

      # Create the webapp2_extras.auth user.
      model = self.auth.store.user_model
      ok, user = model.create_user(form.data['email'],
                                   password_raw=form.data['password'])

      if not ok:
        self.session.add_flash(messages.EDITOR_CREATE_ERROR,
                               level='error')
        return self.redirect_to('editors.list')

      # Create the profile.
      profile = Profile(name=name,
                        email=form.data['email'],
                        is_editor=True,
                        auth_user_id=user.key.id())
      profile.put()

      # Force reload of profile object
      Profile.get(profile.key())

      self.session.add_flash(messages.EDITOR_CREATE_SUCCESS)
      return self.redirect_to('editors.list')

    return self.render_to_response('editors/form.haml', {'form': form})
開發者ID:carylF,項目名稱:Caryl-Ford,代碼行數:33,代碼來源:editor.py

示例2: test_forgot_password_post_sends_email

# 需要導入模塊: from models.profile import Profile [as 別名]
# 或者: from models.profile.Profile import get [as 別名]
  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())
開發者ID:carylF,項目名稱:Caryl-Ford,代碼行數:31,代碼來源:test_forgot_password.py

示例3: test_forgot_password_post_resets_activation_key

# 需要導入模塊: from models.profile import Profile [as 別名]
# 或者: from models.profile.Profile import get [as 別名]
  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)
開發者ID:carylF,項目名稱:Caryl-Ford,代碼行數:11,代碼來源:test_forgot_password.py

示例4: update

# 需要導入模塊: from models.profile import Profile [as 別名]
# 或者: from models.profile.Profile import get [as 別名]
  def update(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')
      self.redirect_to('editors.list')

    form = ProfileUpdateForm(self.request.POST, obj=editor)
    form.user_id = editor.key().id()

    if self.request.method == 'GET':
      names = editor.name.split(' ')
      form.first_name.data = names[0]
      form.last_name.data = names[1]

    form.profile_id = editor.key().id()

    if self.request.method == 'POST' and form.validate():
      # Access to the user model is only needed in this section.
      user = editor.get_auth_user()
      editor.name = ' '.join([form.first_name.data, form.last_name.data])

      if form.email.data != editor.email:
        user.auth_ids.remove(editor.email)
        user.auth_ids.append(form.email.data)
        editor.email = form.email.data

      if form.password.data:
        user.password = security.generate_password_hash(form.password.data,
                                                        length=12)

      editor.put()
      user.put()

      # Force reload of profile object
      Profile.get(editor.key())
      self.session.add_flash(messages.EDITOR_UPDATE_SUCCESS)

      return self.redirect_to('editors.list')

    return self.render_to_response('editors/form.haml', {'form': form})
開發者ID:carylF,項目名稱:Caryl-Ford,代碼行數:42,代碼來源:editor.py

示例5: test_forgot_password_post_with_email_trailing_whitespace

# 需要導入模塊: from models.profile import Profile [as 別名]
# 或者: from models.profile.Profile import get [as 別名]
  def test_forgot_password_post_with_email_trailing_whitespace(self):
    profile = self.create_profile()
    params = {'email': profile.email + '   '}
    response = self.app.post(self.uri_for('forgot-password'), params)
    self.assertOk(response)

    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)
    self.assertLength(1, self.mail_stub.get_sent_messages())
    message, = self.mail_stub.get_sent_messages()
    profile = Profile.get(profile.key())
    self.assertEqual('"%s" <%s>' % (profile.name, profile.email), message.to)
開發者ID:carylF,項目名稱:Caryl-Ford,代碼行數:16,代碼來源:test_forgot_password.py


注:本文中的models.profile.Profile.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。