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


Python Subscription.save方法代码示例

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


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

示例1: add_invited

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
def add_invited(user):
    print "ADD INVITED SUBSCRIPTIONS"
    ## Add to subscription list

    # get newsletter
    try:
        newsl = Newsletter.objects.get(slug='emif-catalogue-newsletter')

        # create subscription
        user_sub = Subscription(user=user,  newsletter=newsl)

        user_sub.subscribe()

        user_sub.save()

    except Newsletter.DoesNotExist:
        print "Problem registering new user to emif default newsletter"

    # add invited dbs if any
    sps = InvitePending.objects.filter(email=user.email)

    for sp in sps:

        fingerprint = sp.fingerprint

        fingerprint.save()

        fingerprint.shared.add(user)

        sp.delete()

        # must reindex, because databases lists come from solr, to update user_t
        fingerprint.indexFingerprint()
开发者ID:bastiao,项目名称:catalogue,代码行数:35,代码来源:models.py

示例2: test_unsubscribe_request_activate

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_unsubscribe_request_activate(self):
        """ Update a request. """

        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail)
        subscription.save()

        activate_url = subscription.unsubscribe_activate_url()

        response = self.client.get(activate_url)
        self.assertInContext(response, 'form', UpdateForm)
        self.assertContains(response, subscription.activation_code)

        testname2 = 'Test Name2'
        response = self.client.post(activate_url, {
            'name_field': testname2,
            'user_activation_code': subscription.activation_code
        })

        # Assure we are redirected to "unsubscribe activated" page.
        self.assertRedirects(response, self.unsubscribe_activated_url)

        subscription = self.get_only_subscription(
            email_field__exact=self.testemail
        )

        self.assertTrue(subscription.unsubscribed)
        self.assertEqual(subscription.name, testname2)
        self.assertEqual(subscription.email, self.testemail)

        dt = (timezone.now() - subscription.unsubscribe_date).seconds
        self.assertLessThan(dt, 2)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:35,代码来源:test_web.py

示例3: subscribe_request

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
def subscribe_request(request):
    """ Adds a new subscription to mailchimp list. """
    if request.POST:
        mail_chimp = mailchimp.Mailchimp(
            settings.SECRETS['mailchimp_api_key']
        )
        form = NewsletterForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            subscription = Subscription(email=email)
            subscription.save()
            try:
                mail_chimp.lists.subscribe(
                    settings.SECRETS['mailchimp_list_id'],
                    {'email': email},
                    double_optin=False,
                    send_welcome=True
                )
            except mailchimp.ListAlreadySubscribedError:
                return {
                    'success': False, 'error': 'Email is already subscribed'
                }
            return {'success': True}
        else:
            return {
                'success': False,
                'error': form.errors.get('email')
            }
    return {'success': False, 'error': 'Request not valid'}
开发者ID:kushiahu,项目名称:djangomx,代码行数:31,代码来源:views.py

示例4: test_subscribe_request_activate_form_loophole

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_subscribe_request_activate_form_loophole(self):
        """
        Prevent updating to unconfirmed email address. (#108)
        """

        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail)
        subscription.save()

        activate_url = subscription.subscribe_activate_url()

        response = self.client.get(activate_url)
        self.assertInContext(response, 'form', UpdateForm)
        self.assertContains(response, subscription.activation_code)

        testname2 = 'Test Name2'
        testemail2 = '[email protected]'
        response = self.client.post(activate_url, {
            'name_field': testname2,
            'email_field': testemail2,
            'user_activation_code': subscription.activation_code
        })

        # Assure we are redirected to "update activated" page.
        self.assertRedirects(response, self.subscribe_activated_url)

        subscription = Subscription.objects.get(pk=subscription.pk)

        self.assertTrue(subscription)
        self.assertTrue(subscription.subscribed)
        self.assertEqual(subscription.email, self.testemail)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:34,代码来源:test_web.py

示例5: importUsers

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
def importUsers():

    try:
        newsl = Newsletter.objects.get(slug='emif-catalogue-newsletter')


        users = User.objects.all()

        for user in users:
            try:
                subscription = Subscription.objects.get(user=user,  newsletter=newsl)

            except Subscription.DoesNotExist:
                # create subscription if doesnt exist yet
                user_sub = Subscription(user=user,  newsletter=newsl)

                user_sub.subscribe()

                user_sub.save()

                print "-- Created subscription for emif newsletter to user "+str(user.username)

                pass

    except Newsletter.DoesNotExist:
        print "Problem finding default newsletter for emif"
开发者ID:bioinformatics-ua,项目名称:montra,代码行数:28,代码来源:addNewsletterExistingUsers.py

示例6: test_unsubscribe_request_post_error

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_unsubscribe_request_post_error(self):
        """
        Test whether a failing unsubscribe request email generated an error in
        the context.

        We do this by overriding the default mail backend to a settings which
        we know pretty sure is bound to fail.
        """
        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail,
                                    subscribed=True)
        subscription.save()

        with override_settings(
            EMAIL_BACKEND='tests.utils.FailingEmailBackend'
        ):
            with patch_logger('newsletter.views', 'error') as messages:
                response = self.client.post(
                    self.unsubscribe_url, {'email_field': self.testemail}
                )
            self.assertEqual(len(messages), 1)
            self.assertIn("Connection refused", messages[0])

        self.assertTrue(response.context['error'])
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:27,代码来源:test_web.py

示例7: import_auth_users

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def import_auth_users(self, *args, **options):
        auth_list, created = List.objects.get_or_create(name="8pm_leak")
        file = open("newsletter/management/commands/runners.txt", "r")

        EMAIL_REGEX = re.compile(r"[^@][email protected][^@]+\.[^@]+")

        runners = []
        for email in file:
            if not EMAIL_REGEX.match(email):
                print "Error matching regex"
            else:
                runners.append(email.replace(',','').rstrip())

        users = []
        for u in User.objects.all():
            users.append(u.email)

        diff = [x for x in runners if x not in users]

        for u in diff:
            try:
                s = Subscription.objects.get(email_field=u)
                print "skipping, user alread loaded from auth: ",s
            except Subscription.DoesNotExist:
                print "adding new user from list intersection: ",u
                subscriber = Subscription(email_field=u,list=auth_list,subscribed=True)
                subscriber.save()

        print "Runners.txt len: ", len(runners)
        print "Current DB users len: ",len(users)
        print "Diff len: ",len(diff)
开发者ID:zdanozdan,项目名称:django-newsletter,代码行数:33,代码来源:8pm.py

示例8: test_unsubscribe_view

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_unsubscribe_view(self):
        """ Test the unsubscription form. """
        subscription = Subscription(user=self.user, newsletter=self.n)
        subscription.subscribed = True
        subscription.unsubscribed = False
        subscription.save()

        self.assertLessThan(
            subscription.subscribe_date, timezone.now() + timedelta(seconds=1)
        )

        response = self.client.get(self.unsubscribe_url)

        self.assertContains(response, self.n.title, status_code=200)

        self.assertEqual(response.context['newsletter'], self.n)
        self.assertEqual(response.context['user'], self.user)

        self.assertContains(
            response, 'action="%s"' % self.unsubscribe_confirm_url)
        self.assertContains(response, 'id="id_submit"')

        subscription = self.get_user_subscription()
        self.assertTrue(subscription.subscribed)
        self.assertFalse(subscription.unsubscribed)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:27,代码来源:test_web.py

示例9: test_unsubscribe_request_post_no_email

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_unsubscribe_request_post_no_email(self):
        """
        Post the unsubscribe request form
        with confirmation email switched off in settings.
        """

        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail,
                                    subscribed=True)
        subscription.save()

        response = self.client.post(
            self.unsubscribe_url, {'email_field': self.testemail}
        )

        # Assure we are redirected to "unsubscribe activated" page.
        self.assertRedirects(response, self.unsubscribe_activated_url)

        changed_subscription = self.get_only_subscription(
            email_field__exact=self.testemail
        )

        # email confirmation is switched off,
        # so after unsubscribe request user should be unsubscribed
        self.assertFalse(changed_subscription.subscribed)
        self.assertTrue(changed_subscription.unsubscribed)

        """ Check the subscription email. """
        # no email should be send
        self.assertEqual(len(mail.outbox), 0)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:33,代码来源:test_web.py

示例10: test_update_request_activate

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_update_request_activate(self):
        """ Update a request. """

        subscription = Subscription(newsletter=self.n,
                                    name='Test Name',
                                    email='[email protected]')
        subscription.save()

        activate_url = subscription.update_activate_url()

        response = self.client.get(activate_url)
        self.assertInContext(response, 'form', UpdateForm)
        self.assertContains(response, subscription.activation_code)

        testname2 = 'Test Name2'
        testemail2 = '[email protected]'
        response = self.client.post(activate_url, {
            'name_field': testname2,
            'email_field': testemail2,
            'user_activation_code': subscription.activation_code
        })

        # Assure we are redirected to "update activated" page.
        self.assertRedirects(response, self.update_activated_url)

        subscription = self.get_only_subscription(
            email_field__exact=testemail2
        )

        self.assertTrue(subscription)
        self.assertTrue(subscription.subscribed)
        self.assertEqual(subscription.name, testname2)
        self.assertEqual(subscription.email, testemail2)
开发者ID:sha-red,项目名称:django-newsletter,代码行数:35,代码来源:test_web.py

示例11: import_auth_users

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
 def import_auth_users(self, *args, **options):
     auth_list, created = List.objects.get_or_create(name="django_auth")
     users = User.objects.all()
     for u in users:
         try:
             s = Subscription.objects.get(user=u,list=auth_list)
             print "skipping, user alread loaded from auth: ",s
         except Subscription.DoesNotExist:
             print "adding new user from auth: ",u
             subscriber = Subscription(user=u,list=auth_list,subscribed=True)
             subscriber.save()
开发者ID:zdanozdan,项目名称:django-newsletter,代码行数:13,代码来源:import_users.py

示例12: subscribe

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
def subscribe(request):
  if request.method == 'POST':
    from django.forms.fields import email_re
    if email_re.match(request.POST['email']):
      sub = Subscription(email=request.POST['email'])
      sub.save()
      create_message(request, "Dodano do newslettera")
      return conditional_redirect(request, '/')
    else:
      create_message(request, "Błędny adres e-mail")
      return conditional_redirect(request, '/')
  else:
      return conditional_redirect(request, '/')
开发者ID:LittleForker,项目名称:django-minishop,代码行数:15,代码来源:views.py

示例13: test_twosubmissions_unsubscried

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_twosubmissions_unsubscried(self):
        """ Test submission with two subscribers, one unactivated. """

        s2 = Subscription(
            name='Test Name 2', email='[email protected]',
            newsletter=self.n, subscribed=False
        )
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s])
开发者ID:AdTech1001,项目名称:django-newsletter,代码行数:15,代码来源:test_mailing.py

示例14: test_twosubmissions

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
    def test_twosubmissions(self):
        """ Test submission with two activated subscribers. """

        s2 = Subscription(
            name='Test Name 2', email='[email protected]',
            newsletter=self.n, subscribed=True
        )
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertTrue(self.s in list(subscriptions))
        self.assertTrue(s2 in list(subscriptions))
开发者ID:AdTech1001,项目名称:django-newsletter,代码行数:16,代码来源:test_mailing.py

示例15: subscribe

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import save [as 别名]
def subscribe(request):
    if 'subscription' in request.POST:
        subscription = Subscription(email = request.POST['subscription'])
        subscriptions = Subscription.objects.filter(email = request.POST['subscription'])

        try:
            subscription.full_clean()
            subscription.save()
            return HttpResponse('Uspješno ste se pretplatili!')
        except ValidationError, e:
            if (subscriptions.count() != 0):
              return HttpResponse('E-mail adresa je vec pretplacena!')
            else:
              return HttpResponse('Došlo je do pogreške!')
开发者ID:retro,项目名称:kset-org,代码行数:16,代码来源:views.py


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