当前位置: 首页>>代码示例>>Python>>正文


Python Membership.status方法代码示例

本文整理汇总了Python中membership.Membership.status方法的典型用法代码示例。如果您正苦于以下问题:Python Membership.status方法的具体用法?Python Membership.status怎么用?Python Membership.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在membership.Membership的用法示例。


在下文中一共展示了Membership.status方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ignore_long_suspensions

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import status [as 别名]
  def test_ignore_long_suspensions(self):
    # Ensure that we have a known value for when we start ignoring plans.
    conf = Config()
    conf.PLAN_USER_IGNORE_THRESHOLD = 30

    self.plan1.member_limit = 1

    user = Membership(first_name="Testy", last_name="Testerson",
                      email="[email protected]", plan="plan1",
                      status="active")
    user.put()

    # Initially, the plan should be full, for every status.
    self.assertTrue(self.plan1.is_full())
    user.status = "suspended"
    user.put()
    self.assertTrue(self.plan1.is_full())
    user.status = None
    user.put()
    self.assertTrue(self.plan1.is_full())

    # If we mess with the updated time, it should be ignored when the plan is
    # not active.
    user.updated = datetime.datetime.now() - datetime.timedelta(days=31)

    user.status = "active"
    user.put(skip_time_update=True)
    self.assertTrue(self.plan1.is_full())
    user.status = "suspended"
    user.put(skip_time_update=True)
    self.assertFalse(self.plan1.is_full())
    user.status = None
    user.put(skip_time_update=True)
    self.assertFalse(self.plan1.is_full())
开发者ID:itstehkman,项目名称:hd-signup,代码行数:36,代码来源:test_plans.py

示例2: test_already_existing

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import status [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)
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:45,代码来源:test_main.py

示例3: post

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import status [as 别名]
    def post(self):
        first_name = self.request.get("first_name")
        last_name = self.request.get("last_name")
        twitter = self.request.get("twitter").lower().strip().strip("@")
        email = self.request.get("email").lower().strip()
        plan = self.request.get("plan")

        if not first_name or not last_name or not email:
            self.response.out.write(
                self.render("templates/main.html", message="Sorry, we need name and email address.", plan=plan)
            )
            self.response.set_status(400)
            return

        membership = db.GqlQuery("SELECT * FROM Membership WHERE email = :email", email=email).get()

        if membership:
            # A membership object already exists in the datastore.
            if membership.extra_dnd == True:
                self.response.out.write("Error #237.  Please contact [email protected]")
                self.response.set_status(422)
                return
            if membership.status == "suspended":
                self.response.out.write(
                    self.render(
                        "templates/main.html",
                        message="Your account has been suspended."
                        ' <a href="/reactivate">Click here</a> to reactivate.',
                        plan=plan,
                    )
                )
                self.response.set_status(422)
                return
            elif membership.status in ("active", "no_visits"):
                self.response.out.write(
                    self.render("templates/main.html", message="Account already exists.", plan=plan)
                )
                self.response.set_status(422)
                return
            elif (membership.username and membership.password and membership.plan) and not membership.spreedly_token:
                # They've already filled out everything, but they haven't started a
                # subscription. Take them to the PinPayments page.
                logging.info("Taking user %s directly to PinPayments page." % (membership.username))
                self.redirect(membership.new_subscribe_url(self.request.host))
                return
            else:
                # Existing membership never got activated. Overwrite it.
                logging.info("Overwriting existing membership for %s." % (email))

                membership.first_name = first_name
                membership.last_name = last_name
                membership.email = email
                membership.twitter = twitter
        else:
            # Make a new membership object.
            membership = Membership(first_name=first_name, last_name=last_name, email=email, twitter=twitter)

        if self.request.get("paypal") == "1":
            membership.status = "paypal"
        membership.hash = hashlib.md5(membership.email).hexdigest()
        if "1337" in self.request.get("referrer").upper():
            membership.referrer = re.sub("[^0-9]", "", self.request.get("referrer").upper())
        else:
            membership.referrer = self.request.get("referrer").replace("\n", " ")
        membership.put()

        logging.debug("Using plan: %s" % (plan))
        if plan == "choose":
            # Have the user select a plan.
            self.redirect("/plan/%s" % (membership.hash))
        else:
            # A plan was specified for us, so go on to creating the account.
            logging.info("Got plan '%s', skipping plan selection step." % (plan))
            query = urllib.urlencode({"plan": plan})
            self.redirect("/account/%s?%s" % (membership.hash, query))
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:77,代码来源:main.py

示例4: post

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import status [as 别名]
    def post(self):
        refer = self.request.get('refer')
        first_name = self.request.get('first_name')
        last_name = self.request.get('last_name')
        twitter = self.request.get('twitter').lower().strip().strip('@')
        email = self.request.get('email').lower().strip()
        plan = self.request.get('plan', 'full')
        
        # See if the referring user is valid.
        try:
          ref_first_name = refer.split()[0]
          ref_last_name = refer.split()[1]
          referred_user = db.GqlQuery("SELECT * FROM Membership \
              WHERE first_name = :first_name AND last_name = :last_name",
              first_name = ref_first_name,
              last_name = ref_last_name).get()
        except IndexError:
          referred_user = None
        
        if not first_name or not last_name or not email:
            self.response.out.write(render('templates/main.html', {
                'plan': plan, 'message': "Sorry, we need name and e-mail address."}))
        elif (not referred_user and refer != ""):
          self.response.out.write(render('templates/main.html', {
            'plan': plan,
            'message': "The person who referred you is not an active user."}))
        else:
            
            # this just runs a check twice. (there is no OR in GQL)
            # first name, last name
            existing_member = db.GqlQuery("SELECT * FROM Membership WHERE first_name = :first_name AND last_name = :last_name", first_name=first_name, last_name=last_name).get()
            if existing_member:
                membership = existing_member
            # email
            existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = :email", email=email).get()
            if existing_member:
                membership = existing_member

            first_part = re.compile(r'[^\w]').sub('', first_name.split(' ')[0])
            last_part = re.compile(r'[^\w]').sub('', last_name)
            if len(first_part)+len(last_part) >= 15:
                last_part = last_part[0]
            username = '.'.join([first_part, last_part]).lower()
            if username in fetch_usernames():
                username = email.split('@')[0].lower()
            
            # [email protected]
            existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = :email", email='%[email protected]' % username).get()
            if existing_member:
                membership = existing_member
            
            try:
                membership
                if membership.extra_dnd == True:
                    self.response.out.write("Error #237.  Please contact [email protected]")
                    return
                if membership.status == "suspended":
                    c = Config()
                    self.redirect(str("https://www.spreedly.com/%s/subscriber_accounts/%s" % (c.SPREEDLY_ACCOUNT, membership.spreedly_token)))              
            except NameError:
                membership = None

                
            # old code below
            #existing_member = Membership.get_by_email(email)
            #if existing_member and existing_member.status in [None, 'paypal']:
            #    existing_member.delete()
            if membership is None:
                if referred_user:
                  referuserid = referred_user.username
                else:
                  referuserid = None
                membership = Membership(
                    first_name=first_name, last_name=last_name, email=email,
                    plan=plan, twitter=twitter, referuserid=referuserid)
                if self.request.get('paypal') == '1':
                    membership.status = 'paypal'
                membership.hash = hashlib.md5(membership.email).hexdigest()
                if '1337' in self.request.get('referrer').upper():
                    membership.referrer = re.sub("[^0-9]", "", self.request.get('referrer').upper())
                else:
                    membership.referrer = self.request.get('referrer').replace('\n', ' ')
                membership.put()
            
            # if there is a membership, redirect here
            if membership.status != "active":
              #self.redirect(str('/account/%s' % membership.hash))
              # HRD compatible hack, code taken from AccountHandler::get()
              first_part = re.compile(r'[^\w]').sub('', membership.first_name.split(' ')[0]) # First word of first name
              last_part = re.compile(r'[^\w]').sub('', membership.last_name)
              if len(first_part)+len(last_part) >= 15:
                  last_part = last_part[0] # Just last initial
              username = '.'.join([first_part, last_part]).lower()
              if username in fetch_usernames():
                  username = membership.email.split('@')[0].lower()
              if self.request.get('u'):
                  pick_username = True
              message = escape(self.request.get('message'))
              account_url = str('/account/%s' % membership.hash)
              self.response.out.write(render('templates/account.html', locals()))
#.........这里部分代码省略.........
开发者ID:martinlschumann,项目名称:hd-signup,代码行数:103,代码来源:main.py


注:本文中的membership.Membership.status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。