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)
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
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)
def template_delete(request, template_id): template = get_object_or_404(Template, template_id=template_id) if not has_perm(request.user, 'campaign_monitor.delete_template', template): raise Http403 t_id = template.template_id try: CST(auth=auth, template_id=t_id).delete() 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) template.delete() msg_string = 'Successfully deleted Template : %s' % t_id messages.add_message(request, messages.SUCCESS, _(msg_string)) return redirect("campaign_monitor.template_index")
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)
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
def template_delete(request, template_id): template = get_object_or_404(Template, template_id=template_id) if not has_perm(request.user, 'campaign_monitor.delete_template', template): raise Http403 t_id = template.template_id try: CST(auth=auth, template_id=t_id).delete() except BadRequest, e: msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message) messages.add_message(request, messages.ERROR, _(msg_string)) return redirect(template)
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')
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)
def template_add(request, form_class=TemplateForm, template_name='campaign_monitor/templates/add.html'): if not has_perm(request.user, 'campaign_monitor.add_template'): raise Http403 if request.method == "POST": form = form_class(request.POST, request.FILES) if form.is_valid(): #save template to generate urls template = form.save(commit=False) template.template_id = temporary_id() template.save() #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 = "%s%s" % (site_url, template.get_html_url()) else: zip_url = "" #sync with campaign monitor try: t_id = CST(auth=auth).create(client_id, 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)) template.delete() return render_to_response( template_name, {'form': form}, context_instance=RequestContext(request)) except Exception, e: messages.add_message(request, messages.ERROR, 'Error: %s' % e) template.delete() return render_to_response( template_name, {'form': form}, context_instance=RequestContext(request)) #get campaign monitor details t = CST(auth=auth, template_id=t_id).details() template.template_id = t_id 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) messages.add_message(request, messages.SUCCESS, 'Successfully created Template : %s' % t_id) return redirect(template)