ckeditor: Cannot set property 'dir' of undefined (django + zinnia) - django

I am experiencing this strange error only on my production environment. It works fine locally and on staging.
I'm using Django==1.10.5 & django-blog-zinnia==0.18.1 with zinnia-wysiwyg-ckeditor==1.3. I believe this issue happened recently when we upgraded from Django==1.8 to the latest.
When I try to create a blog entry, I can't edit the content because the ckeditor instance does not load. The errors are:
https://example.com/admin/zinnia/entry/81/change/config.js/change/ 404 (Not Found)
https://example.com/admin/zinnia/entry/81/change/lang/en.js/change/
GET https://example.com/admin/zinnia/entry/81/change/skins/moono-lisa/editor.css/change/
Uncaught TypeError: Cannot set property 'dir' of undefined
The URL is /admin/zinnia/entry/81/change/
So this very much looks like ckeditor.js is trying to load additional static files based on the current URLs and somehow it injects the filenames into the current URL.
As a workaround, I ssh-ed into the server and manipulated /static/ckeditor/ckeditor/ckeditor.8bd276b5ef4c.js and added this line at the very top:
window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';
This solves the issue. The big question is: Why does this only happen on one of my machines, why does Django/zinnia not set CKEDITOR_BASEPATH correctly by itself?
I'm posting this here because I am not sure if this is an issue in Django, zinnia or zinnia-ckeditor, if anyone got insights on who is guilty, I'm happy to re-post this issue on the relevant issue tracker on github.
EDIT:
As a workaround, in my project I created the file templates/admin/change_form.html:
{% extends "admin/change_form.html" %}
{% block extrahead %}
<script>window.CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/';</script>
{{ block.super }}
{% endblock %}

Related

why is adding a base template breaking my django forms [duplicate]

This question already has an answer here:
Using a Django template_tag on pages that extend from the view that loads the tag
(1 answer)
Closed 6 years ago.
I'm making a website with django and rest framework and I found myself copying and pasting a lot of the same code on every page. I learned about creating a base.html and adding {% extends 'app/base.html' %} from http://tutorial.djangogirls.org/en/template_extending/. This worked great for most of my pages but I am having issues with 2 pages that have different forms (but I get the same error for all the forms). The error is:
TemplateSyntaxError at /boards/: Invalid filter: 'attr'
error during template rendering in template boards.html, error at line 30
I am confused because when I get rid of the {% extends 'app/base.html' %} and just copy the head of base.html into this other page, it works fine. The headers of the 2 are identical but something within the forms breaks when I try to use the base template. Its kind of a lot of code to include so I'm not going to include it unless requested. But hopefully someone has an idea of what the issue could be without seeing my code?
I guess it may be relevant to include that I am using django-widget-tweaks with my forms. I'm not sure if that is at all related to the problem.
Turns out the issue was actually with django-widget-tweaks! I had {% load i18n widget_tweaks %} only in base.html but I also had to add it to the individual pages (I am still not really sure why, but it worked). So each template that extends base.html and that has a form on it looks like:
{% extends 'app/base.html' %}
{% load i18n widget_tweaks %}
{% block content %}
....
{% endblock %}
Apparently just loading widget tweaks in the base doesn't cut it, see the comments for why not.

sphinx overrided template block not recognized

I'm attempting to add a link to an icon I used to the footer of my doc page, but I can't seem to figure out how to copy this link. I'm following this tutorial but haven't had any luck. I've created a file _templates/layout.html:
{% extends "!layout.html" %}
{% block footer %}
<li>CC BY 3.0</li>
{{ super() }}
{% endblock %}
then in my conf.py I do
templates_path = ['_templates']
# ...
html_theme = 'sphinx_rtd_theme'
The problem is that when I build, nothing extra shows up in the footer of my page. I initially thought sphinx just wasn't finding my file, but if I change {% extends "!layout.html" %} to {% extends "layout.html" %} I get the error
Running Sphinx v1.3.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 30 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
preparing documents... done
writing output... [ 3%] dev/conventions
Exception occurred:
File "C:\...\Anaconda\lib\site-packages\jinja2\utils.py", line 389,
in __getitem__
if self._queue[-1] != key:
RuntimeError: maximum recursion depth exceeded in cmp
The full traceback has been saved in c:\...\appdata\local\temp\1\sphi
nx-err-tjhk_m.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message c
an be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphin
x/issues>. Thanks!
So I know sphinx see's my file, but it doesn't seem to write anything. What am I doing wrong?
The issue I ended up having was I was overwriting the wrong file, while layout.html did implement a footer block, it was not the block I was looking to add to. Instead sphinx_rtd_theme has a footer.html file, which I ended up overwriting instead and everything worked as intended.

Django-compressor not working after first compress statement

I have a website with various js files, and i'm using django-compressor like so:
{% compress js %}
{% endcompress %}
{% compress js %}
{% endcompress %}
For some reason its only creating the FIRST js file. I have my app hosted on an EC2. I can see the first file there. The second file appears when I do a view source on the page, however, the file itself doens't exist (I get a 404 when I click on the link to the second js file). Is there anything I'm doing wrong? I have my settings as per below:
COMPRESS_ENABLED = not DEBUG
COMPRESS_PARSER = 'compressor.parser.BeautifulSoupParser'
COMPRESS_CSS_FILTERS = ['compressor.filters.cssmin.CSSMinFilter']
COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
It's working perfectly for css files...but failing on any other js file after the first compress flag...
I honestly have no idea what happened. this used to work perfectly, but randomly stopped out of no where! I did the following and it worked:
python manage.py compress --force
This basically forces it to compress all files; normally django-compressor ignores files that have not changed and have been compressed already.

{% url %} gives me NoReverseMatch error while reverse() returns the url just fine. Why?

I don't know if this SO question is of the same problem that I am about to describe, but it does share the same symptoms. Unfortunately, it still remains unresolved as I am writing.
So here is my problem. I am trying to add James Bennett's django-registration app to my django project. I have pretty much finished configuring it to my needs - custom templates and urls. Just when I thought everything was good to go. I got NoReverseMatch error from using {% url 'testing' item_id=123 %} (I also tried using the view name, myapp.views.test, instead but no luck) in one of the custom templates required by django-registration. Interestingly, I tried reverse('testing', kwargs={'item_id':123}) in the shell and the url was returned just fine. I thought {% url %} uses reverse() in the back-end but why did I get different outcomes?
urls.py: (the URLconf of my site)
urlpatterns = patterns('myapp.views',
url(r'^test/(?P<item_id>\d+)/$', 'test', name='testing'),
)
activation_email.txt: (the said template. Note it's intentionally in .txt extension as required by django-registration and that shouldn't be the cause of the problem.)
{% comment %}Used to generate the body of the activation email.{% endcomment %}
Welcome to {{ site }}! Please activate your account by clicking on the following link:
{% url 'testing' item_id=123 %}
Note the activation link/code will be expired in {{ expiration_days }} days.
I don't know if it matters but just thought I should mention activation_email.txt is stored in the templates directory of myapp though it is used by django-registration.
Also, I am using django 1.4
I have a feeling that the problem has something to do with the url namespaces, a topic that I have never understood, but it's just a naive guess. (IMO, the django documentation is great in explaining everything about django, except when it comes to url namespaces)
I'm no expert here, but in a Django project I'm working on at the moment I use the name of the url without quotes. I just added quotes around a similar line in one of my templates and it produced the same error as your error.
Try:
{% url testing item_id=123 %}

Django: Photologue does not show images in templates

I am trying to install django-photologue. Everything seems ok, because I install and set up following the official guidelines. I have to upload some photos as examples. However, when viewing a photo or gallery details , then an error as follows:
Caught an exception while rendering: 'Photo' object has no attribute 'get_thumbnail_url'
I tried to remove the following code from the file photo_detail.html
{% if object.public_galleries %}
<h2>This photo is found in the following galleries:</h2>
<ol>
{% for gallery in object.public_galleries %}
<li>{%previous_in_gallery object gallery%} {{ gallery.title }} {%next_in_gallery object gallery%}</li>
{% endfor %}
</ol>
{% endif %}
No more errors, but pictures do not show up. If you click on the link will still lead to correct photographs to see. I think the problem in:
{{ object.get_display_url }}
It is totally not return any value.
Please help me solve this problem. Thanks!
Did you run python manage.py plinit after install and opt to create both a thumbnail and display photosize? These photosizes need to be defined in your database.
In other versions, you have to edit photologue/templates/photolog/tags/next_in_gallery.html and replace
{{ photo.get_thumbnail_url }}
with
{{ photo.thumbnail.url }}
Same for photologue/templates/photolog/tags/prev_in_gallery.html.
Honestly from looking at the source, it looks like a bug in the project. If you search the source, thumbnail doesn't seem to be a field within the Photo class (get_FIELD_url is an easy way to access an ImageField's url btw.) So I would recommend tinkering with the source or finding another project. I might be wrong though but that's what my ~5 minute scan of the project found.