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


Python settings.MAILCHIMP_API_KEY屬性代碼示例

本文整理匯總了Python中django.conf.settings.MAILCHIMP_API_KEY屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.MAILCHIMP_API_KEY屬性的具體用法?Python settings.MAILCHIMP_API_KEY怎麽用?Python settings.MAILCHIMP_API_KEY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


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

示例1: consume

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def consume(self, data: Dict[str, Any]) -> None:
        # TODO: This is the only implementation with Dict cf Mapping; should we simplify?
        user_profile = get_user_profile_by_id(data['user_id'])
        logging.info(
            "Processing signup for user %s in realm %s",
            user_profile.id, user_profile.realm.string_id,
        )
        if settings.MAILCHIMP_API_KEY and settings.PRODUCTION:
            endpoint = "https://{}.api.mailchimp.com/3.0/lists/{}/members".format(
                settings.MAILCHIMP_API_KEY.split('-')[1], settings.ZULIP_FRIENDS_LIST_ID,
            )
            params = dict(data)
            del params['user_id']
            params['list_id'] = settings.ZULIP_FRIENDS_LIST_ID
            params['status'] = 'subscribed'
            r = requests.post(endpoint, auth=('apikey', settings.MAILCHIMP_API_KEY), json=params, timeout=10)
            if r.status_code == 400 and ujson.loads(r.text)['title'] == 'Member Exists':
                logging.warning("Attempted to sign up already existing email to list: %s",
                                data['email_address'])
            elif r.status_code == 400:
                retry_event(self.queue_name, data, lambda e: r.raise_for_status())
            else:
                r.raise_for_status() 
開發者ID:zulip,項目名稱:zulip,代碼行數:25,代碼來源:queue_processors.py

示例2: handle

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def handle(self, *args: Any, **options: Optional[str]) -> None:
        api_key = options['api_key']
        if api_key is None:
            try:
                if settings.MAILCHIMP_API_KEY is None:
                    raise CommandError('MAILCHIMP_API_KEY is None. Check your server settings file.')
                api_key = settings.MAILCHIMP_API_KEY
            except AttributeError:
                raise CommandError('Please supply a MailChimp API key to --api-key, or add a '
                                   'MAILCHIMP_API_KEY to your server settings file.')

        if options['list_id'] is None:
            try:
                if settings.ZULIP_FRIENDS_LIST_ID is None:
                    raise CommandError('ZULIP_FRIENDS_LIST_ID is None. Check your server settings file.')
                options['list_id'] = settings.ZULIP_FRIENDS_LIST_ID
            except AttributeError:
                raise CommandError('Please supply a MailChimp List ID to --list-id, or add a '
                                   'ZULIP_FRIENDS_LIST_ID to your server settings file.')

        endpoint = "https://{}.api.mailchimp.com/3.0/lists/{}/members".format(
            api_key.split('-')[1], options['list_id'],
        )

        for user in UserProfile.objects.filter(is_bot=False, is_active=True) \
                                       .values('email', 'full_name', 'realm_id'):
            data = {
                'email_address': user['email'],
                'list_id': options['list_id'],
                'status': 'subscribed',
                'merge_fields': {
                    'NAME': user['full_name'],
                    'REALM_ID': user['realm_id'],
                    'OPTIN_TIME': options['optin_time'],
                },
            }
            r = requests.post(endpoint, auth=('apikey', api_key), json=data, timeout=10)
            if r.status_code == 400 and ujson.loads(r.text)['title'] == 'Member Exists':
                print("{} is already a part of the list.".format(data['email_address']))
            elif r.status_code >= 400:
                print(r.text) 
開發者ID:zulip,項目名稱:zulip,代碼行數:43,代碼來源:add_users_to_mailing_list.py

示例3: get_mailchimp_api

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def get_mailchimp_api():
    if hasattr(settings, 'MAILCHIMP_API_KEY'):
        key = settings.MAILCHIMP_API_KEY
    else:
        key = '00000000000000000000000000000000-us1'
    return mailchimp.Mailchimp(key) 
開發者ID:electionscience,項目名稱:approval_frame,代碼行數:8,代碼來源:mailchimp_api.py

示例4: form_valid

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def form_valid(self, form):
        mailchimp_enabled = settings.MAILCHIMP_API_KEY and settings.MAILCHIMP_LIST_ID

        dummy_key = 'a' * 32

        client = MailChimp(mc_api=settings.MAILCHIMP_API_KEY or dummy_key, timeout=5.0, enabled=mailchimp_enabled)

        data = form.cleaned_data.copy()
        email = data.pop('email')
        data = {
            k.upper(): v
            for k, v in data.items()
        }
        try:
            client.lists.members.create(settings.MAILCHIMP_LIST_ID, {
                'email_address': email,
                'status': 'pending',
                'merge_fields': data,
            })
        except Exception as e:
            self.warning(e)
        else:
            if mailchimp_enabled:
                self.success()
            else:
                self.warning(Exception(
                    'Incorrect Mailchimp configuration: API_KEY: {}, LIST_ID: {}'.format(
                        str(settings.MAILCHIMP_API_KEY),
                        str(settings.MAILCHIMP_LIST_ID),
                    )
                ))

        return super().form_valid(form) 
開發者ID:OpenTechFund,項目名稱:hypha,代碼行數:35,代碼來源:views.py

示例5: global_vars

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def global_vars(request):
    return {
        'APPLY_SITE': ApplyHomePage.objects.first().get_site(),
        'PUBLIC_SITE': HomePage.objects.first().get_site(),
        'newsletter_form': NewsletterForm(),
        'newsletter_enabled': settings.MAILCHIMP_API_KEY and settings.MAILCHIMP_LIST_ID,
        'ORG_LONG_NAME': settings.ORG_LONG_NAME,
        'ORG_SHORT_NAME': settings.ORG_SHORT_NAME,
        'ORG_EMAIL': settings.ORG_EMAIL,
    } 
開發者ID:OpenTechFund,項目名稱:hypha,代碼行數:12,代碼來源:context_processors.py

示例6: _get_base_url

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def _get_base_url(self):
        dc = settings.MAILCHIMP_API_KEY.split('-')[-1]

        return f'https://{dc}.api.mailchimp.com/3.0/' 
開發者ID:f213,項目名稱:education-backend,代碼行數:6,代碼來源:mailchimp.py

示例7: _post

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def _post(self, url: str, payload: dict):
        response = requests.post(
            url=self.format_url(url),
            auth=HTTPBasicAuth('user', settings.MAILCHIMP_API_KEY),
            json=payload,
        )
        if response.status_code != 200:
            raise AppMailchimpWrongResponseException(f'Wrong response from mailchimp: {response.status_code}. Response = {response.json()}')

        return response 
開發者ID:f213,項目名稱:education-backend,代碼行數:12,代碼來源:mailchimp.py

示例8: member_pre_save_cb

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MAILCHIMP_API_KEY [as 別名]
def member_pre_save_cb(sender, instance, raw, **kwargs):
    """
    Subscribe or unsubscribe a user from Mailchimp.
    """
    if raw or settings.TESTING:
        return

    try:
        member = sender.objects.get(pk=instance.pk)
    except sender.DoesNotExist:
        pass
    else:
        if member.newsletter == instance.newsletter:
            return

    if not settings.MAILCHIMP_API_KEY:
        logger.warn(
            "User changed email preference but no Mailchimp API key "
            "has been specified, set MAILCHIMP_API_KEY."
        )

        return

    mc = mailchimp.Mailchimp(settings.MAILCHIMP_API_KEY)

    try:
        address = instance.primary_email.email
    except AttributeError:
        # We're not sure why the callback is firing an extra time, before
        # SignupView.create_account runs (when email not yet saved).
        return

    if instance.newsletter:
        try:
            mc.lists.subscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                double_optin=False,
                update_existing=True,
            )
        except mailchimp.ListAlreadySubscribedError:
            logger.info('"%s" was already subscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e)
    else:
        try:
            mc.lists.unsubscribe(
                settings.MAILCHIMP_NEWSLETTER_LIST,
                {"email": address},
                send_goodbye=False,
                send_notify=False,
            )
        except (mailchimp.ListNotSubscribedError, mailchimp.EmailNotExistsError):
            logger.info('"%s" was already unsubscribed', address)
        except (mailchimp.Error, ValueError) as e:
            logger.error("A Mailchimp error occurred: %s, %s", e.__class__, e) 
開發者ID:OpenHumans,項目名稱:open-humans,代碼行數:58,代碼來源:signals.py


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