mirror of
https://github.com/apache/superset.git
synced 2026-04-13 13:18:25 +00:00
* Allow id as a valid name for pylint * Re-enable pylint for superset/models/core.py * re-enable pylint for superset/models/sql_lab.py * re-enable pylint for superset/models/schedules.py * re-enable pylint for superset/models/helpers.py * re-enable pylint for superset/models/annotations.py * re-enable pylint on superset/models/tags.py * a couple more fixes after black formatting... * Add another inline pylint disable * Fix black * Move to inline disables for 'id' attribute on models * Fix lint disables after black reformatted them
95 lines
3.0 KiB
Python
95 lines
3.0 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
"""Models for scheduled execution of jobs"""
|
|
|
|
import enum
|
|
|
|
from flask_appbuilder import Model
|
|
from sqlalchemy import Boolean, Column, Enum, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.ext.declarative import declared_attr
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from superset import security_manager
|
|
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
|
|
|
metadata = Model.metadata # pylint: disable=no-member
|
|
|
|
|
|
class ScheduleType(enum.Enum):
|
|
slice = "slice"
|
|
dashboard = "dashboard"
|
|
|
|
|
|
class EmailDeliveryType(enum.Enum):
|
|
attachment = "Attachment"
|
|
inline = "Inline"
|
|
|
|
|
|
class SliceEmailReportFormat(enum.Enum):
|
|
visualization = "Visualization"
|
|
data = "Raw data"
|
|
|
|
|
|
class EmailSchedule:
|
|
|
|
"""Schedules for emailing slices / dashboards"""
|
|
|
|
__tablename__ = "email_schedules"
|
|
|
|
id = Column(Integer, primary_key=True) # pylint: disable=invalid-name
|
|
active = Column(Boolean, default=True, index=True)
|
|
crontab = Column(String(50))
|
|
|
|
@declared_attr
|
|
def user_id(self):
|
|
return Column(Integer, ForeignKey("ab_user.id"))
|
|
|
|
@declared_attr
|
|
def user(self):
|
|
return relationship(
|
|
security_manager.user_model,
|
|
backref=self.__tablename__,
|
|
foreign_keys=[self.user_id],
|
|
)
|
|
|
|
recipients = Column(Text)
|
|
deliver_as_group = Column(Boolean, default=False)
|
|
delivery_type = Column(Enum(EmailDeliveryType))
|
|
|
|
|
|
class DashboardEmailSchedule(Model, AuditMixinNullable, ImportMixin, EmailSchedule):
|
|
__tablename__ = "dashboard_email_schedules"
|
|
dashboard_id = Column(Integer, ForeignKey("dashboards.id"))
|
|
dashboard = relationship(
|
|
"Dashboard", backref="email_schedules", foreign_keys=[dashboard_id]
|
|
)
|
|
|
|
|
|
class SliceEmailSchedule(Model, AuditMixinNullable, ImportMixin, EmailSchedule):
|
|
__tablename__ = "slice_email_schedules"
|
|
slice_id = Column(Integer, ForeignKey("slices.id"))
|
|
slice = relationship("Slice", backref="email_schedules", foreign_keys=[slice_id])
|
|
email_format = Column(Enum(SliceEmailReportFormat))
|
|
|
|
|
|
def get_scheduler_model(report_type):
|
|
if report_type == ScheduleType.dashboard.value:
|
|
return DashboardEmailSchedule
|
|
elif report_type == ScheduleType.slice.value:
|
|
return SliceEmailSchedule
|
|
return None
|