django-knowledge icon indicating copy to clipboard operation
django-knowledge copied to clipboard

Docs refer to non-existant KNOWLEDGE_BASE_TEMPLATE setting

Open sbisker opened this issue 11 years ago • 11 comments

We've been customizing the style of django-knowledge and were looking forward to using the KNOWLEDGE_BASE_TEMPLATE setting to avoid having to drop a custom build of all of django-knowledge into our source base. However, the KNOWLEDGE_BASE_TEMPLATE setting seems to be absent from the source. Is this a setting that is in development, and the docs are too new? Or is this a depreciated setting and the docs need to be scrubbed? Thanks.

sbisker avatar Mar 06 '13 20:03 sbisker

I was also curious about this. The docs say that you just need to copy and modify the base.html into your own template folder.. but that isn't any good if the app is just using the default ones. @sbisker, did you happen to find a solution to this without dropping a custom build into your base?

Gabrinthei avatar Jul 08 '13 17:07 Gabrinthei

I am also having this issue. This setting does exist, but doesn't seem to work. Look at the settings file line 18:

BASE_TEMPLATE = getattr(settings, 'KNOWLEDGE_BASE_TEMPLATE', 'django_knowledge/base.html')

However, it doesn't seem to have any effect when you make the change in your local settings.py.

Here is a simple test, using Django's built in shell command from your projects root directory:

% python manage.py shell
>>> from knowledge.settings import *
>>> print LOGIN_REQUIRED
False
>>> print LOGIN_URL
/path/to/my/local/custom/auth/login
>>> print BASE_TEMPLATE
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'BASE_TEMPLATE' is not defined

As you can see, all of the others work, except BASE_TEMPLATE.

robnewman avatar Sep 24 '13 21:09 robnewman

Okay, I have found the issue. I assume both of you installed from pip just like I did? Well, here is the contents of knowledge/settings.py as installed by pip:

from django.conf import settings

# crowd control
LOGIN_REQUIRED = getattr(settings, 'KNOWLEDGE_LOGIN_REQUIRED', False)
LOGIN_URL = getattr(settings, 'LOGIN_URL', '/accounts/login/')
ALLOW_ANONYMOUS = getattr(settings, 'KNOWLEDGE_ALLOW_ANONYMOUS', False)
AUTO_PUBLICIZE = getattr(settings, 'KNOWLEDGE_AUTO_PUBLICIZE', False)
FREE_RESPONSE = getattr(settings, 'KNOWLEDGE_FREE_RESPONSE', True)

# alerts
ALERTS = getattr(settings, 'KNOWLEDGE_ALERTS', False)
ALERTS_FUNCTION_PATH = getattr(settings, 'KNOWLEDGE_ALERTS_FUNCTION_PATH',
    'knowledge.signals.send_alerts')

# misc
SLUG_URLS = getattr(settings, 'KNOWLEDGE_SLUG_URLS', True)

Notice something missing? Yup. No

BASE_TEMPLATE = getattr(settings, 'KNOWLEDGE_BASE_TEMPLATE', 'django_knowledge/base.html')

It looks like even though the author recommends using the stable release via pip, that DOES NOT have the custom template. Sloppy. You might like to clone the Git repo instead. That's what I am going to do. Good luck.

robnewman avatar Sep 24 '13 21:09 robnewman

After updating from Github directly:

pip install -e git+https://github.com/zapier/django-knowledge.git#egg=django-knowledge

This now works:

% python manage.py shell
>>> from django.conf import settings
>>> from knowledge.settings import *
>>> print BASE_TEMPLATE
django_knowledge/base.html

Like I said before... sloppy.

robnewman avatar Sep 24 '13 21:09 robnewman

We haven't pushed the recent updates to PyPi yet.

bryanhelmig avatar Sep 25 '13 00:09 bryanhelmig

Then (with respect as you are providing this for free, and thank you) you should really make a note of this on the readthedocs page at a minimum. Its pretty much a deal breaker for me, and probably other devs, if they can't apply their own chrome/skin to the app.

robnewman avatar Sep 25 '13 16:09 robnewman

Valid point, we definitely should. I'd be happy to accept a pull request that addresses some of this, as I can't devote time to cleaning up django-knowledge in the near short-term... :frowning:

bryanhelmig avatar Sep 25 '13 19:09 bryanhelmig

That is also a valid point (that you can't devote time), and I am aware that open-source sometimes means extra 'features'. If I get time I will try and address some of this issues. Regards.

robnewman avatar Sep 26 '13 15:09 robnewman

One final comment on this. This project also assumes that your custom templates live in the global space under: mysite/mysite/templates/, as shown in the current Django docs.

For large Django projects the standard is to create per application template directories. So, if you have installed django-knowledge and want to have your own templates, you need to either put your custom knowledge templates under mysite/mysite/templates/django_knowledge, or hack your settings.py file to point to your own custom app templates.

I did the latter as I have a very large Django project, and to make it work with my custom templates I had to create my own app knowledge with it's own templates directory. To make it work via my settings.py here is what I did:

if 'knowledge' in INSTALLED_APPS:
    # Ugly hack. If we install django-knowledge via pip it is
    # installed under site_packages, and the templates therein are used.
    # However, we want to override this with our own templates, but not in
    # the projects global templates directory due to keeping a clean house.
    # So need to define a path that Django's built in
    # Template Loaders can find. Use relative paths.
    TEMPLATE_DIRS += (PROJECT_PATH + '/../knowledge/templates',)
    KNOWLEDGE_BASE_TEMPLATE = 'django_knowledge/base.html'

This is ugly, but it works.

robnewman avatar Sep 26 '13 18:09 robnewman

Thanks for the feedback and insight, I definitely appreciate it! Hopefully I'll get a rainy afternoon sometime and give our open source stuff some love and attention. :smile:

bryanhelmig avatar Sep 26 '13 19:09 bryanhelmig

Sorry, was traveling in Japan, so very late to this. :) Agreed that this fix needs to make its way upstream, but we wound up simply cloning the repo for now.

sbisker avatar Sep 30 '13 16:09 sbisker