djangonauts / django-hstore

PostgreSQL HStore support for Django.
http://django-hstore.readthedocs.io/
Other
517 stars 142 forks source link

Add ability to change destination for underscore js media #90

Closed GregUK closed 9 years ago

GregUK commented 9 years ago

django_hstore/widgets.py

There is hardcoded external_js to cloudflare. Should be able to easily override to use internal CDN f required or other source.

class BaseAdminHStoreWidget(AdminTextareaWidget):
    """
    Base admin widget class for default-admin and grappelli-admin widgets
    """
    admin_style = 'default'
    @property
    def media(self):
    # load underscore from CDNJS (popular javascript content delivery network)
    external_js = [
    "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"
    ]
    internal_js = [
    "django_hstore/hstore-widget.js"
    ]
nemesifier commented 9 years ago

I think it would be ok to store underscore locally instead of loading from the CDN, if you or anyone sends a PR with this little modification I'll accept it.

GregUK commented 9 years ago

The approach I was planning to use was to check the settings and set a default if it doesnt exist. such as:

from django.conf import settings
...
internal_js = [
       getattr(settings, 'UNDERSCORE_JS_PATH', "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"
]
nemesifier commented 9 years ago

why complicating your life when django.contrib.static does a great job at handling static files?

GregUK commented 9 years ago

How would you recommend approaching it?

nemesifier commented 9 years ago

The standard practice in django apps is to ship JS files inside the static/ dir, which then are collected automatically when one runs manage.py collectstatic.

if we want to retain the possibility to load from CDN we could add do something like:

    if(getattr(settings, 'DJANGO_HSTORE_UNDERSCOREJS_CDN', False)):
        underscorejs = "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js
    else:
        underscorejs = "django_hstore/underscore-min.js"
GregUK commented 9 years ago

I'll update accordingly

nemesifier commented 9 years ago

This was merged and released in 1.3.6, see #91 for more info