You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by su...@apache.org on 2021/02/26 00:13:00 UTC
[superset] 01/02: refactor out id_or_slug filter logic
This is an automated email from the ASF dual-hosted git repository.
suddjian pushed a commit to branch get-dashboard-by-slug
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 8ab7a38436a0dc32aa467041a7466cf64a262819
Author: David Aaron Suddjian <aa...@gmail.com>
AuthorDate: Thu Feb 25 08:19:56 2021 -0800
refactor out id_or_slug filter logic
---
superset/models/dashboard.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/superset/models/dashboard.py b/superset/models/dashboard.py
index f827cd4..76b30ad 100644
--- a/superset/models/dashboard.py
+++ b/superset/models/dashboard.py
@@ -42,6 +42,7 @@ from sqlalchemy.orm import relationship, sessionmaker, subqueryload
from sqlalchemy.orm.mapper import Mapper
from sqlalchemy.orm.session import object_session
from sqlalchemy.sql import join, select
+from sqlalchemy.sql.elements import BinaryExpression
from superset import app, ConnectorRegistry, db, is_feature_enabled, security_manager
from superset.connectors.base.models import BaseDatasource
@@ -359,14 +360,16 @@ class Dashboard( # pylint: disable=too-many-instance-attributes
)
@classmethod
- def get(cls, id_or_slug: str) -> Dashboard:
- session = db.session()
- qry = session.query(Dashboard)
+ def id_or_slug_filter(cls, id_or_slug: str) -> BinaryExpression:
if id_or_slug.isdigit():
- qry = qry.filter_by(id=int(id_or_slug))
+ return Dashboard.id == int(id_or_slug)
else:
- qry = qry.filter_by(slug=id_or_slug)
+ return Dashboard.slug == id_or_slug
+ @classmethod
+ def get(cls, id_or_slug: str) -> Dashboard:
+ session = db.session()
+ qry = session.query(Dashboard).filter(Dashboard.id_or_slug_filter(id_or_slug))
return qry.one_or_none()