Commit 1d73974e authored by Serge S. Koval's avatar Serge S. Koval

Renamed SQLa fields

parent bd18251e
......@@ -145,7 +145,7 @@ class ModelView(BaseModelView):
if field_class == mongoengine.EmbeddedDocumentField:
continue
if self.list_display_pk or field_class != mongoengine.ObjectIdField:
if self.column_display_pk or field_class != mongoengine.ObjectIdField:
columns.append(n)
return columns
......@@ -158,7 +158,7 @@ class ModelView(BaseModelView):
for n, f in self._get_model_fields():
if type(f) in SORTABLE_FIELDS:
if self.list_display_pk or type(f) != mongoengine.ObjectIdField:
if self.column_display_pk or type(f) != mongoengine.ObjectIdField:
columns[n] = f
return columns
......@@ -232,7 +232,7 @@ class ModelView(BaseModelView):
form_class = model_form(self.model,
base_class=BaseForm,
only=self.form_columns,
exclude=self.excluded_form_columns,
exclude=self.form_excluded_columns,
field_args=self.form_args,
converter=self.model_form_converter())
......
......@@ -131,8 +131,8 @@ class InlineModelConverter(InlineModelConverterBase):
# Remove reverse property from the list
ignore = [reverse_field.name]
if info.excluded_form_columns:
exclude = ignore + info.excluded_form_columns
if info.form_excluded_columns:
exclude = ignore + info.form_excluded_columns
else:
exclude = ignore
......
......@@ -135,7 +135,7 @@ class ModelView(BaseModelView):
if field_class == ForeignKeyField:
columns.append(n)
elif self.list_display_pk or field_class != PrimaryKeyField:
elif self.column_display_pk or field_class != PrimaryKeyField:
columns.append(n)
return columns
......@@ -144,7 +144,7 @@ class ModelView(BaseModelView):
columns = dict()
for n, f in self._get_model_fields():
if self.list_display_pk or type(f) != PrimaryKeyField:
if self.column_display_pk or type(f) != PrimaryKeyField:
columns[n] = f
return columns
......@@ -200,7 +200,7 @@ class ModelView(BaseModelView):
form_class = model_form(self.model,
base_class=form.BaseForm,
only=self.form_columns,
exclude=self.excluded_form_columns,
exclude=self.form_excluded_columns,
field_args=self.form_args,
converter=self.model_form_converter())
......
......@@ -76,7 +76,7 @@ class AdminModelConverter(ModelConverterBase):
**kwargs)
elif prop.direction.name == 'ONETOMANY':
# Skip backrefs
if not local_column.foreign_keys and getattr(self.view, 'hide_backrefs', False):
if not local_column.foreign_keys and getattr(self.view, 'column_hide_backrefs', False):
return None
return QuerySelectMultipleField(
......@@ -412,8 +412,8 @@ class InlineModelConverter(InlineModelConverterBase):
# Remove reverse property from the list
ignore = [reverse_prop.key]
if info.excluded_form_columns:
exclude = ignore + info.excluded_form_columns
if info.form_excluded_columns:
exclude = ignore + info.form_excluded_columns
else:
exclude = ignore
......
......@@ -25,12 +25,16 @@ class ModelView(BaseModelView):
admin.add_view(ModelView(User, db.session))
"""
hide_backrefs = True
column_hide_backrefs = ObsoleteAttr('column_hide_backrefs',
'hide_backrefs',
True)
"""
Set this to False if you want to see multiselect for model backrefs.
"""
auto_select_related = True
column_auto_select_related = ObsoleteAttr('column_auto_select_related',
'auto_select_related',
True)
"""
Enable automatic detection of displayed foreign keys in this view
and perform automatic joined loading for related models to improve
......@@ -41,25 +45,29 @@ class ModelView(BaseModelView):
will still make separate database call.
"""
list_select_related = None
column_select_related = ObsoleteAttr('column_select_related',
'list_select_related',
None)
"""
List of parameters for SQLAlchemy `subqueryload`. Overrides `auto_select_related`
List of parameters for SQLAlchemy `subqueryload`. Overrides `column_auto_select_related`
property.
For example::
class PostAdmin(ModelAdmin):
list_select_related = ('user', 'city')
column_select_related = ('user', 'city')
You can also use properties::
class PostAdmin(ModelAdmin):
list_select_related = (Post.user, Post.city)
column_select_related = (Post.user, Post.city)
Please refer to the `subqueryload` on list of possible values.
"""
list_display_all_relations = False
column_display_all_relations = ObsoleteAttr('column_display_all_relations',
'list_display_all_relations',
False)
"""
Controls if list view should display all relations, not only many-to-one.
"""
......@@ -221,10 +229,10 @@ class ModelView(BaseModelView):
raise Exception('Model %s does not have primary key.' % self.model.__name__)
# Configuration
if not self.list_select_related:
if not self.column_select_related:
self._auto_joins = self.scaffold_auto_joins()
else:
self._auto_joins = self.list_select_related
self._auto_joins = self.column_select_related
# Internal API
def _get_model_iterator(self, model=None):
......@@ -258,7 +266,7 @@ class ModelView(BaseModelView):
for p in self._get_model_iterator():
# Verify type
if hasattr(p, 'direction'):
if self.list_display_all_relations or p.direction.name == 'MANYTOONE':
if self.column_display_all_relations or p.direction.name == 'MANYTOONE':
columns.append(p.key)
elif hasattr(p, 'columns'):
# TODO: Check for multiple columns
......@@ -267,7 +275,7 @@ class ModelView(BaseModelView):
if column.foreign_keys:
continue
if not self.list_display_pk and column.primary_key:
if not self.column_display_pk and column.primary_key:
continue
columns.append(p.key)
......@@ -295,7 +303,7 @@ class ModelView(BaseModelView):
if column.foreign_keys:
continue
if not self.list_display_pk and column.primary_key:
if not self.column_display_pk and column.primary_key:
continue
columns[p.key] = column
......@@ -435,7 +443,7 @@ class ModelView(BaseModelView):
converter = self.model_form_converter(self.session, self)
form_class = form.get_form(self.model, converter,
only=self.form_columns,
exclude=self.excluded_form_columns,
exclude=self.form_excluded_columns,
field_args=self.form_args)
if self.inline_models:
......@@ -466,6 +474,9 @@ class ModelView(BaseModelView):
Return list of joined tables by going through the
displayed columns.
"""
if not self.column_auto_select_related:
return []
relations = set()
for p in self._get_model_iterator():
......
......@@ -180,7 +180,9 @@ class BaseModelView(BaseView, ActionsMixin):
column_filters = ('user', 'email')
"""
list_display_pk = False
column_display_pk = ObsoleteAttr('column_display_pk',
'list_display_pk',
False)
"""
Controls if primary key should be displayed in list view.
"""
......@@ -222,14 +224,16 @@ class BaseModelView(BaseView, ActionsMixin):
form_columns = ('name', 'email')
"""
excluded_form_columns = None
form_excluded_columns = ObsoleteAttr('form_excluded_columns',
'excluded_form_columns',
None)
"""
Collection of excluded form field names.
For example::
class MyModelView(BaseModelView):
excluded_form_columns = ('last_name', 'email')
form_excluded_columns = ('last_name', 'email')
"""
form_overrides = None
......@@ -243,13 +247,15 @@ class BaseModelView(BaseView, ActionsMixin):
"""
# Actions
disallowed_actions = []
action_disallowed_list = ObsoleteAttr('action_disallowed_list',
'disallowed_actions',
[])
"""
Set of disallowed action names. For example, if you want to disable
mass model deletion, do something like this:
class MyModelView(BaseModelView):
disallowed_actions = ['delete']
action_disallowed_list = ['delete']
"""
# Various settings
......@@ -732,9 +738,9 @@ class BaseModelView(BaseView, ActionsMixin):
on some condition.
Default implementation only checks if particular action
is not in `disallowed_actions`.
is not in `action_disallowed_list`.
"""
return name not in self.disallowed_actions
return name not in self.action_disallowed_list
@contextfunction
def get_list_value(self, context, model, name):
......
......@@ -20,7 +20,7 @@ class InlineFormAdmin(object):
class MyUserInfoForm(InlineFormAdmin):
form_columns = ('name', 'email')
"""
_defaults = ['form_columns', 'excluded_form_columns', 'form_args']
_defaults = ['form_columns', 'form_excluded_columns', 'form_args']
def __init__(self, model, **kwargs):
"""
......
......@@ -317,7 +317,7 @@ def test_non_int_pk():
def test_form():
# TODO: form_columns
# TODO: excluded_form_columns
# TODO: form_excluded_columns
# TODO: form_args
# TODO: Select columns
pass
......
......@@ -289,7 +289,7 @@ def test_column_filters():
def test_form():
# TODO: form_columns
# TODO: excluded_form_columns
# TODO: form_excluded_columns
# TODO: form_args
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment