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

Renamed SQLa fields

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