Open JustDevZero opened 3 years ago
In order to replace sass_src
against their compiled counterparts, django-sass-processor has to parse all templates. If Django's internal template parser finds something it can't understand, it complains with the above errors.
You can ignore them.
However, maybe a little investigation on your templates might give you a reason, why that happens. Does this make sense?
Well, django template parser can normall understand this through templatetags... But somehow any custom templatetag is being ignored here.
OK, basically it looks like Django doesn't like to use database on templatetags. Even it works...
Is your database up, running and is migrated, before you invoke ./manage compilescss
?
Yup, it is.
But if i try to put an ipdb into the templatetag it doesn't get triggered.
On the other hand if I try to change from a @register.simple_tag to @register.tag it gets indeed triggered (but of course don't worry because normal tags work a lot different)
Maybe the code will need to be changed after all...
Ok, finally figure out how to solve my problem, for anyone interested:
from sass_processor.templatetags.sass_tags import SassSrcNode
class CustomSassProcessor(SassProcessor):
def resolve_path(self, context=None):
from resources.models import SiteConfiguration
from resources.models import ThemesModel
from django.conf import settings
if context is None:
context = Context()
path = self._path.resolve(context)
conf = SiteConfiguration.get_solo()
rh = ThemesModel.get_solo().refresh_hash
if not conf.customer_id:
return '%s' % path
static_root, static_file = path.rsplit('/', 1)
static_file = static_file.split('.')[0]
for item in settings.SASS_PROCESSOR_INCLUDE_DIRS:
full_static_route = '%s/%s/%s_%s_%s.scss' % (item, static_root, conf.customer_id, static_file, rh)
if os.path.isfile(full_static_route):
return '%s/%s_%s_%s.scss' % (static_root, conf.customer_id, static_file, rh)
return '%s' % path
class CustomSassSrc(SassSrcNode):
def __init__(self, path):
self.sass_processor = CustomSassProcessor(path)
@register.tag(name='custom_sass_src')
def render_sass_src(parser, token):
return CustomSassSrc.handle_token(parser, token)
Maybe it's not the best way, but with this I can I achieve what i needed, having the scss replaced by the different colored versions.
And then, I just call directly custom_sass_src instead of a mix of sass_src and something else.
This issue bugs me a bit. The output is huge in my case:
Invalid template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/categories/templates/admin/edit_inline/gen_coll_tabular.html: No named cycles in template. 'row1,row2' is not defined
Error parsing template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/admin_tools/dashboard/templates/admin_tools/dashboard/dummy.html: Invalid template name in 'extends' tag: ''. Got this from the 'template' variable.
Invalid template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/nested_admin/templates/nesting/admin/includes/grappelli_inline.html: Invalid filter: 'prettylabel'
Error parsing template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/admin_tools/menu/templates/admin_tools/menu/dummy.html: Invalid template name in 'extends' tag: ''. Got this from the 'template' variable.
Error parsing template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/wagtail/admin/templates/wagtailadmin/bulk_actions/confirmation/form_with_fields.html: home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/wagtail/admin/templates/wagtailadmin/bulk_actions/confirmation/form.html
Invalid template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/django_filters/templates/django_filters/rest_framework/crispy_form.html: 'crispy_forms_tags' is not a registered tag library. Must be one of:
admin_chart_tags
...(many lines with all the tags)...
yandex_metrica
Error parsing template /home/petr/.cache/pypoetry/virtualenvs/blenderkit-server-eqrfB9dY-py3.10/lib/python3.10/site-packages/adminsortable2/templates/adminsortable2/change_list.html: Invalid template name in 'extends' tag: ''. Got this from the 'original_change_list_template' variable.
I think there were some cases in the past where the compilescss
command did help me to identify some error in the templates.
But these errors are just false alarms by third libraries that I even can't fix.
Wouldn't it be possible to blacklist those templates as they don't contain sass_src
tags?
This is because sass-processor makes a static code analysis including templates.
In the worst case, the templatetag sass_processor
is not found in one of the extended or included templates.
This can be fixed by adding that template folder to the SASS_PROCESSOR_INCLUDE_DIRS
.
When I try to run compilescss it just explodes with a bunch of errors, i'm trying to add an ipdb in order to find where it's exploding but i ind in a almost endless loop in walk_nodes method.
The content using the sass_src is like this on the first one:
Where custom_sass_src basically builds a different, given some data on the database.
But then, it also happends the " 'NoneType' object has no attribute 'engine'" error on files that even had no sass_src tag.