Beispiel #1
0
class MyCard(Card):

    cvv2 = Field(
        Integer,
        readonly=False,
        minimum=100,
        maximum=9999,
        not_none=False,
        nullable=True,
        required=False,
        python_type=int,
    )
    pin1 = Field(
        Unicode(4),
        readonly=False,
        min_length=4,
        max_length=4,
        not_none=False,
        nullable=True,
        required=False,
        python_type=str,
    )
    pin2 = Field(
        Unicode(12),
        readonly=False,
        min_length=5,
        max_length=12,
        not_none=False,
        nullable=True,
        required=False,
        python_type=str,
    )
Beispiel #2
0
class Invitation(ActivationMixin, DeclarativeBase):
    __tablename__ = 'invitation'

    code = Field(Unicode(), primary_key=True)

    total_sits = Field(Integer())
    filled_sits = Field(Integer(), default=0)

    __table_args__ = (CheckConstraint(
        'total_sits >= filled_sits',
        name='cc_invitation_total_sits_grater_that_filled'), )

    @property
    def unfilled_sits(self):
        return self.total_sits - self.filled_sits

    @classmethod
    def ensure_code(cls, code):
        invitation = Invitation.query.filter(
            Invitation.code == code).with_for_update().one_or_none()

        if invitation is None:
            raise HttpNotFound()

        return invitation
Beispiel #3
0
class MemberContact(DeclarativeBase):
    __tablename__ = 'member_contact'

    member_id = Field(Integer, ForeignKey('member.id'), primary_key=True)
    contact_member_id = Field(Integer,
                              ForeignKey('member.id'),
                              primary_key=True)
class Supervisor(DeclarativeBase):
    __tablename__ = 'supervisor'

    id = Field(
        Integer,
        primary_key=True,
        readonly='709 id is readonly'
    )
    email = Field(
        Unicode(100),
        not_none='701 email cannot be null',
        required='702 email required',
        pattern=(
            '(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)',
            '707 Invalid email address'
        ),
        watermark='Email',
        example="*****@*****.**"
    )
    title = Field(
        Unicode(50),
        index=True,
        min_length=(4, '703 title must be at least 4 characters'),
        max_length=(50, '704 Maximum allowed length for title is 50'),
        watermark='First Name',
        nullable=True,
    )
    age = Field(
        Integer,
        nullable=True,
        python_type=(int, '705 age must be integer'),
        minimum=(18, '706 age must be greater than 17'),
        maximum=(99, '706 age must be less than 100')
    )
class FullTextSearchObject(FullTextSearchMixin, DeclarativeBase):
    __tablename__ = 'fulltext_search_object'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50))

    __ts_vector__ = to_tsvector(title)
Beispiel #6
0
class SecurityLog(TimestampMixin, PaginationMixin, DeclarativeBase):
    __tablename__ = 'security_log'

    id = Field(Integer(), primary_key=True)
    client_id = Field(Integer(), ForeignKey('member.id'))

    type = Field(Enum('login', 'password-change', name='security_log_type'))
    details = Field(Unicode())

    @classmethod
    def generate_log(cls, type):
        session_info = context.application.__authenticator__.extract_agent_info(
        )
        remote_address = session_info['remoteAddress']
        machine = session_info['machine']
        os = session_info['os']
        agent = session_info['agent']
        client = session_info['client']
        app = session_info['app']

        log = cls()
        log.client_id = context.identity.id
        log.type = type
        log.details = f'Remote Address: {remote_address} Machine: {machine} OS: {os} Agent: {agent}' \
                      f' Client: {client} App: {app}'

        return log
Beispiel #7
0
class Comment(DeclarativeBase):
    __tablename__ = 'comment'
    id = Field(Integer, primary_key=True)
    content = Field(Unicode(100), max_length=90)
    special = Field(Boolean, default=True)
    post_id = Field(ForeignKey('post.id'), json='postId')
    post = relationship('Post')
Beispiel #8
0
class Tag(DeclarativeBase):
    __tablename__ = 'tag'
    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50), watermark='title', label='title')
    posts = relationship('Post',
                         secondary=post_tag_table,
                         back_populates='tags')
class SqlErrorCheckingModel(ModifiedMixin, FilteringMixin, PaginationMixin,
                            OrderingMixin, DeclarativeBase):

    __tablename__ = 'sql_error_checking_model'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50), unique=True, nullable=False)
Beispiel #10
0
class Target(ModifiedMixin, OrderingMixin, FilteringMixin, PaginationMixin,
             DeclarativeBase):
    __tablename__ = 'target'

    id = Field(Integer, primary_key=True)
    type = Field(
        Unicode(25),
        python_type=str,
        min_length=4,
        not_none=False,
        required=False,
        watermark='Loerm Ipsum',
        message='Loerm Ipsum',
        example='direct',
    )

    # since the number of collections are small, the selectin strategy is
    # more efficient for loading
    members = relationship(
        'Member',
        secondary='target_member',
        backref='rooms',
        lazy='selectin',
        protected=True,
    )
    envelop_id = relationship('Envelop')

    __mapper_args__ = {
        'polymorphic_identity': __tablename__,
        'polymorphic_on': type,
    }
Beispiel #11
0
class Item(ModifiedMixin, DeclarativeBase):
    __tablename__ = 'item'

    id = Field(Integer, primary_key=True)
    title = Field(
        ITEM_TITLE_SQLTYPE,
        not_none=True,
        required=True,
    )

    list = Field(LIST_TITLE_SQLTYPE)

    ownerid = Field(ForeignKey('user.id'))
    owner = relationship(
        'User',
        backref='items',
        foreign_keys=[ownerid]
    )

    __table_args__ = (
        UniqueConstraint(
            ownerid, list, title,
            name='uix_ownerid_list_title'
        ),
    )

    @property
    def fulltitle(self):
        return f'{self.list}/{self.title}'

    def __str__(self):
        return f'{self.fulltitle}'
Beispiel #12
0
class State(FilteringMixin, DeclarativeBase):
    __tablename__ = 'state'

    id = Field(Integer(), primary_key=True)
    country_id = Field(Integer(), ForeignKey('country.id'))

    name = Field(Unicode(50))

    country = relationship('Country', uselist=False)
Beispiel #13
0
class ModelValidationCheckingModel(DeclarativeBase):
    __tablename__ = 'model_validation_checking_model'

    id = Field(Integer, primary_key=True, readonly=True)
    title = Field(Unicode(50),
                  unique=True,
                  nullable=False,
                  pattern='[A-Z][a-zA-Z]*')
    modified = Field(DateTime, default=datetime.now, readonly=True)
Beispiel #14
0
class Author(DeclarativeBase):
    __tablename__ = 'author'

    id = Field(Integer, primary_key=True)
    email = Field(
        Unicode(100),
        unique=True,
        index=True,
        json='email',
        pattern=r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)',
        watermark='Email',
        example="*****@*****.**")
    title = Field(Unicode(50),
                  index=True,
                  min_length=2,
                  watermark='First Name')
    first_name = Field(Unicode(50),
                       index=True,
                       json='firstName',
                       min_length=2,
                       watermark='First Name')
    last_name = Field(Unicode(100),
                      json='lastName',
                      min_length=2,
                      watermark='Last Name')
    phone = Field(
        Unicode(10), nullable=True, json='phone', min_length=10,
        pattern=\
            r'\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??'
            r'\d{4}|\d{3}[-\.\s]??\d{4}',
        watermark='Phone'
    )
    name = composite(FullName,
                     first_name,
                     last_name,
                     readonly=True,
                     json='fullName',
                     protected=True)
    _password = Field('password',
                      Unicode(128),
                      index=True,
                      json='password',
                      protected=True,
                      min_length=6)
    birth = Field(Date)
    weight = Field(Float(asdecimal=True))
    age = Field(Integer, default=18, minimum=18, maximum=100)

    def _set_password(self, password):
        self._password = '******' % password

    def _get_password(self):  # pragma: no cover
        return self._password

    password = synonym('_password',
                       descriptor=property(_get_password, _set_password),
                       info=dict(protected=True))
Beispiel #15
0
class City(FilteringMixin, DeclarativeBase):
    __tablename__ = 'city'

    id = Field(Integer(), primary_key=True)
    state_id = Field(Integer(), ForeignKey('state.id'))

    name = Field(Unicode(50))

    state = relationship('State', uselist=False)
class Person(DeclarativeBase):
    __tablename__ = 'person'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50),
                  unique=True,
                  index=True,
                  min_length=2,
                  watermark='Title',
                  label='Title')
Beispiel #17
0
class Issue(FilteringMixin, OrderingMixin, PaginationMixin, DeclarativeBase):
    __tablename__ = 'issue'

    id = Field(Integer, primary_key=True)

    title = Field(Unicode(50))
    description = Field(Unicode(200))
    # user_id = Column(Integer, ForeignKey('users.id'))
    work_group_id = Column(Integer, ForeignKey('work_group.id'))
    work_group = orm.relationship("WorkGroup", back_populates="issue")
Beispiel #18
0
class IpWhitelist(TimestampMixin, DeclarativeBase):
    __tablename__ = 'ip_whitelist'

    id = Field(Integer(), primary_key=True)
    client_id = Field(Integer(), ForeignKey('member.id'))

    ip = Field(Unicode(50),
               min_length=7,
               max_length=15,
               pattern=r'^([0-9]{1,3}\.){3}[0-9]{1,3}$')
Beispiel #19
0
class Post(ModifiedMixin, DeclarativeBase):
    __tablename__ = 'post'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50), watermark='title', label='title', icon='star')
    author_id = Field(ForeignKey('author.id'), json='authorId')
    author = relationship(Author)
    memos = relationship(Memo, protected=True, json='privateMemos')
    comments = relationship(Comment)
    tags = relationship(Tag, secondary=post_tag_table, back_populates='posts')
    tag_time = Field(Time)
class WorkGroup(FilteringMixin, OrderingMixin, PaginationMixin,
                DeclarativeBase):
    __tablename__ = 'work_group'

    id = Field(Integer, primary_key=True)

    title = Field(Unicode(50))
    description = Field(Unicode(200))
    priority = Field(Integer, nullable=True)
    issue = orm.relationship("Issue",
                             uselist=False,
                             back_populates="work_group")
Beispiel #21
0
class Country(DeclarativeBase):
    __tablename__ = 'country'

    id = Field(Integer(), primary_key=True)

    name = Field(Unicode(50))
    code = Field(Unicode(10),
                 min_length=1,
                 max_length=10,
                 pattern=r'^[a-z]{1,10}$',
                 unique=True)

    phone_prefix = Field(Integer())
Beispiel #22
0
class Member(DeclarativeBase):
    __tablename__ = 'member'

    id = Field(Integer, primary_key=True)
    email = Field(Unicode(100), unique=True, index=True)
    title = Field(Unicode(100), unique=True)
    _password = Field('password', Unicode(128), index=True, protected=True)

    def _hash_password(cls, password):
        salt = sha256()
        salt.update(os.urandom(60))
        salt = salt.hexdigest()

        hashed_pass = sha256()
        # Make sure password is a str because we cannot hash unicode objects
        hashed_pass.update((password + salt).encode('utf-8'))
        hashed_pass = hashed_pass.hexdigest()

        password = salt + hashed_pass
        return password

    def _set_password(self, password):
        """Hash ``password`` on the fly and store its hashed version."""
        self._password = self._hash_password(password)

    def _get_password(self):
        """Return the hashed version of the password."""
        return self._password

    password = synonym('_password',
                       descriptor=property(_get_password, _set_password),
                       info=dict(protected=True))

    def create_jwt_principal(self):
        return JwtPrincipal(dict(id=self.id, email=self.email,
                                 name=self.title))

    def create_refresh_principal(self):
        return JwtRefreshToken(dict(id=self.id))

    def validate_password(self, password):
        hashed_pass = sha256()
        hashed_pass.update((password + self.password[:64]).encode('utf-8'))

        return self.password[64:] == hashed_pass.hexdigest()

    @classmethod
    def current(cls):
        return DBSession.query(cls).\
            filter(cls.email == context.identity.email).one()
Beispiel #23
0
class Resource(ModifiedMixin, OrderingMixin, PaginationMixin, FilteringMixin,
               DeclarativeBase):
    __tablename__ = 'resource'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(30),
                  watermark='title here',
                  label='Title',
                  pattern='[a-zA-Z0-9]{3,}',
                  min_length=3)
    password = Field(Unicode(30),
                     protected=True,
                     nullable=False,
                     default='123456')
Beispiel #24
0
class OrderableOrderingObject(OrderableMixin, OrderingMixin, DeclarativeBase):
    __tablename__ = 'orderable_ordering_object'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(50))
    _age = Field(Integer)

    def _set_age(self, age):
        self._age = age

    def _get_age(self):  # pragma: no cover
        return self._age

    age = synonym('_age', descriptor=property(_get_age, _set_age))
class Interval(FilteringMixin, DeclarativeBase):
    __tablename__ = 'interval'

    id = Field(Integer, primary_key=True)
    start = Field(Integer)
    end = Field(Integer)

    @hybrid_property
    def length(self):
        return self.end - self.start

    @length.expression
    def length(cls):
        return cls.end - cls.start
Beispiel #26
0
class Resource(ModifiedMixin, OrderingMixin, PaginationMixin, FilteringMixin,
               DeclarativeBase):
    __tablename__ = 'resource'

    id = Field(Integer, primary_key=True)
    title = Field(Unicode(30),
                  watermark='title here',
                  icon='default',
                  label='Title',
                  pattern='[a-zA-Z0-9]{3,}',
                  min_length=3)

    @property
    def __etag__(self):
        return self.last_modification_time.isoformat()
Beispiel #27
0
class Envelop(OrderingMixin, PaginationMixin, FilteringMixin, ModifiedMixin,
              SoftDeleteMixin, ActivationMixin, DeclarativeBase):
    __tablename__ = 'envelop'

    id = Field(Integer, primary_key=True)
    type = Field(Unicode(25))
    target_id = Field(Integer, ForeignKey('target.id'))
    sender_id = Field(Integer, ForeignKey('member.id'))
    body = Field(
        Unicode(65536),
        required=True,
        not_none=True,
        min_length=1,
        protected=False,
        python_type=str,
        watermark='Loerm Ipsum',
        example='Loerm Ipsum',
        message='Loerm Ipsum',
        label='Text or caption',
    )

    sender_reference_id = column_property(
        select([Member.reference_id]) \
        .where(Member.id == sender_id) \
        .correlate_except(Member),
        deferred=True
    )

    def to_dict(self):
        envelop_dictionary = super().to_dict()
        envelop_dictionary.update(senderReferenceId=self.sender_reference_id)
        return envelop_dictionary

    @classmethod
    def json_metadata(cls):
        metadata = super().json_metadata()
        metadata['fields']['senderReferenceId'] = FieldInfo(
            Integer,
            not_none=True,
            readonly=True,
            required=False,
        ).to_json()
        return metadata

    __mapper_args__ = {
        'polymorphic_identity': __tablename__,
        'polymorphic_on': type,
    }
Beispiel #28
0
class Person(FullTextSearchMixin, DeclarativeBase):
    __tablename__ = 'person'

    id = Field(Integer, primary_key=True)
    first_name = Field(Unicode(50))
    last_name = Field(Unicode(50))
    description = Field(Text)

    __ts_vector__ = to_tsvector(
        first_name, last_name, description
    )

    __table_args__ = (
        Index('idx_person_fts', __ts_vector__, postgresql_using='gin'),
        Index('idx_first_name_trgm', text("first_name gin_trgm_ops"), postgresql_using='gin')
    )
Beispiel #29
0
class EtagCheckingModel(ModifiedMixin, DeclarativeBase):
    __tablename__ = 'etag_checking_model'

    title = Field(Unicode(50), primary_key=True)

    @property
    def __etag__(self):
        return self.last_modification_time.isoformat()
Beispiel #30
0
class Email(BaseEmail):  # pragma: no cover
    __tablename__ = 'email'
    __mapper_args__ = {'polymorphic_identity': __tablename__}

    body = Field(JSON, json='body')

    @property
    def email_body(self):
        return self.body