示例#1
0
class RoleSchema(SQLAlchemySchema):
    """Role item schema"""
    class Meta:
        """Meta"""

        model = Role

    name = auto_field()
    permissions = fields.List(fields.Nested(ActionResourceSchema),
                              data_key='actions')
示例#2
0
class UserCollectionItemSchema(SQLAlchemySchema):
    """user collection item schema"""
    class Meta:
        """Meta"""

        model = User
        dateformat = "iso"

    first_name = auto_field()
    last_name = auto_field()
    username = auto_field()
    active = auto_field(dump_only=True)
    email = auto_field()
    last_login = auto_field(dump_only=True)
    login_count = auto_field(dump_only=True)
    fail_login_count = auto_field(dump_only=True)
    roles = fields.List(fields.Nested(RoleSchema, only=('name', )))
    created_on = auto_field(validate=validate_istimezone, dump_only=True)
    changed_on = auto_field(validate=validate_istimezone, dump_only=True)
示例#3
0
文件: log.py 项目: tanj/log-it
class LogFullFixture(FixtureSchema):
    class Meta(FixtureSchema.Meta):
        model = TLog
        filter_attrs = ["sLog"]

    sLog = auto_field()
    user = Nested(UserFixture, many=False)
    fields = Nested(FieldFixture, many=True)
    user_permissions = Nested(UserPermissionFixture)
    role_permissions = Nested(RolePermissionFixture)
示例#4
0
class TickerSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Ticker
        render_module = simplejson

    currency_code = fields.String(validate=validate_currency)
    currency_rate = fields.Decimal(validate=validate_decimal)
    amount_requested = fields.Decimal(validate=validate_decimal)
    final_amount = fields.Decimal(validate=validate_decimal)
    created_at = auto_field(dump_only=True)
示例#5
0
class TargetSchema(SQLAlchemyAutoSchema):
    class Meta(BaseSchema.Meta):
        model = db_models.Target
        exclude = ()
        unknown = EXCLUDE  # todo: sort this out

    # It's possible to define defaults here. However, default here would require aditional default functions, as None is
    # considered valid value by Marshmallow does not trigger default/missing.
    protocol = EnumField(sslyze.ssl_settings.TlsWrappedProtocolEnum)
    id = auto_field(dump_only=True)
示例#6
0
class PoolSchema(SQLAlchemySchema):
    """Pool schema"""
    class Meta:
        """Meta"""

        model = Pool
        load_instance = True
        exclude = ("pool", )

    name = auto_field("pool")
    slots = auto_field()
    occupied_slots = fields.Method("get_occupied_slots", dump_only=True)
    running_slots = fields.Method("get_running_slots", dump_only=True)
    queued_slots = fields.Method("get_queued_slots", dump_only=True)
    open_slots = fields.Method("get_open_slots", dump_only=True)

    @staticmethod
    def get_occupied_slots(obj: Pool) -> int:
        """
        Returns the occupied slots of the pool.
        """
        return obj.occupied_slots()

    @staticmethod
    def get_running_slots(obj: Pool) -> int:
        """
        Returns the running slots of the pool.
        """
        return obj.running_slots()

    @staticmethod
    def get_queued_slots(obj: Pool) -> int:
        """
        Returns the queued slots of the pool.
        """
        return obj.queued_slots()

    @staticmethod
    def get_open_slots(obj: Pool) -> int:
        """
        Returns the open slots of the pool.
        """
        return obj.open_slots()
class ImageFileSchema(SQLAlchemySchema):
    """
    image file model schema
    """
    class Meta:
        """
        meta class
        """
        model = ImageFile
        load_instance = True
        sqla_session = db.session

    id = auto_field()
    created = auto_field()
    name = fields.String(required=True)
    file_path = fields.String(load_only=True)
    url = fields.Function(
        lambda obj: os.path.join(current_app.config['HOST'], current_app.
                                 config['STATIC_URL'], obj.file_path))
示例#8
0
class EpisodeSchema(SQLAlchemySchema):
    class Meta:
        model = Episode
        load_instance = True

    id = auto_field()
    show_id = auto_field()
    share_link = auto_field()
    iframe = auto_field()
    title = auto_field()
    description = auto_field()
    image = auto_field()
    tracklist = auto_field()
class ContactSchema(SQLAlchemySchema):
    class Meta:
        model = Contact
        load_instance = True

    contact_id = auto_field()
    project_id = auto_field()
    name = auto_field()
    link = auto_field()
    checked = auto_field()
    in_contact = auto_field()
    notes = auto_field()
    active = auto_field()
class InventorySchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Inventory
        include_fk = True
        exclude = ['value_of_materials']

    value_of_materials = auto_field(dump_only=True)

    # Override materials field to use a nested representation rather than pks
    material = Nested(lambda: MaterialSchema(), dump_only=True)
    place = Nested(lambda: PlaceSchema(), dump_only=True)
示例#11
0
class BandForm(SQLAlchemyAutoSchema):
    """Represent the BDC-Catalog Band model."""

    collection_id = auto_field()

    class Meta:
        """Internal meta information of form interface."""

        model = Band
        sqla_session = db.session
        exclude = []
示例#12
0
class BoundLimitSchema(SQLAlchemySchema):
    id = auto_field()
    limit_id = auto_field()
    user_id = auto_field()
    user_group_id = auto_field()
    scheduler_partition_id = auto_field()
    refresh_period_days = auto_field()
    priority = auto_field()
    is_default = auto_field()
    is_active = auto_field()

    class Meta:
        model = BoundLimit
        load_instance = True
        include_relationships = True

    limit_item = fields.Nested(LimitItemSchema)
示例#13
0
class UserSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = User
        sqla_session = db.session
        load_instance = True

    password = auto_field(load_only=True)
    languages = fields.Nested(UserXLanguageSchema, many=True, exclude=("id",))
    emergency_contacts = fields.Nested(EmergencyContactSchema, many=True, exclude=('id',))

    reviews_of_me = fields.Nested(ReviewSchema, many=True)
    reviews_by_me = fields.Nested(ReviewSchema, many=True)
示例#14
0
class CertificateChainSchemaWithoutCertificates(SQLAlchemyAutoSchema):
    class Meta(BaseSchema.Meta):
        model = db_models.CertificateChain
        exclude = ()

    id = auto_field(dump_only=True)

    chain_arr = fields.Method("chain_to_propper_arr", dump_only=True)

    @staticmethod
    def chain_to_propper_arr(obj):
        return app.utils.db.basic.split_array_to_tuple(obj.chain)
示例#15
0
class DAGSchema(SQLAlchemySchema):
    """DAG schema"""

    class Meta:
        """Meta"""

        model = DagModel

    dag_id = auto_field(dump_only=True)
    root_dag_id = auto_field(dump_only=True)
    is_paused = auto_field()
    is_subdag = auto_field(dump_only=True)
    fileloc = auto_field(dump_only=True)
    owners = fields.Method("get_owners", dump_only=True)
    description = auto_field(dump_only=True)
    schedule_interval = fields.Nested(ScheduleIntervalSchema)
    tags = fields.List(fields.Nested(DagTagSchema), dump_only=True)

    @staticmethod
    def get_owners(obj: DagModel):
        """Convert owners attribute to DAG representation"""

        if not getattr(obj, 'owners', None):
            return []
        return obj.owners.split(",")
示例#16
0
class DAGRunSchema(SQLAlchemySchema):
    """Schema for DAGRun"""

    class Meta:
        """Meta"""

        model = DagRun
        dateformat = "iso"

    run_id = auto_field(data_key='dag_run_id')
    dag_id = auto_field(dump_only=True)
    execution_date = auto_field(validate=validate_istimezone)
    start_date = auto_field(dump_only=True)
    end_date = auto_field(dump_only=True)
    state = DagStateField(dump_only=True)
    external_trigger = auto_field(default=True, dump_only=True)
    conf = ConfObject()

    @pre_load
    def autogenerate(self, data, **kwargs):
        """Auto generate run_id and execution_date if they are not loaded"""
        if "execution_date" not in data.keys():
            data["execution_date"] = str(timezone.utcnow())
        if "dag_run_id" not in data.keys():
            try:
                data["dag_run_id"] = DagRun.generate_run_id(
                    DagRunType.MANUAL, timezone.parse(data["execution_date"])
                )
            except (ParserError, TypeError) as err:
                raise BadRequest("Incorrect datetime argument", detail=str(err))
        return data
示例#17
0
class DAGSchema(SQLAlchemySchema):
    """DAG schema"""
    class Meta:
        """Meta"""

        model = DagModel

    dag_id = auto_field(dump_only=True)
    root_dag_id = auto_field(dump_only=True)
    is_paused = auto_field()
    is_subdag = auto_field(dump_only=True)
    fileloc = auto_field(dump_only=True)
    file_token = fields.Method("get_token", dump_only=True)
    owners = fields.Method("get_owners", dump_only=True)
    description = auto_field(dump_only=True)
    schedule_interval = fields.Nested(ScheduleIntervalSchema)
    tags = fields.List(fields.Nested(DagTagSchema), dump_only=True)

    @staticmethod
    def get_owners(obj: DagModel):
        """Convert owners attribute to DAG representation"""
        if not getattr(obj, 'owners', None):
            return []
        return obj.owners.split(",")

    @staticmethod
    def get_token(obj: DagModel):
        """Return file token"""
        serializer = URLSafeSerializer(conf.get('webserver', 'secret_key'))
        return serializer.dumps(obj.fileloc)
示例#18
0
class EventLogSchema(SQLAlchemySchema):
    """Event log schema"""
    class Meta:
        """Meta"""
        model = Log

    id = auto_field(data_key='event_log_id', dump_only=True)
    dttm = auto_field(data_key='when', dump_only=True)
    dag_id = auto_field(dump_only=True)
    task_id = auto_field(dump_only=True)
    event = auto_field(dump_only=True)
    execution_date = auto_field(dump_only=True)
    owner = auto_field(dump_only=True)
    extra = auto_field(dump_only=True)
示例#19
0
class DAGRunSchema(SQLAlchemySchema):
    """
    Schema for DAGRun
    """

    class Meta:
        """Meta"""

        model = DagRun
        dateformat = "iso"

    run_id = auto_field(data_key='dag_run_id')
    dag_id = auto_field(dump_only=True)
    execution_date = auto_field()
    start_date = auto_field(dump_only=True)
    end_date = auto_field(dump_only=True)
    state = DagStateField(dump_only=True)
    external_trigger = auto_field(default=True, dump_only=True)
    conf = ConfObject()

    @pre_load
    def autogenerate(self, data, **kwargs):
        """
        Auto generate run_id and execution_date if they are not loaded
        """
        if "execution_date" not in data.keys():
            data["execution_date"] = str(timezone.utcnow())
        if "dag_run_id" not in data.keys():
            data["dag_run_id"] = DagRun.generate_run_id(
                DagRunType.MANUAL, timezone.parse(data["execution_date"])
            )
        return data
示例#20
0
class TourSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Tour
        load_instance = True
        sqla_session = db.session

    uuid = fields.UUID(dump_only=True)
    upload_time = auto_field(dump_only=True)
    duration = fields.TimeDelta(precision='minutes')
    location = fields.Nested(Location)
    category = EnumField(TourCategory)
    guide = fields.Nested(UserSchema)
    reviews = fields.Nested(ReviewSchema, many=True)
示例#21
0
文件: template.py 项目: pbehnke/doku
class StylesheetSchema(DokuSchema, DateSchemaMixin, ApiSchemaMixin):
    class Meta:
        model = Stylesheet
        exclude = ("base_templates", "templates")
        load_instance = True

    API_NAME = "template"

    id = auto_field()
    name = auto_field()
    source = auto_field()
    base_templates = Nested("TemplateSchema",
                            exclude=("base_style", ),
                            many=True)
    templates = Nested("TemplateSchema", exclude=("styles", ), many=True)

    upload_url = fields.Method("_upload_url", dump_only=True, allow_none=True)

    def _upload_url(self, stylesheet) -> Optional[str]:
        if stylesheet.id is None:
            return None
        return url_for("api.v1.stylesheet.upload", stylesheet_id=stylesheet.id)
示例#22
0
class LocationSchema(SQLAlchemySchema):
    class Meta:
        model = Location

    id = auto_field()
    device_id = auto_field()
    recorded_at = auto_field()
    location_type = auto_field()
    longitude = auto_field()
    latitude = auto_field()
    altitude = auto_field()
示例#23
0
class BulkInvoiceSchema(SQLAlchemySchema):
    class Meta:
        model = BulkInvoice

    # Define the relevant fields for JSON
    name = fields.Str()
    title = fields.Str()
    mailing_list = auto_field()
    issuing_date = auto_field()
    update_time = auto_field()
    due_date = auto_field()
    status = auto_field()
    text_invoice = auto_field()
    text_reminder = auto_field()
    text_mail = auto_field()
class PostUserSchema(SQLAlchemySchema):
    class Meta:
        model = PostUser
        load_instance = True

    id = auto_field()
    info = auto_field()
    timestamp = auto_field()
    user_id = auto_field()
    user_name = auto_field()
    vehicle_id = auto_field()
    vehicle_placa = auto_field()
示例#25
0
class DatasetSchema(SQLAlchemySchema):
    class Meta:
        model = Dataset
        ordered = True

    dataset_id = auto_field()
    name = auto_field()
    creation_timestamp = auto_field()
    service_type = auto_field()
    validity_expiration_timestamp = auto_field()
    author = auto_field()
    external = auto_field()
示例#26
0
class CollectorSchema(SQLAlchemySchema):
    class Meta:
        model = DatasetCollector
        ordered = True

    kafka_topic = auto_field(required=True)
    kafka_server = auto_field(required=True)
    nsd_id = auto_field(required=True)
    creation_timestamp = auto_field()
    termination_timestamp = auto_field()
    latest_update = auto_field()
    status = auto_field()
示例#27
0
class UserSchema(SQLAlchemySchema):
    class Meta:
        model = UserModel
        load_instance = True

    id = auto_field()
    username = auto_field()
    email = auto_field()
    verified = auto_field()
    active = auto_field()
    first_name = auto_field()
    last_name = auto_field()
示例#28
0
class ShowSchema(SQLAlchemySchema):
    class Meta:
        model = Show
        load_instance = True

    id = auto_field()
    title = auto_field()
    host = auto_field()
    description = auto_field()
    bio = auto_field()
    image = auto_field()
    tags = auto_field()
示例#29
0
class BoundJobRuleSchema(SQLAlchemySchema):
    id = auto_field()
    job_rule_id = auto_field()
    user_id = auto_field()
    user_group_id = auto_field()
    scheduler_partition_id = auto_field()
    priority = auto_field()
    is_default = auto_field()
    is_active = auto_field()

    class Meta:
        model = BoundJobRule
        load_instance = True
        include_relationships = True

    job_rule = fields.Nested(JobRuleSchema)
示例#30
0
class MessageSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Message
        load_instance = True
        sqla_session = True

    author_id = auto_field(load_only=True)
    author = fields.Nested(lambda: UserSchema(only=("id", "username")),
                           dump_only=True)

    @validates("author_id")
    def validate_author_id(self, author_id):
        user = User.query.get(author_id)
        if user is None:
            raise ValidationError("User does not exist")

    chatroom_id = auto_field(load_only=True)

    @validates("chatroom_id")
    def validate_chatroom_id(self, chatroom_id):
        user = Chatroom.query.get(chatroom_id)
        if user is None:
            raise ValidationError("Chatroom does not exist")