Commit db5792fc authored by Adrián Ribao's avatar Adrián Ribao
Browse files

some improvements and image management

parent 7383114c
......@@ -4,7 +4,7 @@ from django.contrib import admin
#from mptt.admin import MPTTModelAdmin
from django.utils.translation import ugettext_lazy as _
from cartero.models import Contact, EmailTemplate, Campaign, ExcludedEmail,\
ShortURL, LinkClick, OpenEmail
ShortURL, LinkClick, OpenEmail, Image
from django.conf.urls.defaults import patterns, include, url
from cartero.views import CreateTemplateView, UpdateTemplateView
from cartero.utils.sending import CampaignDeliver
......@@ -16,9 +16,9 @@ from cartero.utils.sending import CampaignDeliver
class ContactAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
list_display = [
'email',
'first_name',
'last_name',
'email',
'sent',
'testing',
'bounced',
......@@ -180,3 +180,19 @@ class OpenEmailAdmin(admin.ModelAdmin):
'ip_address',
]
admin.site.register(OpenEmail, OpenEmailAdmin)
class ImageAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
list_display = [
'name',
'site',
'file_url',
]
list_filter = [
'site',
]
search_fields = [
'name',
]
prepopulated_fields = {"slug": ("name", )}
admin.site.register(Image, ImageAdmin)
# -*- coding: utf-8 -*-
from appconf import AppConf
import os
class CarteroConf(AppConf):
APP_ROOT = os.path.abspath(os.path.dirname(__file__))
EMAIL_TEMPLATES = os.path.join(APP_ROOT, "templates/cartero/emails/")
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Image'
db.create_table('cartero_image', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=255)),
('name', self.gf('django.db.models.fields.CharField')(max_length=150)),
('file', self.gf('django.db.models.fields.files.ImageField')(max_length=100)),
))
db.send_create_signal('cartero', ['Image'])
# Changing field 'EmailTemplate.template'
db.alter_column('cartero_emailtemplate', 'template', self.gf('django.db.models.fields.FilePathField')(path='/home/antares/paginas_web/adcxml/templates/mails/campaigns/', max_length=255, match='\\.html$'))
def backwards(self, orm):
# Deleting model 'Image'
db.delete_table('cartero_image')
# Changing field 'EmailTemplate.template'
db.alter_column('cartero_emailtemplate', 'template', self.gf('django.db.models.fields.FilePathField')(path='/home/antares/paginas_web/adcxml/cartero/templates/cartero/', max_length=255, match='\\.html$'))
models = {
'cartero.campaign': {
'Meta': {'object_name': 'Campaign'},
'contacts': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['cartero.Contact']", 'symmetrical': 'False', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'email_template': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.EmailTemplate']"}),
'from_email': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'rate_limit_amount': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '60'}),
'rate_limit_interval': ('django.db.models.fields.CharField', [], {'default': "'h'", 'max_length': '1'}),
'ready': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'reply_to': ('django.db.models.fields.CharField', [], {'max_length': '150', 'blank': 'True'}),
'sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['sites.Site']"}),
'start': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 2, 13, 0, 0)'}),
'subject': ('django.db.models.fields.CharField', [], {'max_length': '150'})
},
'cartero.contact': {
'Meta': {'object_name': 'Contact'},
'bounced': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '200'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['sites.Site']"}),
'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'cartero.emailtemplate': {
'Meta': {'object_name': 'EmailTemplate'},
'context': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'plain': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
'template': ('django.db.models.fields.FilePathField', [], {'path': "'/home/antares/paginas_web/adcxml/templates/mails/campaigns/'", 'max_length': '255', 'match': "'\\\\.html$'"})
},
'cartero.excludedemail': {
'Meta': {'object_name': 'ExcludedEmail'},
'comments': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '200'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'reason': ('django.db.models.fields.CharField', [], {'max_length': '2'})
},
'cartero.image': {
'Meta': {'object_name': 'Image'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'file': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'})
},
'cartero.linkclick': {
'Meta': {'object_name': 'LinkClick'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'db_index': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.ShortURL']"})
},
'cartero.mailtracks': {
'Meta': {'object_name': 'MailTracks'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Contact']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'cartero.openemail': {
'Meta': {'object_name': 'OpenEmail'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Contact']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'db_index': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'cartero.shorturl': {
'Meta': {'object_name': 'ShortURL'},
'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '75', 'db_index': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'})
},
'sites.site': {
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
}
}
complete_apps = ['cartero']
\ No newline at end of file
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Image.site'
db.add_column('cartero_image', 'site',
self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['sites.Site']),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Image.site'
db.delete_column('cartero_image', 'site_id')
models = {
'cartero.campaign': {
'Meta': {'object_name': 'Campaign'},
'contacts': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['cartero.Contact']", 'symmetrical': 'False', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'email_template': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.EmailTemplate']"}),
'from_email': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'rate_limit_amount': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '60'}),
'rate_limit_interval': ('django.db.models.fields.CharField', [], {'default': "'h'", 'max_length': '1'}),
'ready': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'reply_to': ('django.db.models.fields.CharField', [], {'max_length': '150', 'blank': 'True'}),
'sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['sites.Site']"}),
'start': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 2, 13, 0, 0)'}),
'subject': ('django.db.models.fields.CharField', [], {'max_length': '150'})
},
'cartero.contact': {
'Meta': {'object_name': 'Contact'},
'bounced': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '200'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['sites.Site']"}),
'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'cartero.emailtemplate': {
'Meta': {'object_name': 'EmailTemplate'},
'context': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'plain': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
'template': ('django.db.models.fields.FilePathField', [], {'path': "'/home/antares/paginas_web/adcxml/templates/mails/campaigns/'", 'max_length': '255', 'match': "'\\\\.html$'"})
},
'cartero.excludedemail': {
'Meta': {'object_name': 'ExcludedEmail'},
'comments': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '200'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'reason': ('django.db.models.fields.CharField', [], {'max_length': '2'})
},
'cartero.image': {
'Meta': {'object_name': 'Image'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'file': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['sites.Site']"}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'})
},
'cartero.linkclick': {
'Meta': {'object_name': 'LinkClick'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'db_index': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.ShortURL']"})
},
'cartero.mailtracks': {
'Meta': {'object_name': 'MailTracks'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Contact']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'cartero.openemail': {
'Meta': {'object_name': 'OpenEmail'},
'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Campaign']"}),
'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cartero.Contact']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'db_index': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
'cartero.shorturl': {
'Meta': {'object_name': 'ShortURL'},
'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '75', 'db_index': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'})
},
'sites.site': {
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
}
}
complete_apps = ['cartero']
\ No newline at end of file
......@@ -12,14 +12,14 @@ from django.dispatch import receiver
import string
import random
from django.core.urlresolvers import reverse
from django.conf import settings
from cartero.conf import CarteroConf
#from django.contrib.auth.models import User
APP_ROOT = os.path.abspath(os.path.dirname(__file__))
class Contact(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
site = models.ForeignKey(Site, verbose_name=_(u'Site'))
site = models.ForeignKey(Site, verbose_name=_(u'Site'), default=settings.SITE_ID)
first_name = models.CharField(max_length=150, verbose_name=_(u'First name'), blank=False,
help_text=_(u'First name of the contact.'))
last_name = models.CharField(max_length=150, verbose_name=_(u'Last name'), blank=False,
......@@ -37,7 +37,7 @@ class Contact(models.Model):
verbose_name_plural = _(u'Contacts')
def __unicode__(self):
return u'{0} {1}'.format(self.first_name, self.last_name)
return u'{0} {1} {2}'.format(self.email, self.first_name, self.last_name)
class EmailTemplate(models.Model):
created = models.DateTimeField(auto_now_add=True)
......@@ -45,7 +45,7 @@ class EmailTemplate(models.Model):
site = models.ForeignKey(Site, verbose_name=_(u'Site'))
name = models.CharField(max_length=150, verbose_name=_(u'Name'), blank=False,
help_text=_(u'Name of the template.'))
template = models.FilePathField(path=os.path.join(APP_ROOT, 'templates/cartero/'), match='\.html$', recursive=False, max_length=255)
template = models.FilePathField(path=settings.CARTERO_EMAIL_TEMPLATES, match='\.html$', recursive=False, max_length=255)
context = models.TextField(blank=True, verbose_name=_(u'JSON context'),
help_text=_(u'JSON context pased to the template.'))
html = models.TextField(blank=True, verbose_name=_(u'HTML content'),
......@@ -92,7 +92,7 @@ class Campaign(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
site = models.ForeignKey(Site, verbose_name=_(u'Site'))
site = models.ForeignKey(Site, verbose_name=_(u'Site'), default=settings.SITE_ID)
name = models.CharField(max_length=150, verbose_name=_(u'Name'), blank=False,
help_text=_(u'Name of the campaign.'))
subject = models.CharField(max_length=150, verbose_name=_(u'Subject'), blank=False,
......@@ -278,3 +278,23 @@ class OpenEmail(models.Model):
#def get_absolute_url(self):
#return ('view_or_url_name' )
class Image(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
site = models.ForeignKey(Site, verbose_name=_(u'Site'), default=settings.SITE_ID)
name = models.CharField(max_length=150, verbose_name=_(u'Name'), blank=False,
help_text=_(u'Name of the campaign.'))
slug = models.SlugField(max_length=255, unique=True)
file = models.ImageField(upload_to='cartero/images/', verbose_name=_(u'Image File'),
help_text=_(u'Image file'))
class Meta:
verbose_name = _(u'Image')
verbose_name_plural = _(u'Images')
def __unicode__(self):
return u'{0}'.format(self.name, )
def file_url(self):
url = 'http://{0}{1}'.format(self.site.domain, self.file.url)
return url
{% extends "mails/base/basic.html" %}
{% load tt_cartero %}
{% block header_text %}{% editable_text header_text %}{% endblock %}
{% block intro %}{{ block.super }}{% endblock %}
{% block intro_header %}
{% editable_text intro_header %}
{% endblock %}
{% block intro_content %}
{% editable_html intro_content %}
{% endblock %}
{% block content %}
{% editable_html content %}
{% endblock %}
{% block callout %}{% endblock %}
......@@ -4,7 +4,7 @@ from django.template import loader, Context
from cartero.utils.templates import get_nodes
class TemplateTestCase(TestCase):
template = 'cartero/base_email.html'
template = 'cartero/emails/base_email.html'
def test_read_placeholders(self):
"""
......@@ -13,7 +13,6 @@ class TemplateTestCase(TestCase):
t = loader.get_template(self.template)
c = Context({})
nodes = get_nodes(t)
for node in nodes:
print node.tag_name, node.name, node.tag_args
assert False
self.assertEqual(1 + 1, 2)
#for node in nodes:
#print node.tag_name, node.name, node.tag_args
#assert False
......@@ -20,6 +20,11 @@ class CampaignDeliver(object):
self.campaign = campaign
self.site = Site.objects.get_current()
def get_tree_from_html(self, html):
parser = etree.HTMLParser()
tree = etree.parse(StringIO(html), parser)
return tree
def compile_css(self, tree):
# Insert css from external files
links = tree.xpath('//link')
......@@ -45,12 +50,10 @@ class CampaignDeliver(object):
html = p.transform()
return html
def parse_links(self, html):
def parse_links(self, tree):
"""
Parse the links and return the lxml tree.
"""
parser = etree.HTMLParser()
tree = etree.parse(StringIO(html), parser)
links = tree.xpath('//a')
for link in links:
href= link.attrib.get('href')
......@@ -103,8 +106,10 @@ class CampaignDeliver(object):
t = Template(html)
html = t.render(Context(context))
# Get the tree
tree = self.get_tree_from_html(html)
# Parse links
tree = self.parse_links(html)
tree = self.parse_links(tree)
# Add track
tree = self.add_track(tree, contact)
# Compile css
......
......@@ -3,7 +3,7 @@ from django.views.generic import FormView, DetailView, UpdateView, View, Templat
#from django.views.generic.list import ListView
#from django.views.generic.detail import DetailView
from django.http import HttpResponse
from cartero.models import EmailTemplate, APP_ROOT, ExcludedEmail, ShortURL, LinkClick, Campaign, MailTracks, OpenEmail
from cartero.models import EmailTemplate, ExcludedEmail, ShortURL, LinkClick, Campaign, MailTracks, OpenEmail
from cartero.forms import EmailTemplateForm
from django.core.urlresolvers import reverse_lazy, reverse
from cartero.utils.templates import get_nodes
......@@ -100,7 +100,7 @@ class PreviewTemplate(DetailView):
return context
def get_preview(self):
email_template = loader.get_template(self.object.template.replace(os.path.join(APP_ROOT, 'templates/'), ''))
email_template = loader.get_template(self.object.template.replace(os.path.join(settings.CARTERO_APP_ROOT, 'templates/'), ''))
c = RequestContext(self.request, self.get_context())
html = email_template.render(c)
#html = self.compile_css(html)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment