Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

pep8 fixes #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions credits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class Profile(models.Model):

"""
For testing, track the number of "credits".
"""
Expand Down
35 changes: 18 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys
import os

sys.path.insert(0, os.path.abspath('..'))
version = __import__('drip').__version__
Expand All @@ -21,7 +22,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))

# -- General configuration -----------------------------------------------------
# -- General configuration -----------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
Expand Down Expand Up @@ -90,7 +91,7 @@
#modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------------
# -- Options for HTML output ---------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
Expand Down Expand Up @@ -170,24 +171,24 @@
htmlhelp_basename = 'DjangoDripdoc'


# -- Options for LaTeX output --------------------------------------------------
# -- Options for LaTeX output --------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'DjangoDrip.tex', u'Django Drip Documentation',
u'Bryan Helmig', 'manual'),
('index', 'DjangoDrip.tex', u'Django Drip Documentation',
u'Bryan Helmig', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -211,7 +212,7 @@
#latex_domain_indices = True


# -- Options for manual page output --------------------------------------------
# -- Options for manual page output --------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
Expand All @@ -224,15 +225,15 @@
#man_show_urls = False


# -- Options for Texinfo output ------------------------------------------------
# -- Options for Texinfo output ------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'DjangoDrip', u'Django Drip Documentation',
u'Bryan Helmig', 'DjangoDrip', 'One line description of project.',
'Miscellaneous'),
('index', 'DjangoDrip', u'Django Drip Documentation',
u'Bryan Helmig', 'DjangoDrip', 'One line description of project.',
'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand Down
38 changes: 23 additions & 15 deletions drip/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class QuerySetRuleInline(admin.TabularInline):

class DripForm(forms.ModelForm):
message_class = forms.ChoiceField(
choices=((k, '%s (%s)' % (k, v)) for k, v in configured_message_classes().items())
choices=((k, '%s (%s)' % (k, v))
for k, v in configured_message_classes().items())
)

class Meta:
model = Drip
exclude = []
Expand All @@ -30,6 +32,7 @@ class DripAdmin(admin.ModelAdmin):
form = DripForm

av = lambda self, view: self.admin_site.admin_view(view)

def timeline(self, request, drip_id, into_past, into_future):
"""
Return a list of people who should get emails.
Expand All @@ -40,17 +43,22 @@ def timeline(self, request, drip_id, into_past, into_future):

shifted_drips = []
seen_users = set()
for shifted_drip in drip.drip.walk(into_past=int(into_past), into_future=int(into_future)+1):
for shifted_drip in drip.drip.walk(
into_past=int(into_past), into_future=int(into_future) + 1):
shifted_drip.prune()
shifted_drips.append({
'drip': shifted_drip,
'qs': shifted_drip.get_queryset().exclude(id__in=seen_users)
})
seen_users.update(shifted_drip.get_queryset().values_list('id', flat=True))
seen_users.update(
shifted_drip.get_queryset().values_list(
'id',
flat=True))

return render(request, 'drip/timeline.html', locals())

def view_drip_email(self, request, drip_id, into_past, into_future, user_id):
def view_drip_email(
self, request, drip_id, into_past, into_future, user_id):
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
drip = get_object_or_404(Drip, id=drip_id)
Expand Down Expand Up @@ -90,17 +98,17 @@ def get_urls(self):
from django.conf.urls import patterns, url
urls = super(DripAdmin, self).get_urls()
my_urls = patterns('',
url(
r'^(?P<drip_id>[\d]+)/timeline/(?P<into_past>[\d]+)/(?P<into_future>[\d]+)/$',
self.av(self.timeline),
name='drip_timeline'
),
url(
r'^(?P<drip_id>[\d]+)/timeline/(?P<into_past>[\d]+)/(?P<into_future>[\d]+)/(?P<user_id>[\d]+)/$',
self.av(self.view_drip_email),
name='view_drip_email'
)
)
url(
r'^(?P<drip_id>[\d]+)/timeline/(?P<into_past>[\d]+)/(?P<into_future>[\d]+)/$',
self.av(self.timeline),
name='drip_timeline'
),
url(
r'^(?P<drip_id>[\d]+)/timeline/(?P<into_past>[\d]+)/(?P<into_future>[\d]+)/(?P<user_id>[\d]+)/$',
self.av(self.view_drip_email),
name='view_drip_email'
)
)
return my_urls + urls
admin.site.register(Drip, DripAdmin)

Expand Down
33 changes: 23 additions & 10 deletions drip/drips.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ def context(self):
@property
def subject(self):
if not self._subject:
self._subject = Template(self.drip_base.subject_template).render(self.context)
self._subject = Template(
self.drip_base.subject_template).render(
self.context)
return self._subject

@property
def body(self):
if not self._body:
self._body = Template(self.drip_base.body_template).render(self.context)
self._body = Template(
self.drip_base.body_template).render(
self.context)
return self._body

@property
Expand All @@ -83,7 +87,8 @@ def plain(self):
def message(self):
if not self._message:
if self.drip_base.from_email_name:
from_ = "%s <%s>" % (self.drip_base.from_email_name, self.drip_base.from_email)
from_ = "%s <%s>" % (
self.drip_base.from_email_name, self.drip_base.from_email)
else:
from_ = self.drip_base.from_email

Expand All @@ -97,6 +102,7 @@ def message(self):


class DripBase(object):

"""
A base object for defining a Drip.

Expand All @@ -115,16 +121,19 @@ def __init__(self, drip_model, *args, **kwargs):

self.name = kwargs.pop('name', self.name)
self.from_email = kwargs.pop('from_email', self.from_email)
self.from_email_name = kwargs.pop('from_email_name', self.from_email_name)
self.subject_template = kwargs.pop('subject_template', self.subject_template)
self.from_email_name = kwargs.pop(
'from_email_name',
self.from_email_name)
self.subject_template = kwargs.pop(
'subject_template',
self.subject_template)
self.body_template = kwargs.pop('body_template', self.body_template)

if not self.name:
raise AttributeError('You must define a name.')

self.now_shift_kwargs = kwargs.get('now_shift_kwargs', {})


#########################
### DATE MANIPULATION ###
#########################
Expand Down Expand Up @@ -211,7 +220,7 @@ def prune(self):
exclude_user_ids = SentDrip.objects.filter(date__lt=conditional_now(),
drip=self.drip_model,
user__id__in=target_user_ids)\
.values_list('user_id', flat=True)
.values_list('user_id', flat=True)
self._queryset = self.get_queryset().exclude(id__in=exclude_user_ids)

def send(self):
Expand All @@ -224,7 +233,10 @@ def send(self):
"""

if not self.from_email:
self.from_email = getattr(settings, 'DRIP_FROM_EMAIL', settings.DEFAULT_FROM_EMAIL)
self.from_email = getattr(
settings,
'DRIP_FROM_EMAIL',
settings.DEFAULT_FROM_EMAIL)
MessageClass = message_class_for(self.drip_model.message_class)

count = 0
Expand All @@ -243,11 +255,12 @@ def send(self):
)
count += 1
except Exception as e:
logging.error("Failed to send drip %s to user %s: %s" % (self.drip_model.id, user, e))
logging.error(
"Failed to send drip %s to user %s: %s" %
(self.drip_model.id, user, e))

return count


####################
### USER DEFINED ###
####################
Expand Down
1 change: 1 addition & 0 deletions drip/management/commands/send_drips.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class Command(BaseCommand):

def handle(self, *args, **options):
from drip.models import Drip

Expand Down
59 changes: 38 additions & 21 deletions drip/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,59 @@ class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Drip'
db.create_table('drip_drip', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('lastchanged', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
('enabled', self.gf('django.db.models.fields.BooleanField')(default=False)),
('subject_template', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
('body_html_template', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
('id', self.gf('django.db.models.fields.AutoField')
(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')
(auto_now_add=True, blank=True)),
('lastchanged', self.gf('django.db.models.fields.DateTimeField')
(auto_now=True, blank=True)),
('name', self.gf('django.db.models.fields.CharField')
(unique=True, max_length=255)),
('enabled',
self.gf('django.db.models.fields.BooleanField')(default=False)),
('subject_template', self.gf('django.db.models.fields.TextField')
(null=True, blank=True)),
('body_html_template', self.gf(
'django.db.models.fields.TextField')(null=True, blank=True)),
))
db.send_create_signal('drip', ['Drip'])

# Adding model 'SentDrip'
db.create_table('drip_sentdrip', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('drip', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sent_drips', to=orm['drip.Drip'])),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sent_drips', to=orm['auth.User'])),
('id', self.gf('django.db.models.fields.AutoField')
(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')
(auto_now_add=True, blank=True)),
('drip', self.gf('django.db.models.fields.related.ForeignKey')
(related_name='sent_drips', to=orm['drip.Drip'])),
('user', self.gf('django.db.models.fields.related.ForeignKey')
(related_name='sent_drips', to=orm['auth.User'])),
('subject', self.gf('django.db.models.fields.TextField')()),
('body', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal('drip', ['SentDrip'])

# Adding model 'QuerySetRule'
db.create_table('drip_querysetrule', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('lastchanged', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
('drip', self.gf('django.db.models.fields.related.ForeignKey')(related_name='queryset_rules', to=orm['drip.Drip'])),
('method_type', self.gf('django.db.models.fields.CharField')(default='filter', max_length=12)),
('field_name', self.gf('django.db.models.fields.CharField')(max_length=128)),
('lookup_type', self.gf('django.db.models.fields.CharField')(default='exact', max_length=12)),
('field_value', self.gf('django.db.models.fields.CharField')(max_length=255)),
('id', self.gf('django.db.models.fields.AutoField')
(primary_key=True)),
('date', self.gf('django.db.models.fields.DateTimeField')
(auto_now_add=True, blank=True)),
('lastchanged', self.gf('django.db.models.fields.DateTimeField')
(auto_now=True, blank=True)),
('drip', self.gf('django.db.models.fields.related.ForeignKey')
(related_name='queryset_rules', to=orm['drip.Drip'])),
('method_type', self.gf('django.db.models.fields.CharField')
(default='filter', max_length=12)),
('field_name',
self.gf('django.db.models.fields.CharField')(max_length=128)),
('lookup_type', self.gf('django.db.models.fields.CharField')
(default='exact', max_length=12)),
('field_value',
self.gf('django.db.models.fields.CharField')(max_length=255)),
))
db.send_create_signal('drip', ['QuerySetRule'])


def backwards(self, orm):
# Deleting model 'Drip'
db.delete_table('drip_drip')
Expand All @@ -55,7 +73,6 @@ def backwards(self, orm):
# Deleting model 'QuerySetRule'
db.delete_table('drip_querysetrule')


models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
Expand Down