jazzband / django-dbtemplates Goto Github PK
View Code? Open in Web Editor NEWDjango template loader for database stored templates with extensible cache backend
Home Page: https://django-dbtemplates.readthedocs.io
License: Other
Django template loader for database stored templates with extensible cache backend
Home Page: https://django-dbtemplates.readthedocs.io
License: Other
Hi,
I had develop a similar (but incomplete) app to store template in database.
In combination with a custom ODTTemplate Engine, It allows to store and use ODT files as template.
Your app is very very usefull and complete, but I can't use it because I can't set my ODT content manually, only by upload a template file.
What do you think about transform Template content field in real FielField, and keep content as cached property ? (Well, it is possible in admin to keep content field to handle text content and store it as file)
I can propose a PR for this.
Thank you for your advice
Is it possible to store the .mo file (compiled .po file) in the database for the templates that are in the database?
If so, do you have a hint on how to approach this?
I am using a foreignkey to dbtemplates Template model to determine how to display another model. ie.
class MyModel(models.Model):
template = models.ForeignKey(Template)
...
When I switch the template field on MyModel to another template via the admin, MyModel is not getting the correct template for display. I get "TemplateDoesNotExist" sometimes. Other times it continues to display using the previous template. It never updates to the new template though. I have to use the admin action "repopulate cache with selected items" to get it to find the template again.
I am using a class based view and defining "get_template_names()" to get the Template model from the foreignkey.
Shouldn't the template be updating when the foreignkey is changed? And shouldn't it find the correct one either in the cache or via the database?
(Django 1.5)
Since the introduction of the CACHES
setting Django by default uses the LocMemCache
backend. Using multiple Django processes on the server, each process maintains it's own cache (as documented here: https://docs.djangoproject.com/en/1.6/topics/cache/#local-memory-caching).
I think this yields to outdated templates in the cache of all processes, except the one, that was used to save a change through the Django Admin.
Setting DBTEMPLATES_CACHE_BACKEND
to None
does not change the behaviour.
I think this behaviour needs to be documented, because I have to actively disable the LocMemCache setting to fix the problem with stale db-templates.
If I don't use caching at all in a project, I would normally not think about altering the Django default setting.
Environment: Django 1.6.2, Python 2.7.5, dbtemplates 1.3
Possibly related to #43
Edit: Using a DummyCache
as the default cache fixed the problem with stale db-templates completely.
(With full acknowledgement that submitting this issue without a PR is only so helpful on my part ... ! )
It looks like Django 2.0 comes with a new template loader API, which actually matches dbtemplates
a bit more nicely. Here is a simple proof-of-concept implementation, sans caching and other basic safeguards, for dbtemplates/loader.py
:
from django.contrib.sites.models import Site
from django.template import Origin, TemplateDoesNotExist
from django.template.loaders.base import Loader as BaseLoader
from dbtemplates.models import Template
class Loader(BaseLoader):
def get_contents(self, origin):
site = Site.objects.get_current()
template = Template.objects.get(name=origin.template_name, sites__in=[site.id])
return template.content
def get_template_sources(self, template_name):
site = Site.objects.get_current()
try:
template = Template.objects.get(name=template_name, sites__in=[site.id])
yield Origin(name=template_name, template_name=template_name, loader=self)
except Template.DoesNotExist:
pass
I'm brand new to the project, and I'm happy to take a swing at it if no one else is interested, but thought I would at least get the conversation going first.
Hi Jannis,
The dbtemplates can not change the content inside html file at templates directory even on the admin already changed.
Also it will be awesome if can convert html into text at the content.
Hi I would like to manage just few templates with dbtemplates. But I sync and generate the locale messages, it asks for all the templates.
How can I skip this process?
Hi,
I just ran into issue #33 while using the latest version of dbtemplates in PyPI (https://pypi.python.org/pypi/django-dbtemplates). It's at least two years out of date :(
dbtemplates does not work with dummy cache backend (I use it for development).
You can check it by adding next lines to your settings.py
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
Hi,
First, thanks for putting this out there - I plan on using it or some variant, but am running in to issues with multiple sites. There are two 'modes' of use of django.contrib.sites - the original (SITE_ID = ) and 'by request' (no SITE_ID). Some packages make use of the second method, things like allauth for social authentication, for instance. I intend to run my site this way and like the way dbtemapltes is set up, but cannot run because of the dependancy to SITE_ID.
Unfortunately, loaders don't have access to the request for good reason, they may be used elsewhere.
One way I can solve this is with a 5-6 line patch to django itself. I have proposed this to the django development group with muted response, but without outright "won't fix" ("maybe, someday"). No comments yet.
Alternately, I may modify this thing to take a setting if present, otherwise call get_current. I believe this would create a version of dbtemplates which works identically for all installations currently using SITE_ID and allow friendly operation with "by_request". As far as I can see, the only catch is making sure settings.DBTEMPALTES_SITE_ID is in the M2M for all templates.
This scheme would effectively combine the template namespace to the 'main', but I'll probably just string mash the site pk in to the template name under the hood.
Thoughts? Should I go to the effort to try to generalize and prepare a pull request?
Regards,
Ira
To reproduce:
Sites: site1, site2 and site3
File template: copyright.html and 2 dbtemplates, for site1 and site2 respectively.
When active site is site3 and "copyright.html" template is requested, dbtemplates raises MultipleObjectsReturned
.
I would except dbtemplates to raise TemplateDoesNotExist
. loader
will then try to find this template from next template loader, in this case from filesystem.
In my opinion, dbtemplates should try to find template from database which is associated with current site, and if that fails then template from database which is not associated with any site. dbtemplates should not return template associated with site2 when active site is site1.
django flatpage can without site_id and auto switch site by request, but django-dbtemplates must set django site id. Unfortunately when I setting site id , flatpage only know what I set. flatpage can not switch site from request. I want to know why we need site
I've been trying to integrate DBTemplates into my site and have run into a bug when using CodeMirror where the first line of code starts on what appears to be line 3, but it's just the div containing the line numbers being pushed down for some reason. Changing the width of the iframe from 100% to 90% seems to be a viable fix, but I'd be very surprised if this isn't something that's been found before.
I've put a screenshot of what we're seeing down below
Hello there, first many thanks for the great scripts.
I am trying to use css and js just like template, any way around ? it will be great to manage css and js files and use something like <link href="{% static "faq/style.css" %}" rel="stylesheet" type="text/css" media="screen" />
Cheers,
In certain cases test suite's
dbtemplates.DbTemplatesTestCase.test_sync_templates
loads templates from other apps and changes them locally, reformatting the contents.
get_template(namestring) is raising the error TemplateDoesNotExist when called with the name of a template known to be in the database.
(virtenv)user@ubuntu:~/dev/project$ python manage.py shell
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from dbtemplates.models import Template
>>> test_template = Template.objects.get(pk=1)
>>> test_template.name
u'TestTemplate1'
>>> from django.template.loader import get_template
>>> get_template('TestTemplate1')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/.virtualenvs/virtenv/local/lib/python2.7/site-packages/django/template/loader.py", line 145, in get_template
template, origin = find_template(template_name)
File "/home/user/.virtualenvs/virtenv/local/lib/python2.7/site-packages/django/template/loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: TestTemplate1
I am using the dbtemplates loader first in line so that it gets checked before the filesystem.
TEMPLATE_LOADERS = (
'dbtemplates.loader.Loader',
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
And have dbtemplates in INSTALLED_APPS:
INSTALLED_APPS = [
...
# django-dbtemplates
'dbtemplates',
]
For what its worth, I'm on Ubuntu 12.04 with apt-get upgraded everything , python 2.7.3, operating in a virtualenv which I completely deleted and re-built this morning to test. This same code was working 2 weeks ago.
Not sure if this "belongs" to dbtemplates or south...but the presence of the "migrations" directory in the package as installed by pip prevents syncdb from installing the tables, forcing the use of south, or using this hack to make south "fail" and defer to syncdb:
http://lincolnloop.com/blog/disabling-south-migrations/
South blows a tire when it hits db.delete_unique('django_template', ['name']) in the second migration in dbtemplates using MySQL. Is this constraint really necessary to remove?
(app)[user@web313 src]$ python manage.py migrate
Running migrations for dbtemplates:
- Migrating forwards to 0002_auto__del_unique_template_name.
> dbtemplates:0002_auto__del_unique_template_name
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = ALTER TABLE `django_template` ADD CONSTRAINT `django_template_name_uniq` UNIQUE (`name`) []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/__init__.py", line 191, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 221, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 292, in migrate_many
result = self.migrate(migration, database)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 125, in migrate
result = self.run(migration)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 99, in run
return self.run_migration(migration)
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration
migration_function()
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/home/user/.virtualenvs/app/src/django-dbtemplates/dbtemplates/migrations/0002_auto__del_unique_template_name.py", line 12, in forwards
db.delete_unique('django_template', ['name'])
File "/home/user/.virtualenvs/app/lib/python2.7/site-packages/south/db/generic.py", line 479, in delete_unique
raise ValueError("Cannot find a UNIQUE constraint on table %s, columns %r" % (table_name, columns))
ValueError: Cannot find a UNIQUE constraint on table django_template, columns ['name']
0002_auto__del_unique_template_name.py
migration raises warnings in tests:
Creating test database for alias 'default'...
! WARNING: SQLite does not support adding unique constraints. Ignored.
! WARNING: SQLite does not support removing unique constraints. Ignored.
This means that contrary to Template
model definition, template names must be unique in tests.
The current site is added correctly via the post_save
signal and the tests are working fine for Template creation and updating via the shell, but when saved via a ModelForm (for example through the Django admin), instance.sites
gets cleared shortly after again in form.save_m2m
.
This behaviour is analogous to what's described in Django Ticket 14649.
Hi,
Thanks for dbtemplates, I'm looking forward to trying it. I'm running Django==1.9.7, and having trouble setting up this module. When I try to set it up, I get the error:
ImportError: cannot import name 'get_cache'
I think this is fixed in the new version, but not on the one in PyPI (version 1.3). Can you push the latest version to PyPI.
Also, is there any way to cancel cacheing altogether?
Thanks
Full traceback: http://paste.pocoo.org/show/433265/
(14:39:00) jezdez: das muss settings.DBTEMPLATES_CACHE_BACKEND sein
Just installed and reading this:
http://django-dbtemplates.readthedocs.org/en/latest/overview/
I just did a syncdb and I'm getting this error:
django.core.exceptions.ImproperlyConfigured: Please specify a dbtemplates cache backend in your settings.
Does the docs need to be updated to reflect this, or am I not following the instructions closely enough?
Thanks.
Hi,
The version check in dbtemplates/loader.py is not working for Django 1.10, causing "ImportError: cannot import name BaseLoader"
Currently, it's:
if django.get_version() >= '1.8':
from django.template.loaders.base import Loader as tLoaderCls
else:
from django.template.loader import BaseLoader as tLoaderCls # noqa
This could be fixed by something like the following:
from distutils.version import StrictVersion
if StrictVersion(django.get_version()) >= StrictVersion('1.8'):
from django.template.loaders.base import Loader as tLoaderCls
else:
from django.template.loader import BaseLoader as tLoaderCls # noqa
After install the package (version 1.2.1) with pip and set it on INSTALLED_APPS, trying to make the 'python manage.py syncdb' I got that error "AttributeError: 'NoneType' object has no attribute 'find'". This is the complete Traceback:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/dbtemplates/models.py", line 13, in <module>
from dbtemplates.utils.cache import add_template_to_cache, remove_cached_template
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/dbtemplates/utils/cache.py", line 11, in <module>
cache = get_cache_backend()
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/dbtemplates/utils/cache.py", line 9, in get_cache_backend
return get_cache(settings.DBTEMPLATES_CACHE_BACKEND)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/cache/__init__.py", line 64, in get_cache
scheme, host, params = parse_backend_uri(backend_uri)
File "/home/oscar/Web/Django/DJBlog/env/lib/python2.6/site-packages/django/core/cache/__init__.py", line 45, in parse_backend_uri
if backend_uri.find(':') == -1:
AttributeError: 'NoneType' object has no attribute 'find'
I've been using this module on my recent projects and I'd like to help it.
Hi,
is there any reason not to put the dbtemplates.loader before the file system loader if I want to load a template if present in the DB?
Do you plan to fix this issue?:
I am on Django 1.2.3 and get this error when leaving the content empty:
Found a compiled template that is incompatible with the deprecated django.template.loaders.find_template_source
function.
It is the same issue as found here:
cheers
Hi,
I have been seeing this exception
[23/Oct/2010 22:31:15] "GET /media/img/site/hdr.jpg HTTP/1.1" 304 0
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.KeyError'> ignored
[23/Oct/2010 22:32:50] "GET /dbabout/ HTTP/1.1" 200 3126
When I try to access pages that use dbtemplates, I can't figure out where exactly this exception comes from. When I render the same page with a file template I don't see this exception.
Any thoughts?
Best regards
Meitham
Here an example taken from a settings.py that works.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ # your template dirs
],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
'loaders': [
'dbtemplates.loader.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
Hi,
the app is not usable anymore:
It throws TypeError
init() takes exactly 2 arguments (1 given)
/django/template/loader.py in init, line 155
Please: Add a link to github.com/jezdez/django-dbtemplates in the docs and pypi page.
I get this error when I want to extend my admin/base.html
template. It works properly when dbtemplates.loader.Loader
is not in the TEMPLATES
settings, but when it is (even if I try to load a template that is not from the database), I get this error:
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.11.5
Python Version: 3.6.3
Installed Applications:
['myproject',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'collectfaster',
'django.contrib.staticfiles',
'django.contrib.humanize',
'jet',
'django.contrib.admin',
'smuggler',
'raven.contrib.django.raven_compat',
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
'colorfield',
'dbtemplates',
'django_premailer',
'algoliasearch_django',
'push_notifications',
'schedule',
'django_filters',
'django_user_agents']
Installed Middleware:
['raven.contrib.django.middleware.SentryMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_user_agents.middleware.UserAgentMiddleware']
Template error:
In template /myproject/templates/admin/base.html, error at line 1
Cannot extend templates recursively when using non-recursive template loaders 1 : {% extends "admin/base.html" %}
2 :
3 :
4 : {% block content %}
5 :
6 : {{ block.super }}
Traceback:
File "/myproject/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/myproject/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
217. response = self.process_exception_by_middleware(e, request)
File "/myproject/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
215. response = response.render()
File "/myproject/lib/python3.6/site-packages/django/template/response.py" in render
107. self.content = self.rendered_content
File "/myproject/lib/python3.6/site-packages/django/template/response.py" in rendered_content
84. content = template.render(context, self._request)
File "/myproject/lib/python3.6/site-packages/django/template/backends/django.py" in render
66. return self.template.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render
207. return self._render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in _render
199. return self.nodelist.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render
990. bit = node.render_annotated(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render_annotated
957. return self.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/loader_tags.py" in render
177. return compiled_parent._render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in _render
199. return self.nodelist.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render
990. bit = node.render_annotated(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render_annotated
957. return self.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/loader_tags.py" in render
177. return compiled_parent._render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in _render
199. return self.nodelist.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render
990. bit = node.render_annotated(context)
File "/myproject/lib/python3.6/site-packages/django/template/base.py" in render_annotated
957. return self.render(context)
File "/myproject/lib/python3.6/site-packages/django/template/loader_tags.py" in render
154. compiled_parent = self.get_parent(context)
File "/myproject/lib/python3.6/site-packages/django/template/loader_tags.py" in get_parent
151. return self.find_template(parent, context)
File "/myproject/lib/python3.6/site-packages/django/template/loader_tags.py" in find_template
120. "Cannot extend templates recursively when using "
Exception Type: ExtendsError at /admin/
Exception Value: Cannot extend templates recursively when using non-recursive template loaders
I am not familiar with template loaders but I can help if needed. I think the issue comes from these lines. And to enable this parameter the get_contents()
method on the loader needs to be implemented (as per this).
LMK if I can help more.
If this feature doesn't exist it would be super handy to have.
{% include 'path/to/dbtemplate-example.html' %}
last version available on pypi is 2.0,
Is this still being maintained by JazzBand?
I'm interested in using this project, but it doesn't seem that many recent PRs have been merged and it hasn't had a PyPI release since last year.
I think that writing templates in textarea is pain. There is two possibilities:
Using rich text editor can cause many problems and you will not have control over the code. The best solution is source code editor. The only one JavaScript code editor supported by dbtemplates is CodeMirror. We can enable it by default. If some people doesn't use static files we can modify documentation how to make it to work without staticfiles app or how to disable it if they don't want it.
@jezdez has some concerns about usefulness of CodeMirror. If anybody has issues with it can share it and we can see if it is possible (and easy) to fix. If this CodeMirror has too many problems another one can be chosen. Suggestions are welcome.
I'm using python 3.4.1
together with django 1.9.4
and while i'm executing the following command
pip install django-dbtemplates
i get this weird error message:
Collecting django-dbtemplates
Using cached django-dbtemplates-1.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-j7vzt90r/django-dbtemplates/setup.py", line 22, in <module>
version=find_version('dbtemplates', '__init__.py'),
File "/tmp/pip-build-j7vzt90r/django-dbtemplates/setup.py", line 14, in find_version
version_file, re.M)
File "/home/fechnert/projects/salt-observer/env/lib64/python3.4/re.py", line 166, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-j7vzt90r/django-dbtemplates/
Can someone of you help me out?
Hi. Please remove my push access to this repository, I don't plan to commit into it.
A deprecation warning occurs with a current Django version:
[โฆ]/local/lib/python2.7/site-packages/dbtemplates/admin.py:72:
RemovedInDjango18Warning:
Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated
form TemplateAdminForm needs updating
in django 2.2 from django.utils.six import input as raw_input fails with a traceback like:
./manage.py sync_templates
Traceback (most recent call last):
File "/venv/lib/python3.7/site-packages/dbtemplates/management/commands/sync_templates.py", line 83, in handle
[...]
File "/venv/lib/python3.7/site-packages/dbtemplates/management/commands/sync_templates.py", line 86, in handle
confirm = raw_input(
NameError: name 'raw_input' is not defined
it could be replaced with from django.utils.six.moves import input as raw_input
, but as six has been thrown out in django upstream, it might make sense to throw it out completely (which will later also require changes in
django-dbtemplates/dbtemplates/models.py
Line 11 in f5b9e36
I'm receiving a TypeError when I try to run sync_templates.
# ./manage.py sync_templates
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/dbtemplates/management/commands/sync_templates.py", line 70, in handle
tpl_dirs = DIRS + app_template_dirs
TypeError: can only concatenate list (not "tuple") to list
if app_first:
tpl_dirs = app_template_dirs + DIRS
else:
tpl_dirs = DIRS + app_template_dirs #THIS LINE IS THE ERROR LINE
Both of the variables used (DIRS and app_templates) are automatically generateed, and the error can be subverted by casting app_template_dirs to a list. That being said, i'd rather tackle the root cause.
Do you have any suggestions for how I should approach this?
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 273, in __call__
response = self.get_response(request)
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/www/wsgi/qraz.at/urls.py", line 11, in <module>
admin.autodiscover()
File "/usr/lib/pymodules/python2.6/django/contrib/admin/__init__.py", line 26, in autodiscover
import_module('%s.admin' % app)
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/python2.6/dist-packages/dbtemplates/admin.py", line 7, in <module>
from dbtemplates import settings
File "/usr/lib/python2.6/dist-packages/dbtemplates/settings.py", line 12, in <module>
elif cache.startswith("dbtemplates."):
AttributeError: 'dict' object has no attribute 'startswith'
With the following setup, auto-populating a database template (saving with empty content) does not work; the content is empty after all.
TEMPLATE_LOADERS = (
'dbtemplates.loader.Loader',
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
The rationale behind this configuration is to retrieve templates from the database, if they are present (because they might need to be changed frequently). And load all filesystem based templates (that are also in version control) from the cache (which gets updated on app restarts only).
Seems that the TEMPLATE_LOADERS backwards incompatible change from 'dbtemplates.loader.load_template_source' to 'dbtemplates.loader.Loader' is not documented in changelog, isn't it?
This this was the change:
2804cd5#dbtemplates/loader.py
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
Hi,
I didn't see this mentioned in the docs, but after I got dbtemplates setup and I pulled in a few .html templates, I couldn't get changes to display without deleting the original .html templates.
Is there a setting to read from db first then look for the file?
If not, I think it could be handy since the app encourages populating dbtemplate from files. If it then ignores the db because the files exist, the app doesn't work out of the box without steps to then remove the original files.
Still, this is a very slick app for my customers who want to edit templates themselves.
Thanks,
Shige
Is threre anywhere information about with django version dbtemplates support?
using django 2.2 on python 3.7.3, expading the help text with %default fails with a traceback like:
./manage.py sync_templates --help
Traceback (most recent call last):
File "./manage.py", line 21, in <module>
main()
[...]
File "/usr/local/lib/python3.7/argparse.py", line 525, in _format_action
help_text = self._expand_help(action)
File "/usr/local/lib/python3.7/argparse.py", line 614, in _expand_help
return self._get_help_string(action) % params
TypeError: %d format: a number is required, not dict
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.