How to use the createsend.BadRequest function in createsend

To help you get started, we’ve selected a few createsend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philippbosch / django-campaignmonitor / campaignmonitor / views.py View on Github external
def create_draft(request, id):
    campaign = get_object_or_404(Campaign, id=id)
    
    preview_recipients = []
    if request.user.email:
        preview_recipients.append(request.user.email)
    
    try:
        campaign.create_draft(preview_recipients=preview_recipients)
        messages.success(request, _("The draft for campaign '%(name)s' was created successfully.") % {'name': campaign.name})
        if request.user.email:
            messages.info(request, _("A preview has been sent to %(email)s.") % {'email': request.user.email})
    except BadRequest, e:
        messages.error(request, _("An error occurred: %(code)s %(message)s") % {'code': e.data.Code, 'message': e.data.Message})
    
    return HttpResponseRedirect(reverse('admin:campaignmonitor_campaign_changelist'))
github philippbosch / django-campaignmonitor / campaignmonitor / models / campaigns.py View on Github external
subject=self.subject,
            name=self.name,
            from_name=self.from_name,
            from_email=self.from_email,
            reply_to=self.from_email, # TODO
            html_url=self.html_url,
            text_url=self.text_url,
            list_ids=self.list_ids,
            segment_ids=self.segment_ids,
        )
        try:
            campaign_id = campaign.create(**attrs)
            self.cm_id = campaign_id
            self.status = self.STATUS_DRAFT
            self.save()
        except BadRequest, e:
            raise
        if len(preview_recipients):
            campaign = CSCampaign(campaign_id)
            campaign.send_preview(preview_recipients)