forked from schlunsen/django-geoposition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how settings are organized internalls. Remove django-appconf. …
…Change Google Maps API key setting name.
- Loading branch information
1 parent
feaaa78
commit cf9862e
Showing
6 changed files
with
37 additions
and
16 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
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,12 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf import settings | ||
from appconf import AppConf | ||
from django.conf import settings as django_settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
class GeopositionConf(AppConf): | ||
MAP_WIDGET_HEIGHT = 480 | ||
MAP_OPTIONS = {} | ||
MARKER_OPTIONS = {} | ||
class AppSettings(object): | ||
defaults = { | ||
'MAP_WIDGET_HEIGHT': 480, | ||
'MAP_OPTIONS': {}, | ||
'MARKER_OPTIONS': {}, | ||
'GOOGLE_MAPS_API_KEY': None, | ||
} | ||
prefix = 'GEOPOSITION' | ||
required_settings = ['GOOGLE_MAPS_API_KEY'] | ||
|
||
class Meta: | ||
prefix = 'geoposition' | ||
def __init__(self, django_settings): | ||
self.django_settings = django_settings | ||
|
||
for setting in self.required_settings: | ||
prefixed_name = '%s_%s' % (self.prefix, setting) | ||
if not hasattr(self.django_settings, prefixed_name): | ||
raise ImproperlyConfigured("The '%s' setting is required." % prefixed_name) | ||
|
||
def __getattr__(self, name): | ||
prefixed_name = '%s_%s' % (self.prefix, name) | ||
if hasattr(django_settings, prefixed_name): | ||
return getattr(django_settings, prefixed_name) | ||
if name in self.defaults: | ||
return self.defaults[name] | ||
raise AttributeError("'AppSettings' object does not have a '%s' attribute" % name) | ||
|
||
|
||
settings = AppSettings(django_settings) |
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 |
---|---|---|
|
@@ -47,3 +47,4 @@ | |
|
||
|
||
GEOPOSITION_MAP_WIDGET_HEIGHT = 500 | ||
GEOPOSITION_GOOGLE_MAPS_API_KEY = 'DUMMY' |
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