Skip to content

Commit

Permalink
Autoload email context from fields
Browse files Browse the repository at this point in the history
  • Loading branch information
timthelion committed Dec 12, 2019
1 parent 73db18f commit 7afe3b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/project/settings.py
Expand Up @@ -117,6 +117,8 @@

USE_TZ = True

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
CELERY_EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
Expand Down
4 changes: 3 additions & 1 deletion example/winners/models.py
Expand Up @@ -25,7 +25,9 @@ def get_email(self):
return self.obj.user.email

def get_context(self, base_url):
return {'name': self.obj.user.username}
context = super().get_context(base_url)
context['base_url'] = base_url
return context

def get_language(self):
return "en"
Expand Down
6 changes: 6 additions & 0 deletions smmapdfs/model_abcs/pdfsandwich_abc.py
Expand Up @@ -47,6 +47,12 @@ def get_pdf_url(self, base_url):
def get_fields(self):
return self.field_model.objects.filter(pdfsandwich_type=self.pdfsandwich_type)

def get_context(self, base_url):
context = {}
for name, field in self.field_model.fields.items():
context[name] = field(self.obj)
return context

def update_pdf(self, obj):
self.status = ""
temp = NamedTemporaryFile()
Expand Down

0 comments on commit 7afe3b2

Please sign in to comment.