Пример #1
0
def campaign_generate(request,
                      form_class=CampaignForm,
                      template_name='campaign_monitor/campaigns/add.html'):
    if not has_perm(request.user, 'campaign_monitor.add_campaign'):
        raise Http403

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            template = form.cleaned_data['template']

            #set up urls
            site_url = get_setting('site', 'global', 'siteurl')
            html_url = unicode("%s%s" % (site_url, template.get_html_url()))
            html_url += "?jump_links=%s" % form.cleaned_data.get('jump_links')
            try:
                from tendenci.addons.events.models import Event, Type
                html_url += "&events=%s" % form.cleaned_data.get('events')
                html_url += "&events_type=%s" % form.cleaned_data.get(
                    'events_type')
                html_url += "&event_start_dt=%s" % form.cleaned_data.get(
                    'event_start_dt', '')
                html_url += "&event_end_dt=%s" % form.cleaned_data.get(
                    'event_end_dt', '')
            except ImportError:
                pass
            html_url += "&articles=%s" % form.cleaned_data.get('articles')
            html_url += "&articles_days=%s" % form.cleaned_data.get(
                'articles_days')
            html_url += "&news=%s" % form.cleaned_data.get('news')
            html_url += "&news_days=%s" % form.cleaned_data.get('news_days')
            html_url += "&jobs=%s" % form.cleaned_data.get('jobs')
            html_url += "&jobs_days=%s" % form.cleaned_data.get('jobs_days')
            html_url += "&pages=%s" % form.cleaned_data.get('pages')
            html_url += "&pages_days=%s" % form.cleaned_data.get('pages_days')

            if template.zip_file:
                if hasattr(settings,
                           'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                    zip_url = unicode(template.get_zip_url())
                else:
                    zip_url = unicode("%s%s" %
                                      (site_url, template.get_zip_url()))
            else:
                zip_url = unicode()

            #sync with campaign monitor
            try:
                t = CST(auth=auth, template_id=template.template_id)
                t.update(unicode(template.name), html_url, zip_url)
            except BadRequest, e:
                messages.add_message(
                    request, messages.ERROR,
                    'Bad Request %s: %s' % (e.data.Code, e.data.Message))
                return redirect('campaign_monitor.campaign_generate')
            except Exception, e:
                messages.add_message(request, messages.ERROR, 'Error: %s' % e)
                return redirect('campaign_monitor.campaign_generate')
            return redirect("%s/campaign/create/new" %
                            settings.CAMPAIGNMONITOR_URL)
Пример #2
0
def sync_templates(request=None):
    """
    Pushes most recent template updates
    up to Campaign Monitor
    """
    templates = []
    if hasattr(cl, 'templates'):
        templates = cl.templates()

    for t in templates:

        try:
            template = Template.objects.get(template_id=t.TemplateID)
        except Template.DoesNotExist:
            template = Template(template_id=t.TemplateID)
            template.name = t.Name
            template.cm_preview_url = t.PreviewURL
            template.cm_screenshot_url = t.ScreenshotURL
        except Exception as e:
            print 'sync template exception', e

        #set up urls
        site_url = get_setting('site', 'global', 'siteurl')
        html_url = unicode("%s%s" % (site_url, template.get_html_url()))
        html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
        html_url += "&events=1"
        html_url += "&events_type="
        html_url += "&event_start_dt=%s" % datetime.date.today()
        end_dt = datetime.date.today() + timedelta(days=90)
        html_url += "&event_end_dt=%s" % end_dt

        if template.zip_file:
            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                zip_url = unicode(template.get_zip_url())
            else:
                zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
        else:
            zip_url = unicode()

        #sync with campaign monitor
        try:
            cst = CST(auth, template_id=template.template_id)
            cst.update(unicode(template.name), html_url, zip_url)
            success = True
        except BadRequest, e:
            success = False
            if request:
                messages.add_message(
                    request, messages.ERROR,
                    'Bad Request %s: %s' % (e.data.Code, e.data.Message))
            else:
                print e.data.Code, e.data.Message
                return
        except Exception, e:
            success = False
            if request:
                messages.add_message(request, messages.ERROR, 'Error: %s' % e)
            else:
                print e.data.Code, e.data.Message
                return
Пример #3
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, 'campaign_monitor.change_template',
                    template):
        raise Http403

    #set up urls
    site_url = get_setting('site', 'global', 'siteurl')
    html_url = str("%s%s" % (site_url, template.get_html_url()))
    if template.zip_file:
        zip_url = str("%s%s" % (site_url, template.get_zip_url()))
    else:
        zip_url = ""

    #sync with campaign monitor
    try:
        t = CST(template_id=template.template_id)
        t.update(str(template.name), html_url, zip_url)
    except BadRequest, e:
        messages.add_message(
            request, messages.ERROR,
            'Bad Request %s: %s' % (e.data.Code, e.data.Message))
        return redirect(template)
Пример #4
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, 'campaign_monitor.change_template',
                    template):
        raise Http403

    #set up urls
    site_url = get_setting('site', 'global', 'siteurl')

    if template.zip_file:
        if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
            zip_url = template.get_zip_url()
            html_url = template.html_file.url
        else:
            zip_url = "%s%s" % (site_url, template.get_zip_url())
            html_url = str("%s%s" % (site_url, template.get_html_url()))
    else:
        zip_url = ""

    #sync with campaign monitor
    try:
        t = CST(template_id=template.template_id)
        t.update(str(template.name), html_url, zip_url)
    except BadRequest, e:
        messages.add_message(
            request, messages.ERROR,
            'Bad Request %s: %s' % (e.data.Code, e.data.Message))
        return redirect(template)
Пример #5
0
def sync_templates(request=None):
    """
    Pushes most recent template updates
    up to Campaign Monitor
    """
    templates = []
    if hasattr(cl,'templates'):
        templates = cl.templates()

    for t in templates:

        try:
            template = Template.objects.get(template_id = t.TemplateID)
        except Template.DoesNotExist:
            template = Template(template_id = t.TemplateID)
            template.name = t.Name
            template.cm_preview_url = t.PreviewURL
            template.cm_screenshot_url = t.ScreenshotURL
        except Exception as e:
            print 'sync template exception', e

        #set up urls
        site_url = get_setting('site', 'global', 'siteurl')
        html_url = unicode("%s%s"%(site_url, template.get_html_url()))
        html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
        html_url += "&events=1"
        html_url += "&events_type="
        html_url += "&event_start_dt=%s" % datetime.date.today()
        end_dt = datetime.date.today() + timedelta(days=90)
        html_url += "&event_end_dt=%s" % end_dt

        if template.zip_file:
            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                zip_url = unicode(template.get_zip_url())
            else:
                zip_url = unicode("%s%s"%(site_url, template.get_zip_url()))
        else:
            zip_url = unicode()

        #sync with campaign monitor
        try:
            cst = CST(auth, template_id=template.template_id)
            cst.update(unicode(template.name), html_url, zip_url)
            success = True
        except BadRequest, e:
            success = False
            if request:
                msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
                messages.add_message(request, messages.ERROR, _(msg_string))
            else:
                print e.data.Code, e.data.Message
                return
        except Exception, e:
            success = False
            if request:
                msg_string = 'Error: %s' % e
                messages.add_message(request, messages.ERROR, _(msg_string))
            else:
                print e.data.Code, e.data.Message
                return
Пример #6
0
def template_edit(request, template_id, form_class=TemplateForm, template_name='campaign_monitor/templates/edit.html'):

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user,'campaign_monitor.change_template', template):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST, request.FILES, instance=template)
        if form.is_valid():

            #save template to generate urls
            template = form.save()

            #set up urls
            site_url = get_setting('site', 'global', 'siteurl')

            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                html_url = template.html_file.url
            else:
                html_url = str("%s%s" % (site_url, template.get_html_url()))

            if template.zip_file:
                if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                    zip_url = template.get_zip_url()
                else:
                    zip_url = "%s%s" % (site_url, template.get_zip_url())
            else:
                zip_url = ""

            #sync with campaign monitor
            try:
                t = CST(auth=auth, template_id = form.instance.template_id)
                t.update(str(template.name), html_url, zip_url)
            except BadRequest, e:
                msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
                messages.add_message(request, messages.ERROR, _(msg_string))
                return render_to_response(template_name, {'form':form},
                    context_instance=RequestContext(request))
            except Exception, e:
                msg_string = 'Error: %s' % e
                messages.add_message(request, messages.ERROR, _(msg_string))
                return render_to_response(template_name, {'form':form},
                    context_instance=RequestContext(request))

            #get campaign monitor details
            t = t.details()
            template.name = t.Name
            template.cm_preview_url = t.PreviewURL
            template.cm_screenshot_url = t.ScreenshotURL
            template.save()

            #extract and serve files in zip
            extract_files(template)
            msg_string = 'Successfully updated Template : %s' % template.template_id
            messages.add_message(request, messages.SUCCESS, _(msg_string))

            return redirect(template)
Пример #7
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, 'campaign_monitor.change_template',
                    template):
        raise Http403

    #set up urls
    site_url = get_setting('site', 'global', 'siteurl')
    html_url = unicode("%s%s" % (site_url, template.get_html_url()))
    html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
    try:
        from tendenci.apps.events.models import Event, Type
        html_url += "&events=1"
        html_url += "&events_type="
        html_url += "&event_start_dt=%s" % datetime.date.today()
        end_dt = datetime.date.today() + timedelta(days=90)
        html_url += "&event_end_dt=%s" % end_dt
    except ImportError:
        pass

    if template.zip_file:
        if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
            zip_url = unicode(template.get_zip_url())
        else:
            zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
    else:
        zip_url = unicode()

    #sync with campaign monitor
    try:
        t = CST(auth=auth, template_id=template.template_id)
        t.update(unicode(template.name), html_url, zip_url)
    except BadRequest as e:
        msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
        messages.add_message(request, messages.ERROR, _(msg_string))
        return redirect(template)
    except Exception as e:
        msg_string = 'Error: %s' % e
        messages.add_message(request, messages.ERROR, _(msg_string))
        return redirect(template)

    #get campaign monitor details
    t = t.details()
    template.name = t.Name
    template.cm_preview_url = t.PreviewURL
    template.cm_screenshot_url = t.ScreenshotURL
    template.save()
    msg_string = 'Successfully updated Template : %s' % template.template_id
    messages.add_message(request, messages.SUCCESS, _(msg_string))

    return redirect(template)
Пример #8
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user,'campaign_monitor.change_template', template):
        raise Http403

    #set up urls
    site_url = get_setting('site', 'global', 'siteurl')
    html_url = str("%s%s"%(site_url, template.get_html_url()))
    html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
    try:
        html_url += "&events=1"
        html_url += "&events_type="
        html_url += "&event_start_dt=%s" % datetime.date.today()
        end_dt = datetime.date.today() + timedelta(days=90)
        html_url += "&event_end_dt=%s" % end_dt
    except ImportError:
        pass

    if template.zip_file:
        if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
            zip_url = str(template.get_zip_url())
        else:
            zip_url = str("%s%s"%(site_url, template.get_zip_url()))
    else:
        zip_url = str()

    #sync with campaign monitor
    try:
        t = CST(auth=auth, template_id = template.template_id)
        t.update(str(template.name), html_url, zip_url)
    except BadRequest as e:
        msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
        messages.add_message(request, messages.ERROR, _(msg_string))
        return redirect(template)
    except Exception as e:
        msg_string = 'Error: %s' % e
        messages.add_message(request, messages.ERROR, _(msg_string))
        return redirect(template)

    #get campaign monitor details
    t = t.details()
    template.name = t.Name
    template.cm_preview_url = t.PreviewURL
    template.cm_screenshot_url = t.ScreenshotURL
    template.save()
    msg_string = 'Successfully updated Template : %s' % template.template_id
    messages.add_message(request, messages.SUCCESS, _(msg_string))

    return redirect(template)
Пример #9
0
def campaign_generate(request, form_class=CampaignForm, template_name='campaign_monitor/campaigns/add.html'):
    if not has_perm(request.user,'campaign_monitor.add_campaign'):
        raise Http403

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            template = form.cleaned_data['template']

            #set up urls
            site_url = get_setting('site', 'global', 'siteurl')
            html_url = str("%s%s"%(site_url, template.get_html_url()))
            html_url += "?jump_links=%s" % form.cleaned_data.get('jump_links')
            try:
                html_url += "&events=%s" % form.cleaned_data.get('events')
                html_url += "&events_type=%s" % form.cleaned_data.get('events_type')
                html_url += "&event_start_dt=%s" % form.cleaned_data.get('event_start_dt', '')
                html_url += "&event_end_dt=%s" % form.cleaned_data.get('event_end_dt', '')
            except ImportError:
                pass
            html_url += "&articles=%s" % form.cleaned_data.get('articles')
            html_url += "&articles_days=%s" % form.cleaned_data.get('articles_days')
            html_url += "&news=%s" % form.cleaned_data.get('news')
            html_url += "&news_days=%s" % form.cleaned_data.get('news_days')
            html_url += "&jobs=%s" % form.cleaned_data.get('jobs')
            html_url += "&jobs_days=%s" % form.cleaned_data.get('jobs_days')
            html_url += "&pages=%s" % form.cleaned_data.get('pages')
            html_url += "&pages_days=%s" % form.cleaned_data.get('pages_days')

            if template.zip_file:
                if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                    zip_url = str(template.get_zip_url())
                else:
                    zip_url = str("%s%s"%(site_url, template.get_zip_url()))
            else:
               zip_url = str()

            #sync with campaign monitor
            try:
                t = CST(auth=auth, template_id = template.template_id)
                t.update(str(template.name), html_url, zip_url)
            except BadRequest as e:
                messages.add_message(request, messages.ERROR, 'Bad Request %s: %s' % (e.data.Code, e.data.Message))
                return redirect('campaign_monitor.campaign_generate')
            except Exception as e:
                messages.add_message(request, messages.ERROR, 'Error: %s' % e)
                return redirect('campaign_monitor.campaign_generate')
            return redirect("%s/campaign/create/new" % settings.CAMPAIGNMONITOR_URL)

    else:
        form = form_class()

    return render_to_resp(request=request, template_name=template_name,
        context={'form':form})
Пример #10
0
def sync_templates(request=None):
    if hasattr(cl, 'templates'): templates = cl.templates()
    else: templates = []
    for t in templates:
        try:
            template = Template.objects.get(template_id=t.TemplateID)
        except Template.DoesNotExist:
            template = Template(template_id=t.TemplateID)
        #set up urls
        site_url = get_setting('site', 'global', 'siteurl')
        html_url = unicode("%s%s" % (site_url, template.get_html_url()))
        html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
        try:
            from tendenci.addons.events.models import Event, Type
            html_url += "&events=1"
            html_url += "&events_type="
            html_url += "&event_start_dt=%s" % datetime.date.today()
            end_dt = datetime.date.today() + timedelta(days=90)
            html_url += "&event_end_dt=%s" % end_dt
        except ImportError:
            pass

        if template.zip_file:
            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                zip_url = unicode(template.get_zip_url())
            else:
                zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
        else:
            zip_url = unicode()

        #sync with campaign monitor
        try:
            t = CST(auth, template_id=template.template_id)
            t.update(unicode(template.name), html_url, zip_url)
        except BadRequest, e:
            if request:
                messages.add_message(
                    request, messages.ERROR,
                    'Bad Request %s: %s' % (e.data.Code, e.data.Message))
                return redirect('campaign_monitor.template_index')
            else:
                print e.data.Code, e.data.Message
                return
        except Exception, e:
            if request:
                messages.add_message(request, messages.ERROR, 'Error: %s' % e)
                return redirect('campaign_monitor.template_index')
            else:
                print e.data.Code, e.data.Message
                return
Пример #11
0
def campaign_generate(request, form_class=CampaignForm, template_name="campaign_monitor/campaigns/add.html"):
    if not has_perm(request.user, "campaign_monitor.add_campaign"):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            template = form.cleaned_data["template"]

            # set up urls
            site_url = get_setting("site", "global", "siteurl")
            html_url = unicode("%s%s" % (site_url, template.get_html_url()))
            html_url += "?jump_links=%s" % form.cleaned_data.get("jump_links")
            try:
                from tendenci.addons.events.models import Event, Type

                html_url += "&events=%s" % form.cleaned_data.get("events")
                html_url += "&events_type=%s" % form.cleaned_data.get("events_type")
                html_url += "&event_start_dt=%s" % form.cleaned_data.get("event_start_dt", "")
                html_url += "&event_end_dt=%s" % form.cleaned_data.get("event_end_dt", "")
            except ImportError:
                pass
            html_url += "&articles=%s" % form.cleaned_data.get("articles")
            html_url += "&articles_days=%s" % form.cleaned_data.get("articles_days")
            html_url += "&news=%s" % form.cleaned_data.get("news")
            html_url += "&news_days=%s" % form.cleaned_data.get("news_days")
            html_url += "&jobs=%s" % form.cleaned_data.get("jobs")
            html_url += "&jobs_days=%s" % form.cleaned_data.get("jobs_days")
            html_url += "&pages=%s" % form.cleaned_data.get("pages")
            html_url += "&pages_days=%s" % form.cleaned_data.get("pages_days")

            if template.zip_file:
                if hasattr(settings, "USE_S3_STORAGE") and settings.USE_S3_STORAGE:
                    zip_url = unicode(template.get_zip_url())
                else:
                    zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
            else:
                zip_url = unicode()

            # sync with campaign monitor
            try:
                t = CST(template_id=template.template_id)
                t.update(unicode(template.name), html_url, zip_url)
            except BadRequest, e:
                messages.add_message(request, messages.ERROR, "Bad Request %s: %s" % (e.data.Code, e.data.Message))
                return redirect("campaign_monitor.campaign_generate")
            except Exception, e:
                messages.add_message(request, messages.ERROR, "Error: %s" % e)
                return redirect("campaign_monitor.campaign_generate")
            return redirect("%s/campaign/create/new" % settings.CAMPAIGNMONITOR_URL)
Пример #12
0
def sync_templates(request=None):
    if hasattr(cl,'templates'): templates = cl.templates()
    else: templates = []
    for t in templates:
        try:
            template = Template.objects.get(template_id = t.TemplateID)
        except Template.DoesNotExist:
            template = Template(template_id = t.TemplateID)        
        #set up urls
        site_url = get_setting('site', 'global', 'siteurl')
        html_url = unicode("%s%s"%(site_url, template.get_html_url()))
        html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
        try:
            from tendenci.addons.events.models import Event, Type
            html_url += "&events=1"
            html_url += "&events_type="
            html_url += "&event_start_dt=%s" % datetime.date.today()
            end_dt = datetime.date.today() + timedelta(days=90)
            html_url += "&event_end_dt=%s" % end_dt
        except ImportError:
            pass

        if template.zip_file:
            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                zip_url = unicode(template.get_zip_url())
            else:
                zip_url = unicode("%s%s"%(site_url, template.get_zip_url()))
        else:
            zip_url = unicode()
        
        #sync with campaign monitor
        try:
            t = CST(template_id = template.template_id)
            t.update(unicode(template.name), html_url, zip_url)
        except BadRequest, e:
            if request:
                messages.add_message(request, messages.ERROR, 'Bad Request %s: %s' % (e.data.Code, e.data.Message))
                return redirect('campaign_monitor.template_index')
            else:
                print e.data.Code, e.data.Message
                return
        except Exception, e:
            if request:
                messages.add_message(request, messages.ERROR, 'Error: %s' % e)
                return redirect('campaign_monitor.template_index')
            else:
                print e.data.Code, e.data.Message
                return
Пример #13
0
    def run(self, template, **kwargs):
        #set up urls
        site_url = get_setting('site', 'global', 'siteurl')
        html_url = unicode("%s%s" % (site_url, template.get_html_url()))
        html_url += "?jump_links=%s" % form.cleaned_data.get('jump_links')
        try:
            from tendenci.addons.events.models import Event, Type
            html_url += "&events=%s" % form.cleaned_data.get('events')
            html_url += "&events_type=%s" % form.cleaned_data.get(
                'events_type')
            html_url += "&event_start_dt=%s" % form.cleaned_data.get(
                'event_start_dt', '')
            html_url += "&event_end_dt=%s" % form.cleaned_data.get(
                'event_end_dt', '')
        except ImportError:
            pass
        html_url += "&articles=%s" % form.cleaned_data.get('articles')
        html_url += "&articles_days=%s" % form.cleaned_data.get(
            'articles_days')
        html_url += "&news=%s" % form.cleaned_data.get('news')
        html_url += "&news_days=%s" % form.cleaned_data.get('news_days')
        html_url += "&jobs=%s" % form.cleaned_data.get('jobs')
        html_url += "&jobs_days=%s" % form.cleaned_data.get('jobs_days')
        html_url += "&pages=%s" % form.cleaned_data.get('pages')
        html_url += "&pages_days=%s" % form.cleaned_data.get('pages_days')

        if template.zip_file:
            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                zip_url = unicode(template.get_zip_url())
            else:
                zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
        else:
            zip_url = unicode()

        #sync with campaign monitor
        try:
            t = CST(template_id=template.template_id)
            t.update(unicode(template.name), html_url, zip_url)
        except BadRequest, e:
            messages.add_message(
                request, messages.ERROR,
                'Bad Request %s: %s' % (e.data.Code, e.data.Message))
            return redirect('campaign_monitor.campaign_generate')
Пример #14
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, "campaign_monitor.change_template", template):
        raise Http403

    # set up urls
    site_url = get_setting("site", "global", "siteurl")
    html_url = unicode("%s%s" % (site_url, template.get_html_url()))
    html_url += "?jump_links=1&articles=1&articles_days=60&news=1&news_days=60&jobs=1&jobs_days=60&pages=1&pages_days=7"
    try:
        from tendenci.addons.events.models import Event, Type

        html_url += "&events=1"
        html_url += "&events_type="
        html_url += "&event_start_dt=%s" % datetime.date.today()
        end_dt = datetime.date.today() + timedelta(days=90)
        html_url += "&event_end_dt=%s" % end_dt
    except ImportError:
        pass

    if template.zip_file:
        if hasattr(settings, "USE_S3_STORAGE") and settings.USE_S3_STORAGE:
            zip_url = unicode(template.get_zip_url())
        else:
            zip_url = unicode("%s%s" % (site_url, template.get_zip_url()))
    else:
        zip_url = unicode()

    # sync with campaign monitor
    try:
        t = CST(template_id=template.template_id)
        t.update(unicode(template.name), html_url, zip_url)
    except BadRequest, e:
        messages.add_message(request, messages.ERROR, "Bad Request %s: %s" % (e.data.Code, e.data.Message))
        return redirect(template)
Пример #15
0
 def run(self, template, **kwargs):
     #set up urls
     site_url = get_setting('site', 'global', 'siteurl')
     html_url = unicode("%s%s"%(site_url, template.get_html_url()))
     html_url += "?jump_links=%s" % form.cleaned_data.get('jump_links')
     try:
         from tendenci.addons.events.models import Event, Type
         html_url += "&events=%s" % form.cleaned_data.get('events')
         html_url += "&events_type=%s" % form.cleaned_data.get('events_type')
         html_url += "&event_start_dt=%s" % form.cleaned_data.get('event_start_dt', '')
         html_url += "&event_end_dt=%s" % form.cleaned_data.get('event_end_dt', '')
     except ImportError:
         pass
     html_url += "&articles=%s" % form.cleaned_data.get('articles')
     html_url += "&articles_days=%s" % form.cleaned_data.get('articles_days')
     html_url += "&news=%s" % form.cleaned_data.get('news')
     html_url += "&news_days=%s" % form.cleaned_data.get('news_days')
     html_url += "&jobs=%s" % form.cleaned_data.get('jobs')
     html_url += "&jobs_days=%s" % form.cleaned_data.get('jobs_days')
     html_url += "&pages=%s" % form.cleaned_data.get('pages')
     html_url += "&pages_days=%s" % form.cleaned_data.get('pages_days')
     
     if template.zip_file:
         if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
             zip_url = unicode(template.get_zip_url())
         else:
             zip_url = unicode("%s%s"%(site_url, template.get_zip_url()))
     else:
         zip_url = unicode()
     
     #sync with campaign monitor
     try:
         t = CST(template_id = template.template_id)
         t.update(unicode(template.name), html_url, zip_url)
     except BadRequest, e:
         messages.add_message(request, messages.ERROR, 'Bad Request %s: %s' % (e.data.Code, e.data.Message))
         return redirect('campaign_monitor.campaign_generate')
Пример #16
0
def template_edit(request,
                  template_id,
                  form_class=TemplateForm,
                  template_name='campaign_monitor/templates/edit.html'):

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, 'campaign_monitor.change_template',
                    template):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST, request.FILES, instance=template)
        if form.is_valid():

            #save template to generate urls
            template = form.save()

            #set up urls
            site_url = get_setting('site', 'global', 'siteurl')

            if hasattr(settings, 'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                html_url = template.html_file.url
            else:
                html_url = str("%s%s" % (site_url, template.get_html_url()))

            if template.zip_file:
                if hasattr(settings,
                           'USE_S3_STORAGE') and settings.USE_S3_STORAGE:
                    zip_url = template.get_zip_url()
                else:
                    zip_url = "%s%s" % (site_url, template.get_zip_url())
            else:
                zip_url = ""

            #sync with campaign monitor
            try:
                t = CST(auth=auth, template_id=form.instance.template_id)
                t.update(str(template.name), html_url, zip_url)
            except BadRequest, e:
                msg_string = 'Bad Request %s: %s' % (e.data.Code,
                                                     e.data.Message)
                messages.add_message(request, messages.ERROR, _(msg_string))
                return render_to_response(
                    template_name, {'form': form},
                    context_instance=RequestContext(request))
            except Exception, e:
                msg_string = 'Error: %s' % e
                messages.add_message(request, messages.ERROR, _(msg_string))
                return render_to_response(
                    template_name, {'form': form},
                    context_instance=RequestContext(request))

            #get campaign monitor details
            t = t.details()
            template.name = t.Name
            template.cm_preview_url = t.PreviewURL
            template.cm_screenshot_url = t.ScreenshotURL
            template.save()

            #extract and serve files in zip
            extract_files(template)
            msg_string = 'Successfully updated Template : %s' % template.template_id
            messages.add_message(request, messages.SUCCESS, _(msg_string))

            return redirect(template)