Admin: opt in for models
Table,
)
from iommi.base import items
-from iommi.from_model import get_fields
from iommi.traversable import reinvokable
model_by_app_and_name = {
for model_name, model in items(models)
}
+joined_app_name_and_model = {f'{app_name}_{model_name}' for app_name, model_name in model_by_app_and_name.keys()}
+
def require_login(view):
@wraps(view)
@@ -81,7 +82,8 @@ class Admin(Page):
class Meta:
table_class = Table
form_class = Form
- apps__sessions_session__include = False
+ apps__auth_user__include = True
+ apps__auth_group__include = True
parts__messages = Messages()
parts__list_auth_user__columns__password__include = False
@@ -95,7 +97,11 @@ class Meta:
apps=EMPTY,
parts=EMPTY,
)
- def __init__(self, parts, **kwargs):
+ def __init__(self, parts, apps, **kwargs):
+ # Validate apps params
+ for k in apps.keys():
+ assert k in joined_app_name_and_model, joined_app_name_and_model
+
def should_throw_away(k, v):
if isinstance(v, Namespace) and 'call_target' in v:
return False
@@ -121,7 +127,7 @@ def should_throw_away(k, v):
for k, v in items(parts)
}
- super(Admin, self).__init__(parts=parts, **kwargs)
+ super(Admin, self).__init__(parts=parts, apps=apps, **kwargs)
@staticmethod
def has_permission(request, operation, model=None, instance=None):
@@ -145,7 +151,7 @@ def preprocess_rows(admin, rows, **_):
return [
row
for row in rows
- if admin.apps.get(f'{row.app_name}_{row.model_name}', {}).get('include', True)
+ if admin.apps.get(f'{row.app_name}_{row.model_name}', {}).get('include', False)
]
table = setdefaults_path(
@@ -155,14 +161,14 @@ def preprocess_rows(admin, rows, **_):
call_target__cls=cls.get_meta().table_class,
sortable=False,
rows=[
- Struct(app_name=app_name, model_name=model_name, model=model)
+ Struct(app_name=app_name, name=model._meta.verbose_name, model_name=model_name, model=model)
for (app_name, model_name), model in items(model_by_app_and_name)
],
preprocess_rows=preprocess_rows,
columns=dict(
app_name__auto_rowspan=True,
app_name__after=0,
- model_name__cell__url=lambda row, **_: '%s/%s/' % (row.app_name, row.model_name),
+ name__cell__url=lambda row, **_: '%s/%s/' % (row.app_name, row.model_name),
),
)
@@ -208,11 +214,6 @@ def list(cls, request, app_name, model_name, table, call_target=None, **kwargs):
),
query_from_indexes=True,
bulk__actions__delete__include=True,
- **{
- 'columns__' + field.name + '__bulk__include': True
- for field in get_fields(model)
- if not getattr(field, 'unique', False)
- },
)
return call_target(
