jezdez/django-dbtemplates — Issue #17: Using dbtemplates outside of response
Author: selwin
Created: 2011-12-04 08:16:24+00:00
State: open

Hi Jannis,

Currently dbtemplates' use is limited to rendering HTML templates to response and I was wondering if you'd be interested in extending its functionality for other uses.

I currently store email templates in the db so end users can easily edit those but to render these into emails I currently need to do (not sure if there's a cleaner way though):

```
from dbtemplates.models import Template as DBTemplate
from django.template import Context, RequestContext, Template

context_data = { 'foo': 'bar' }
db_template = DBTemplate.objects.get(name='Template name')
template = Template(db_template.content)
message = template.render(Context(context_data))
send_mail(subject, message, from_email, [recipient])
```

I'd like to be able to achieve the same by doing:

```
import dbtemplates

context_data = { 'foo': 'bar' }
message = dbtemplates.render_to_string('template_name', context_data)
send_mail(subject, message, from_email, [recipient])
```

Other proposed APIs:

```
message = dbtemplates.render_to_string('template_name', context_data, request_context)
message = dbtemplates.render(request, 'template_name', context_data) #Similar to the render shortcut in 1.3
template = dbtemplates.get_template('template_name') # If you want to get the template out of db for lower level usage
```

If you're interested, I'll be happy to write a patch as well as tests to implement these. Let me know :)

Regards,
Selwin