-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this change to modify the address javascript you had to fork and edit the `address.js` manually. This change let to define a setting dict to customize the address.js. e.g. ``` ADDRESS_SETTINGS = { 'country': ['AU'], } ``` it will be injected in the address.js to limit the address to the australian country. To achieve that I move the address.js from a static file to a templateview and threat the address.js file as a django template. The TemplateView is responsible to retrieve the settings and generate the context for the template. There is a requirement to make django-address works now. The url must be added in your project: e.g. ``` urlpatterns = [ # ... other urls path('address/', include('address.urls')), ] ```
- Loading branch information
Showing
10 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
7 changes: 5 additions & 2 deletions
7
address/static/address/js/address.js → address/templates/address/address.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
|
||
from .views import AddressJS | ||
|
||
urlpatterns = [ | ||
path('address.js', AddressJS.as_view(), name="address.js"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import json | ||
from django.views.generic import TemplateView | ||
from django.conf import settings | ||
|
||
|
||
class AddressJS(TemplateView): | ||
content_type = "text/javascript" | ||
template_name = "address/address.js" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data() | ||
address_settings = getattr(settings, "ADDRESS_SETTINGS", {}) | ||
context["address_settings"] = json.dumps(address_settings) | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from django.contrib import admin | ||
from django.urls import path | ||
from django.urls import path, include | ||
|
||
from person import views as person | ||
from person import views as person_views | ||
from address import views as address_views | ||
from address import urls as address_urls | ||
|
||
urlpatterns = [ | ||
path('', person.home, name='home'), | ||
path('', person_views.home, name='home'), | ||
path('admin/', admin.site.urls), | ||
path('address/', include('address.urls')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters