Skip to content

Commit

Permalink
surface verbose_name in config
Browse files Browse the repository at this point in the history
(for use with @wq/react; see wq/wq#41)
  • Loading branch information
sheppard committed Sep 2, 2020
1 parent bebe4b5 commit 78dab96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions rest/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def get_class(self, classes, model_class, default=lambda model: None):
return classes[real_model]
else:
if real_model not in self._config:
# FIXME: Probably can just use default instead of erroring
raise ImproperlyConfigured(
"%s is not registered!" % real_model
)
Expand Down
24 changes: 14 additions & 10 deletions rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,20 @@ def get_wq_config(self):

config = getattr(self.Meta, 'wq_config', {}).copy()
config['form'] = fields + nested_fields
if 'name' not in config:
config['name'] = self.Meta.model._meta.model_name
if has_geo_fields and 'map' not in config:
config['map'] = True
if 'label_template' not in config:
label_template = getattr(
self.Meta.model, 'wq_label_template', None
)
if label_template:
config['label_template'] = label_template

meta = self.Meta.model._meta
config.setdefault('name', meta.model_name)
config.setdefault('verbose_name', meta.verbose_name)
config.setdefault('verbose_name_plural', meta.verbose_name_plural)

if has_geo_fields:
config.setdefault('map', True)

label_template = getattr(
self.Meta.model, 'wq_label_template', None
)
if label_template:
config.setdefault('label_template', label_template)
return config

def get_wq_field_info(self, name, field, model=None):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def test_rest_index_json(self):
self.assertIn("list", result["pages"][0])
self.assertNotIn("list", result["pages"][-1])

def test_rest_config_meta(self):
conf = self.get_config('item')
self.assertEqual({
'name': 'item',
'url': 'items',
'list': True,
'cache': 'none',
'form': conf['form'],
'label_template': '{{name}}',
'verbose_name': 'item',
'verbose_name_plural': 'items'
}, conf)

def test_rest_config_json_fields(self):
self.assertEqual([
{
Expand Down

0 comments on commit 78dab96

Please sign in to comment.