本文整理汇总了Python中membership.Membership.get_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python Membership.get_by_email方法的具体用法?Python Membership.get_by_email怎么用?Python Membership.get_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类membership.Membership
的用法示例。
在下文中一共展示了Membership.get_by_email方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
member = Membership.get_by_email(user.email())
if not member:
# User is not (yet) a member.
self.redirect("/")
return
else:
# Open billing information.
url = member.spreedly_url()
plan = Plan.get_by_name(member.plan)
if plan.legacy:
# Show the legacy plan warning.
current = plan.get_legacy_pair()
self.response.out.write(self.render(
"templates/billing_popup.html",
url=url, legacy=plan, current=current))
return
else:
self.redirect(url)
return
示例2: test_user_suspending
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_user_suspending(self):
user = Membership.get_by_email("[email protected]")
# The next one should suspend us.
user.signins = Config().LITE_VISITS - 1
user.put()
params = {"email": "[email protected]"}
response = self.test_app.post("/api/v1/signin", params)
result = json.loads(response.body)
self.assertEqual(200, response.status_int)
self.assertEqual(0, result["visits_remaining"])
user = Membership.get_by_email("[email protected]")
self.assertEqual(Config().LITE_VISITS, user.signins)
self.assertEqual("no_visits", user.status)
示例3: test_already_existing
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_already_existing(self):
# Make a user in the datastore with the same email, but a different name so
# we can see whether it overrides.
existing_user = Membership(first_name="Michael", last_name="Scarn",
email=self._TEST_PARAMS["email"],
status="active")
existing_user.put()
# Because the user is active, it should prohibit us from overriding.
response = self.test_app.post("/", self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("already exists", response.body)
# User should stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual("Michael", user.first_name)
self.assertEqual("Scarn", user.last_name)
existing_user.status = "suspended"
existing_user.put()
# Even though the user is suspended, it should still prohibit us from
# overriding.
response = self.test_app.post("/", self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("suspended", response.body)
# User should stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual("Michael", user.first_name)
self.assertEqual("Scarn", user.last_name)
existing_user.status = None
existing_user.put()
# Now the user should get silently overriden.
response = self.test_app.post("/", self._TEST_PARAMS)
self.assertEqual(302, response.status_int)
# User should not stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual(self._TEST_PARAMS["first_name"], user.first_name)
self.assertEqual(self._TEST_PARAMS["last_name"], user.last_name)
示例4: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url("/profile"))
return
else:
account = Membership.get_by_email(user.email())
email = "%[email protected]%s" % (account.username, Config().APPS_DOMAIN)
gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(email.lower()).hexdigest()
self.response.out.write(self.render("templates/profile.html", locals()))
示例5: test_signin
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_signin(self):
params = {"email": "[email protected]"}
response = self.test_app.post("/api/v1/signin", params)
result = json.loads(response.body)
self.assertEqual(9, result["visits_remaining"])
# Check that our user signing in got recorded.
user = Membership.get_by_email("[email protected]")
self.assertEqual(1, user.signins)
示例6: test_suspended_user
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_suspended_user(self):
user = Membership.get_by_email("[email protected]")
user.status = "suspended"
user.put()
params = {"email": "[email protected]"}
response = self.test_app.post("/api/v1/signin", params, expect_errors=True)
result = json.loads(response.body)
self.assertEqual(422, response.status_int)
self.assertIn("Could not find", result["message"])
示例7: test_user_restore
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_user_restore(self):
self.user.signins = Config().LITE_VISITS + 2
self.user.status = "no_visits"
self.user.put()
response = self.test_app.get("/cron/reset_signins")
self.assertEqual(200, response.status_int)
user = Membership.get_by_email("[email protected]")
self.assertEqual(0, user.signins)
self.assertEqual("active", user.status)
示例8: test_post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_post(self):
response = self.test_app.post("/", self._TEST_PARAMS)
self.assertEqual(302, response.status_int)
# It should have put an entry in the datastore.
user = Membership.get_by_email("[email protected]")
self.assertNotEqual(None, user)
self.assertEqual("Testy", user.first_name)
self.assertEqual("Testerson", user.last_name)
self.assertEqual("ttesterson", user.twitter)
self.assertEqual("My mom", user.referrer)
self.assertNotEqual(None, user.hash)
示例9: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def get(self):
user = users.get_current_user()
member = Membership.get_by_email(user.email())
if not member:
# User is not (yet) a member.
self.redirect("/")
else:
# Open billing information.
url = member.spreedly_url()
plan = Plan.get_by_name(member.plan)
if plan.legacy:
self.response.out.write(self.render(
"templates/billing_popup.html", url=url))
else:
self.redirect(url)
示例10: post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def post(self):
email = self._get_parameters("email")
if not email:
return
# Get information on the user from the datastore.
user = Membership.get_by_email(email)
if (not user or user.status not in ("active", "no_visits")):
self._rest_error("InvalidEmail",
"Could not find an active user with email '%s'." % (email), 422)
return
remaining = _increment_signins(user)
response = json.dumps({"visits_remaining": remaining})
self.response.out.write(response)
示例11: test_rollover
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def test_rollover(self):
self.user.signins = Config().LITE_VISITS - 2
self.user.status = "active"
self.user.put()
response = self.test_app.get("/cron/reset_signins")
self.assertEqual(200, response.status_int)
user = Membership.get_by_email("[email protected]")
self.assertEqual(-2, user.signins)
self.assertEqual("active", user.status)
# Test that signins_remaining gives us the right number.
test_plan = Plan("test_lite", 1, 100, "A test plan",
signin_limit = Config().LITE_VISITS)
user.plan = "test_lite"
remaining = Plan.signins_remaining(user)
self.assertEqual(Config().LITE_VISITS + 2, remaining)
示例12: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def get(self):
email, properties = self._get_parameters("email", "properties")
if type(properties) is unicode:
# A singleton property.
properties = [properties]
if not email:
return
logging.info("Fetching properties for user '%s'." % (email))
# Get the user data.
found_user = Membership.get_by_email(email)
if not found_user:
logging.error("Found no user with email '%s'." % (email))
self._rest_error("InvalidParameters",
"Found no user with that email.", 422)
return
all_properties = {}
# Get the actual value of all the properties.
for key in found_user.properties().keys():
all_properties[key] = getattr(found_user, key)
use_properties = {}
for prop in properties:
if prop == "":
# We don't actually want any properties.
break
if prop not in all_properties.keys():
logging.error("User has no property '%s'." % (prop))
self._rest_error("InvalidParameters", "User has no property '%s'." % \
(prop), 422)
return
use_properties[prop] = all_properties[prop]
# Pickle datetime objects so we can send them more easily.
if type(use_properties[prop]) == datetime.datetime:
logging.debug("Pickling datetime object.")
use_properties[prop] = pickle.dumps(use_properties[prop])
response = json.dumps(use_properties)
logging.debug("Writing response: %s." % (response))
self.response.out.write(response)
示例13: post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def post(self):
email = self._get_parameters("email")
if not email:
return
# Get information on the user from the datastore.
user = Membership.get_by_email(email)
if not user:
self._rest_error("InvalidParameters",
"Could not find user with email '%s'." % (email), 422)
return
# Increment signins.
user.signins += 1
user.put()
remaining = plans.Plan.signins_remaining(user)
response = json.dumps({"visits_remaining": remaining})
self.response.out.write(response)
示例14: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_email [as 别名]
def get(self):
user = users.get_current_user()
if not user:
logging.debug("Need to login.")
self.redirect(users.create_login_url(self.request.uri))
return
member = Membership.get_by_email(user.email())
if not member:
# This member doesn't exist.
logging.error("No member with email '%s'." % (user.email()))
logout_url = users.create_logout_url(self.request.uri)
error = self.render("templates/error.html",
message="No member with your email was found.<br>" \
"<a href=%s>Try Again</a>" % (logout_url))
self.response.out.write(error)
self.response.set_status(422)
return
self._plan_switch_page(member)