Пример #1
0
class SubThing(BaseModel):
    __tablename__ = "subthing"
    _s_auto_commit = True
    id = db.Column(db.String, primary_key=True, server_default=func.uuid_generate_v1())
    name = db.Column(db.String, nullable=False)

    thing_id = db.Column(db.String, db.ForeignKey("thing.id"))
    thing = db.relationship("Thing", foreign_keys=thing_id)
Пример #2
0
class Thing(BaseModel):
    """
        description: Thing related operations
    """
    __tablename__ = "thing"

    id = db.Column(db.String, primary_key=True, server_default=func.uuid_generate_v1())
    name = db.Column(db.String)
    #description = db.Column("a_description", SafeString)
    description = db.Column("description", db.String)
    created = db.Column(db.DateTime)
    documented_column = DocumentedColumn(db.String)

    @classmethod
    @jsonapi_rpc(http_methods=["GET"])
    def get_by_name(cls, name, **kwargs):
        """
        description : Generate and return a Thing based on name
        parameters:
            - name: name
              type : string
        """
        thing = cls.query.filter_by(name=name).one_or_none()
        if not thing:
            # thing.description = populate_based_on_name()
            db.session.add(thing)
            db.session.commit()

        response = SAFRSFormattedResponse()
        result = jsonapi_format_response(thing, meta={}, count=1)
        response.response = result
        return response

    @jsonapi_rpc(http_methods=["POST", "GET"])
    def send_thing(self, email):
        content = "Hello {}, here is your thing: {}\n".format(email, email)
        return {"result": "sent: {}".format(content)}

    startswith = startswith

    @classmethod
    def filter(cls, *args, **kwargs):
        return cls.query.all()

    @jsonapi_rpc(http_methods=["POST", "GET"])
    def none(self):
        return {}

    @jsonapi_attr
    def some_attr(self):
        """
            default: 
                - 200
        """
        return 100
Пример #3
0
class Thing(BaseModel):
    """
        description: Thing related operations
    """
    __tablename__ = "thing"

    id = db.Column(db.String, primary_key=True, server_default=func.uuid_generate_v1())
    name = db.Column(db.String)
    description = db.Column(db.String)

    @classmethod
    @jsonapi_rpc(http_methods=["GET"])
    def get_by_name(cls, name, **kwargs):
        """
        description : Generate and return a Thing based on name
        parameters:
            - name: name
              type : string
        """
        thing = cls.query.filter_by(name=name).one_or_none()
        if not thing:
            # thing.description = populate_based_on_name()
            db.session.add(thing)
            db.session.commit()

        response = SAFRSFormattedResponse()
        result = jsonapi_format_response(thing, meta={}, count=1)
        response.response = result
        return response

    @jsonapi_rpc(http_methods=["POST", "GET"])
    def send_thing(self, email):
        """
        description : Send Thing to email
        args:
            email:
                type : string
                example : [email protected]
        """
        content = "Hello {}, here is your thing: {}\n".format(email, email)
        return {"result": "sent: {}".format(content)}
Пример #4
0
           server_default=text("true")),
    Column("is_admin",
           Boolean,
           nullable=False,
           default=text("false"),
           server_default=text("false")),
)

wallets = Table(
    "wallets",
    metadata,
    Column("id",
           UUID(),
           primary_key=True,
           nullable=False,
           server_default=func.uuid_generate_v1()),
    Column("created_at",
           DateTime,
           nullable=False,
           server_default=func.current_timestamp()),
    Column("updated_at",
           DateTime,
           nullable=False,
           server_default=func.current_timestamp(),
           onupdate=func.current_timestamp()),
    Column("user_id", Integer, ForeignKey("users.id"), nullable=False),
    Column("balance",
           Integer,
           nullable=False,
           default=text("0"),
           server_default=text("0")),
Пример #5
0
class ThingWType(BaseModel):
    __tablename__ = "thing_with_type"
    db_commit = True
    id = db.Column(db.String, primary_key=True, server_default=func.uuid_generate_v1())
    type= db.Column(db.String, nullable=False,default="type_str")
Пример #6
0
class ThingWOCommit(BaseModel):
    __tablename__ = "thing_without_commit"
    db_commit = False
    id = db.Column(db.String, primary_key=True, server_default=func.uuid_generate_v1())
    name = db.Column(db.String)