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

Middleware support #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion javascript_settings/configuration_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ def fetch(self):
pass
return configuration

def get_configuration(self):
def get_configuration(self, **kwargs):
if self.configuration is None:
self.configuration = self.fetch()

self.configuration.update(kwargs)

return self.configuration

DEFAULT_CONFIGURATION_BUILDER = ConfigurationBuilder()
Expand Down
4 changes: 2 additions & 2 deletions javascript_settings/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.utils import simplejson
import json

from configuration_builder import DEFAULT_CONFIGURATION_BUILDER


def get_config(request):
return {
'javascript_settings': simplejson.dumps(
'javascript_settings': json.dumps(
DEFAULT_CONFIGURATION_BUILDER.get_configuration()
)
}
7 changes: 4 additions & 3 deletions javascript_settings/templatetags/javascript_settings_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import template
from django.utils import simplejson
import json

from javascript_settings.configuration_builder import \
DEFAULT_CONFIGURATION_BUILDER
Expand All @@ -26,6 +26,7 @@ def render(self, context):
"""
Renders JS configuration.
"""
return 'var configuration = ' + simplejson.dumps(
DEFAULT_CONFIGURATION_BUILDER.get_configuration()
jssettings = getattr(context.get('request'), 'javascript_settings', {})
return 'var configuration = ' + json.dumps(
DEFAULT_CONFIGURATION_BUILDER.get_configuration(**jssettings)
) + ';'
4 changes: 2 additions & 2 deletions javascript_settings/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.http import HttpResponse
from django.utils import simplejson
import json

from configuration_builder import DEFAULT_CONFIGURATION_BUILDER


def load_configuration(request):
return HttpResponse(
"var configuration = %s;" % simplejson.dumps(
"var configuration = %s;" % json.dumps(
DEFAULT_CONFIGURATION_BUILDER.get_configuration()
)
)