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


Python models.RNewUserQueue類代碼示例

本文整理匯總了Python中apps.profile.models.RNewUserQueue的典型用法代碼示例。如果您正苦於以下問題:Python RNewUserQueue類的具體用法?Python RNewUserQueue怎麽用?Python RNewUserQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: stripe_form

def stripe_form(request):
    user = request.user
    success_updating = False
    stripe.api_key = settings.STRIPE_SECRET
    plan = int(request.GET.get('plan', 2))
    plan = PLANS[plan-1][0]
    error = None
    
    if request.method == 'POST':
        zebra_form = StripePlusPaymentForm(request.POST, email=user.email)
        if zebra_form.is_valid():
            user.email = zebra_form.cleaned_data['email']
            user.save()
            
            try:
                customer = stripe.Customer.create(**{
                    'card': zebra_form.cleaned_data['stripe_token'],
                    'plan': zebra_form.cleaned_data['plan'],
                    'email': user.email,
                    'description': user.username,
                })
            except stripe.CardError:
                error = "This card was declined."
            else:
                user.profile.strip_4_digits = zebra_form.cleaned_data['last_4_digits']
                user.profile.stripe_id = customer.id
                user.profile.save()
                user.profile.activate_premium() # TODO: Remove, because webhooks are slow

                success_updating = True

    else:
        zebra_form = StripePlusPaymentForm(email=user.email, plan=plan)
    
    if success_updating:
        return render_to_response('reader/paypal_return.xhtml', 
                                  {}, context_instance=RequestContext(request))
    
    new_user_queue_count = RNewUserQueue.user_count()
    new_user_queue_position = RNewUserQueue.user_position(request.user.pk)
    new_user_queue_behind = 0
    if new_user_queue_position >= 0:
        new_user_queue_behind = new_user_queue_count - new_user_queue_position 
        new_user_queue_position -= 1
    
    logging.user(request, "~BM~FBLoading Stripe form")

    return render_to_response('profile/stripe_form.xhtml',
        {
          'zebra_form': zebra_form,
          'publishable': settings.STRIPE_PUBLISHABLE,
          'success_updating': success_updating,
          'new_user_queue_count': new_user_queue_count - 1,
          'new_user_queue_position': new_user_queue_position,
          'new_user_queue_behind': new_user_queue_behind,
          'error': error,
        },
        context_instance=RequestContext(request)
    )
開發者ID:Daniel-Hug,項目名稱:NewsBlur,代碼行數:59,代碼來源:views.py

示例2: stripe_form

def stripe_form(request):
    user = request.user
    success_updating = False
    stripe.api_key = settings.STRIPE_SECRET
    plan = int(request.GET.get("plan", 2))
    plan = PLANS[plan - 1][0]

    if request.method == "POST":
        zebra_form = StripePlusPaymentForm(request.POST, email=user.email)
        if zebra_form.is_valid():
            user.email = zebra_form.cleaned_data["email"]
            user.save()

            customer = stripe.Customer.create(
                **{
                    "card": zebra_form.cleaned_data["stripe_token"],
                    "plan": zebra_form.cleaned_data["plan"],
                    "email": user.email,
                    "description": user.username,
                }
            )

            user.profile.strip_4_digits = zebra_form.cleaned_data["last_4_digits"]
            user.profile.stripe_id = customer.id
            user.profile.save()
            user.profile.activate_premium()  # TODO: Remove, because webhooks are slow

            success_updating = True

    else:
        zebra_form = StripePlusPaymentForm(email=user.email, plan=plan)

    if success_updating:
        return render_to_response("reader/paypal_return.xhtml", {}, context_instance=RequestContext(request))

    new_user_queue_count = RNewUserQueue.user_count()
    new_user_queue_position = RNewUserQueue.user_position(request.user.pk)
    new_user_queue_behind = 0
    if new_user_queue_position >= 0:
        new_user_queue_behind = new_user_queue_count - new_user_queue_position
        new_user_queue_position -= 1

    logging.user(request, "~BM~FBLoading Stripe form")

    return render_to_response(
        "profile/stripe_form.xhtml",
        {
            "zebra_form": zebra_form,
            "publishable": settings.STRIPE_PUBLISHABLE,
            "success_updating": success_updating,
            "new_user_queue_count": new_user_queue_count - 1,
            "new_user_queue_position": new_user_queue_position,
            "new_user_queue_behind": new_user_queue_behind,
        },
        context_instance=RequestContext(request),
    )
開發者ID:bayunox,項目名稱:NewsBlur,代碼行數:56,代碼來源:views.py

示例3: save

    def save(self, profile_callback=None):
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']

        email = self.cleaned_data.get('email', None)
        if email:
            email_exists = User.objects.filter(email__iexact=email).count()
            if email_exists:
                raise forms.ValidationError(_(u'Someone is already using that email address.'))

        exists = User.objects.filter(username__iexact=username).count()
        if exists:
            user_auth = authenticate(username=username, password=password)
            if not user_auth:
                raise forms.ValidationError(_(u'Someone is already using that username.'))
            else:
                return user_auth
        
        if not password:
            password = username
            
        new_user = User(username=username)
        new_user.set_password(password)
        new_user.is_active = False
        new_user.email = email
        new_user.save()
        new_user = authenticate(username=username,
                                password=password)
        
        MActivity.new_signup(user_id=new_user.pk)
        
        RNewUserQueue.add_user(new_user.pk)
        
        if new_user.email:
            EmailNewUser.delay(user_id=new_user.pk)
        
        if getattr(settings, 'AUTO_PREMIUM_NEW_USERS', False):
            new_user.profile.activate_premium()
        elif getattr(settings, 'AUTO_ENABLE_NEW_USERS', False):
            new_user.profile.activate_free()
        
        return new_user
開發者ID:1059232202,項目名稱:NewsBlur,代碼行數:42,代碼來源:forms.py

示例4: save

    def save(self, profile_callback=None):
        username = self.cleaned_data["username"]
        password = self.cleaned_data["password"]

        email = self.cleaned_data.get("email", None)
        if email:
            email_exists = User.objects.filter(email__iexact=email).count()
            if email_exists:
                raise forms.ValidationError(_(u"此郵件地址已經被使用。"))

        exists = User.objects.filter(username__iexact=username).count()
        if exists:
            user_auth = authenticate(username=username, password=password)
            if not user_auth:
                raise forms.ValidationError(_(u"此用戶名已經被使用。"))
            else:
                return user_auth

        if not password:
            password = username

        new_user = User(username=username)
        new_user.set_password(password)
        new_user.is_active = False
        new_user.email = email
        new_user.save()
        new_user = authenticate(username=username, password=password)

        MActivity.new_signup(user_id=new_user.pk)

        RNewUserQueue.add_user(new_user.pk)

        if new_user.email:
            EmailNewUser.delay(user_id=new_user.pk)

        if getattr(settings, "AUTO_PREMIUM_NEW_USERS", False):
            new_user.profile.activate_premium()
        elif getattr(settings, "AUTO_ENABLE_NEW_USERS", False):
            new_user.profile.activate_free()

        return new_user
開發者ID:bruceyou,項目名稱:NewsBlur,代碼行數:41,代碼來源:forms.py

示例5: calculate_metrics

    def calculate_metrics(self):
        import datetime
        from django.contrib.auth.models import User
        from apps.profile.models import Profile, RNewUserQueue

        last_month = datetime.datetime.utcnow() - datetime.timedelta(days=30)
        last_day = datetime.datetime.utcnow() - datetime.timedelta(minutes=60*24)

        return {
            'all': User.objects.count(),
            'monthly': Profile.objects.filter(last_seen_on__gte=last_month).count(),
            'daily': Profile.objects.filter(last_seen_on__gte=last_day).count(),
            'premium': Profile.objects.filter(is_premium=True).count(),
            'queued': RNewUserQueue.user_count(),
        }
開發者ID:1761461582,項目名稱:NewsBlur,代碼行數:15,代碼來源:newsblur_users.py

示例6: stripe_form

def stripe_form(request):
    user = request.user
    success_updating = False
    stripe.api_key = settings.STRIPE_SECRET
    plan = int(request.GET.get("plan", 2))
    plan = PLANS[plan - 1][0]
    error = None

    if request.method == "POST":
        zebra_form = StripePlusPaymentForm(request.POST, email=user.email)
        if zebra_form.is_valid():
            user.email = zebra_form.cleaned_data["email"]
            user.save()

            current_premium = (
                user.profile.is_premium
                and user.profile.premium_expire
                and user.profile.premium_expire > datetime.datetime.now()
            )
            # Are they changing their existing card?
            if user.profile.stripe_id and current_premium:
                customer = stripe.Customer.retrieve(user.profile.stripe_id)
                try:
                    card = customer.cards.create(card=zebra_form.cleaned_data["stripe_token"])
                except stripe.CardError:
                    error = "This card was declined."
                else:
                    customer.default_card = card.id
                    customer.save()
                    success_updating = True
            else:
                try:
                    customer = stripe.Customer.create(
                        **{
                            "card": zebra_form.cleaned_data["stripe_token"],
                            "plan": zebra_form.cleaned_data["plan"],
                            "email": user.email,
                            "description": user.username,
                        }
                    )
                except stripe.CardError:
                    error = "This card was declined."
                else:
                    user.profile.strip_4_digits = zebra_form.cleaned_data["last_4_digits"]
                    user.profile.stripe_id = customer.id
                    user.profile.save()
                    user.profile.activate_premium()  # TODO: Remove, because webhooks are slow
                    success_updating = True

    else:
        zebra_form = StripePlusPaymentForm(email=user.email, plan=plan)

    if success_updating:
        return render_to_response("reader/paypal_return.xhtml", {}, context_instance=RequestContext(request))

    new_user_queue_count = RNewUserQueue.user_count()
    new_user_queue_position = RNewUserQueue.user_position(request.user.pk)
    new_user_queue_behind = 0
    if new_user_queue_position >= 0:
        new_user_queue_behind = new_user_queue_count - new_user_queue_position
        new_user_queue_position -= 1

    logging.user(request, "~BM~FBLoading Stripe form")

    return render_to_response(
        "profile/stripe_form.xhtml",
        {
            "zebra_form": zebra_form,
            "publishable": settings.STRIPE_PUBLISHABLE,
            "success_updating": success_updating,
            "new_user_queue_count": new_user_queue_count - 1,
            "new_user_queue_position": new_user_queue_position,
            "new_user_queue_behind": new_user_queue_behind,
            "error": error,
        },
        context_instance=RequestContext(request),
    )
開發者ID:jmorahan,項目名稱:NewsBlur,代碼行數:77,代碼來源:views.py

示例7: run

 def run(self):
     RNewUserQueue.activate_next()
開發者ID:MilenkoM,項目名稱:NewsBlur,代碼行數:2,代碼來源:tasks.py

示例8: stripe_form

def stripe_form(request):
    user = request.user
    success_updating = False
    stripe.api_key = settings.STRIPE_SECRET
    plan = int(request.GET.get('plan', 2))
    plan = PLANS[plan-1][0]
    renew = is_true(request.GET.get('renew', False))
    error = None
    
    if request.method == 'POST':
        zebra_form = StripePlusPaymentForm(request.POST, email=user.email)
        if zebra_form.is_valid():
            user.email = zebra_form.cleaned_data['email']
            user.save()
            
            grace_period = datetime.datetime.now() - datetime.timedelta(days=30)
            current_premium = (user.profile.is_premium and 
                               user.profile.premium_expire and
                               user.profile.premium_expire > grace_period)
            # Are they changing their existing card?
            if user.profile.stripe_id and current_premium:
                customer = stripe.Customer.retrieve(user.profile.stripe_id)
                try:
                    card = customer.cards.create(card=zebra_form.cleaned_data['stripe_token'])
                except stripe.CardError:
                    error = "This card was declined."
                else:
                    customer.default_card = card.id
                    customer.save()
                    success_updating = True
            else:
                try:
                    customer = stripe.Customer.create(**{
                        'card': zebra_form.cleaned_data['stripe_token'],
                        'plan': zebra_form.cleaned_data['plan'],
                        'email': user.email,
                        'description': user.username,
                    })
                except stripe.CardError:
                    error = "This card was declined."
                else:
                    user.profile.strip_4_digits = zebra_form.cleaned_data['last_4_digits']
                    user.profile.stripe_id = customer.id
                    user.profile.save()
                    user.profile.activate_premium() # TODO: Remove, because webhooks are slow
                    success_updating = True

    else:
        zebra_form = StripePlusPaymentForm(email=user.email, plan=plan)
    
    if success_updating:
        return render_to_response('reader/paypal_return.xhtml', 
                                  {}, context_instance=RequestContext(request))
    
    new_user_queue_count = RNewUserQueue.user_count()
    new_user_queue_position = RNewUserQueue.user_position(request.user.pk)
    new_user_queue_behind = 0
    if new_user_queue_position >= 0:
        new_user_queue_behind = new_user_queue_count - new_user_queue_position 
        new_user_queue_position -= 1
    
    immediate_charge = True
    if user.profile.premium_expire and user.profile.premium_expire > datetime.datetime.now():
        immediate_charge = False
    
    logging.user(request, "~BM~FBLoading Stripe form")

    return render_to_response('profile/stripe_form.xhtml',
        {
          'zebra_form': zebra_form,
          'publishable': settings.STRIPE_PUBLISHABLE,
          'success_updating': success_updating,
          'new_user_queue_count': new_user_queue_count - 1,
          'new_user_queue_position': new_user_queue_position,
          'new_user_queue_behind': new_user_queue_behind,
          'renew': renew,
          'immediate_charge': immediate_charge,
          'error': error,
        },
        context_instance=RequestContext(request)
    )
開發者ID:MilenkoM,項目名稱:NewsBlur,代碼行數:81,代碼來源:views.py


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