Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to change destination for underscore js media #90

Closed
GregUK opened this issue Jan 8, 2015 · 7 comments
Closed

Add ability to change destination for underscore js media #90

GregUK opened this issue Jan 8, 2015 · 7 comments

Comments

@GregUK
Copy link

GregUK commented Jan 8, 2015

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
Copy link
Member

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
Copy link
Author

GregUK commented Jan 8, 2015

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
Copy link
Member

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

@GregUK
Copy link
Author

GregUK commented Jan 8, 2015

How would you recommend approaching it?

@nemesifier
Copy link
Member

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
Copy link
Author

GregUK commented Jan 8, 2015

I'll update accordingly

GregUK pushed a commit to GregUK/django-hstore that referenced this issue Jan 8, 2015
@nemesifier
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants