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


Python Membership.referrer方法代码示例

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


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

示例1: post

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import referrer [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

示例2: post

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import referrer [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.referrer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。