feat: make CRUD annotations inline (#9888)

* feat: make CRUD annotations inline

This makes the annotations inline of the "annotation layers". Originally
they were setup as separate ModelViews because of a bug in FAB.

* fix pylint
This commit is contained in:
Maxime Beauchemin
2020-06-02 23:12:37 -07:00
committed by GitHub
parent 1001c6d5f4
commit 209392e9ef
2 changed files with 14 additions and 23 deletions

View File

@@ -198,15 +198,6 @@ class SupersetAppInitializer:
category_label=__("Manage"),
category_icon="",
)
appbuilder.add_view(
AnnotationModelView,
"Annotations",
label=__("Annotations"),
icon="fa-comments",
category="Manage",
category_label=__("Manage"),
category_icon="",
)
appbuilder.add_view(
DatabaseView,
"Databases",
@@ -288,6 +279,7 @@ class SupersetAppInitializer:
appbuilder.add_view_no_menu(SliceAsync)
appbuilder.add_view_no_menu(SqlLab)
appbuilder.add_view_no_menu(SqlMetricInlineView)
appbuilder.add_view_no_menu(AnnotationModelView)
appbuilder.add_view_no_menu(Superset)
appbuilder.add_view_no_menu(TableColumnInlineView)
appbuilder.add_view_no_menu(TableModelView)

View File

@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from flask_appbuilder import CompactCRUDMixin
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_babel import lazy_gettext as _
from wtforms.validators import StopValidation
@@ -21,7 +22,7 @@ from wtforms.validators import StopValidation
from superset.constants import RouteMethod
from superset.models.annotations import Annotation, AnnotationLayer
from .base import DeleteMixin, SupersetModelView
from .base import SupersetModelView
class StartEndDttmValidator: # pylint: disable=too-few-public-methods
@@ -43,17 +44,17 @@ class StartEndDttmValidator: # pylint: disable=too-few-public-methods
class AnnotationModelView(
SupersetModelView, DeleteMixin
SupersetModelView, CompactCRUDMixin
): # pylint: disable=too-many-ancestors
datamodel = SQLAInterface(Annotation)
include_route_methods = RouteMethod.CRUD_SET
list_title = _("List Annotation")
list_title = _("Annotations")
show_title = _("Show Annotation")
add_title = _("Add Annotation")
edit_title = _("Edit Annotation")
list_columns = ["layer", "short_descr", "start_dttm", "end_dttm"]
list_columns = ["short_descr", "start_dttm", "end_dttm"]
edit_columns = [
"layer",
"short_descr",
@@ -67,10 +68,10 @@ class AnnotationModelView(
label_columns = {
"layer": _("Layer"),
"short_descr": _("Short Descr"),
"start_dttm": _("Start Dttm"),
"end_dttm": _("End Dttm"),
"long_descr": _("Long Descr"),
"short_descr": _("Label"),
"long_descr": _("Description"),
"start_dttm": _("Start"),
"end_dttm": _("End"),
"json_metadata": _("JSON Metadata"),
}
@@ -91,18 +92,16 @@ class AnnotationModelView(
self.pre_add(item)
class AnnotationLayerModelView(
SupersetModelView, DeleteMixin
): # pylint: disable=too-many-ancestors
class AnnotationLayerModelView(SupersetModelView): # pylint: disable=too-many-ancestors
datamodel = SQLAInterface(AnnotationLayer)
include_route_methods = RouteMethod.CRUD_SET | {RouteMethod.API_READ}
list_title = _("List Annotation Layer")
related_views = [AnnotationModelView]
list_title = _("Annotation Layers")
show_title = _("Show Annotation Layer")
add_title = _("Add Annotation Layer")
edit_title = _("Edit Annotation Layer")
list_columns = ["id", "name"]
list_columns = ["name", "descr"]
edit_columns = ["name", "descr"]
add_columns = edit_columns