-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from eldarion/add-hookset
Add hookset support
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import importlib | ||
|
||
from django.conf import settings # noqa | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from appconf import AppConf | ||
|
||
|
||
def load_path_attr(path): | ||
i = path.rfind(".") | ||
module, attr = path[:i], path[i + 1:] | ||
try: | ||
mod = importlib.import_module(module) | ||
except ImportError as e: | ||
raise ImproperlyConfigured("Error importing {0}: '{1}'".format(module, e)) | ||
try: | ||
attr = getattr(mod, attr) | ||
except AttributeError: | ||
raise ImproperlyConfigured("Module '{0}' does not define a '{1}'".format(module, attr)) | ||
return attr | ||
|
||
|
||
class FormlyAppConf(AppConf): | ||
|
||
HOOKSET = "formly.hooks.FormlyDefaultHookset" | ||
|
||
def configure_hookset(self, value): | ||
return load_path_attr(value)() |
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,20 @@ | ||
class FormlyDefaultHookset(object): | ||
|
||
@property | ||
def field_type_choices(self): | ||
""" | ||
Customize available field type choices when designing a survey | ||
default: Field.FIELD_TYPE_CHOICES | ||
""" | ||
from formly.models import Field | ||
return Field.FIELD_TYPE_CHOICES | ||
|
||
|
||
class HookProxy(object): | ||
|
||
def __getattr__(self, attr): | ||
from formly.conf import settings | ||
return getattr(settings.FORMLY_HOOKSET, attr) | ||
|
||
|
||
hookset = HookProxy() |
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