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

application initialization/configuration #9

Open
Midnighter opened this issue Aug 29, 2014 · 0 comments
Open

application initialization/configuration #9

Midnighter opened this issue Aug 29, 2014 · 0 comments

Comments

@Midnighter
Copy link

I would like to propose two enhancements (and can make a PR if you want). This is tied to the configuration values.

Currently, the init_app method looks like this:

def init_app(self, app):
    app.before_request(self._on_before_request)
    static_path = app.config.get('SIJAX_STATIC_PATH', None)
    if static_path is not None:
        sijax.helper.init_static_path(static_path)
    self._json_uri = app.config.get('SIJAX_JSON_URI', None)
    app.extensions = getattr(app, 'extensions', {})
    app.extensions['sijax'] = self

I would change it to this:

def init_app(self, app):
    app.before_request(self._on_before_request)
    static_path = app.config.get('SIJAX_STATIC_PATH', None)
    if static_path is not None:
        if not os.path.isabs(static_path):
            static_path = os.path.join(app.static_folder, static_path)
        sijax.helper.init_static_path(static_path)
    json_uri = app.config.get('SIJAX_JSON_URI', None)
    if not json_uri.startswith("/"):
        json_uri = "{}/{}".format(app.static_url_path, json_uri)
    self._json_uri = json_uri
    app.extensions = getattr(app, 'extensions', {})
    app.extensions['sijax'] = self

Which uses the app's configured path and URL for the static folder if the Sijax config values are relative. Should make things more robust if you simply want to use the static folder that you set up for the application anyway. The configuration would then simply become:

SIJAX_STATIC_PATH = "js/sijax"
SIJAX_JSON_URI = "js/sijax/json2.js"

What do you think?

If the json2.js is actually inside the application's static folder, you could also use the following in the HTML templates. Instead of:

<script type="text/javascript">
    {{ g.sijax.get_js()|safe }}
</script>

use:

<script type="text/javascript">
    {{ url_for('static', 'js/sijax/json2.js') }}
</script>

What actually happens when sijax.helper.init_static_path never gets called?

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

1 participant