Ejemplo n.º 1
1
    Table, Column, UnicodeText, Text, Enum, DateTime
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func

from linehaul import db


downloads = Table(
    "downloads", db.metadata,
    Column(
        "id",
        UUID(),
        primary_key=True,
        nullable=False,
        server_default=func.uuid_generate_v4()
    ),

    Column("package_name", UnicodeText(), nullable=False),
    Column("package_version", UnicodeText()),
    Column(
        "distribution_type",
        Enum("sdist", "wheel", "exe", "egg", "msi", name="distribution_type")
    ),

    Column(
        "python_type",
        Enum("cpython", "pypy", "jython", "ironpython", name="python_type")
    ),
    Column("python_release", Text()),
    Column("python_version", Text()),
Ejemplo n.º 2
0
class PackageSwitch(BaseModel):
    __tablename__ = 'package_switch'
    TYPE = {1: 'switch pay per port', 2: 'switch pay per minute'}
    SUB_TYPE = {1: 'hosted_switch', 2: 'on_premise', 3: 'one_time'}
    package_switch_uuid = Column \
        (String(36), primary_key=True, default=generate_uuid_str(),
         server_default=func.uuid_generate_v4())

    package_name = Column(String(64), unique=True)

    type = Column(ChoiceType(TYPE), default=1)
    sub_type = Column(ChoiceType(SUB_TYPE), nullable=True)
    #switch_uuid = Column(String(128),index=True)
    #Column(ForeignKey('switch.switch_uuid', ondelete='CASCADE'), index=True)
    switch_port = Column(Integer())
    minute_count = Column(Integer())
    amount = Column(Integer())
    enabled = Column(Boolean, default=True)
    start_date = Column(DateTime(True),
                        nullable=False,
                        server_default=func.now())
    expire_date = Column(DateTime(True), nullable=True)
    create_on = Column(DateTime(True),
                       nullable=True,
                       server_default=func.now())

    licenses = relationship('LicenseSwitch',
                            uselist=True,
                            back_populates='package')
    #switch = relationship('Switch', uselist=False, back_populates='packages')
    rate_per_port = column_property(
        case([(switch_port > 0, cast(amount, Float).op('/')(switch_port))],
             else_=None))
Ejemplo n.º 3
0
class CorCountingOccurrence(DB.Model):
    __tablename__ = "cor_counting_occtax"
    __table_args__ = {"schema": "pr_occtax"}
    id_counting_occtax = DB.Column(DB.Integer, primary_key=True)
    unique_id_sinp_occtax = DB.Column(UUID(as_uuid=True),
                                      default=select([func.uuid_generate_v4()
                                                      ]),
                                      nullable=False)
    id_occurrence_occtax = DB.Column(
        DB.Integer,
        ForeignKey("pr_occtax.t_occurrences_occtax.id_occurrence_occtax"),
        nullable=False,
    )
    id_nomenclature_life_stage = DB.Column(DB.Integer, nullable=False)
    id_nomenclature_sex = DB.Column(DB.Integer, nullable=False)
    id_nomenclature_obj_count = DB.Column(DB.Integer, nullable=False)
    id_nomenclature_type_count = DB.Column(DB.Integer)
    count_min = DB.Column(DB.Integer)
    count_max = DB.Column(DB.Integer)

    readonly_fields = [
        "id_counting_occtax",
        "unique_id_sinp_occtax",
        "id_occurrence_occtax",
    ]

    medias = DB.relationship(
        TMedias,
        primaryjoin=
        ('TMedias.uuid_attached_row == CorCountingOccurrence.unique_id_sinp_occtax'
         ),
        foreign_keys=[TMedias.uuid_attached_row],
        cascade="all",
        lazy="select",
    )
Ejemplo n.º 4
0
class TMedias(DB.Model):
    __tablename__ = "t_medias"
    __table_args__ = {"schema": "gn_commons"}
    id_media = DB.Column(DB.Integer, primary_key=True)
    id_nomenclature_media_type = DB.Column(
        DB.Integer
        # ,
        # ForeignKey('ref_nomenclatures.t_nomenclatures.id_nomenclature')
    )
    id_table_location = DB.Column(
        DB.Integer, ForeignKey("gn_commons.bib_tables_location.id_table_location")
    )
    unique_id_media = DB.Column(
        UUID(as_uuid=True), default=select([func.uuid_generate_v4()])
    )
    uuid_attached_row = DB.Column(UUID(as_uuid=True))
    title_fr = DB.Column(DB.Unicode)
    title_en = DB.Column(DB.Unicode)
    title_it = DB.Column(DB.Unicode)
    title_es = DB.Column(DB.Unicode)
    title_de = DB.Column(DB.Unicode)
    media_url = DB.Column(DB.Unicode)
    media_path = DB.Column(DB.Unicode)
    author = DB.Column(DB.Unicode)
    description_fr = DB.Column(DB.Unicode)
    description_en = DB.Column(DB.Unicode)
    description_it = DB.Column(DB.Unicode)
    description_es = DB.Column(DB.Unicode)
    description_de = DB.Column(DB.Unicode)
    is_public = DB.Column(DB.Boolean, default=True)
Ejemplo n.º 5
0
class Assessment(db.Model):
    __tablename__ = 'assessments'

    id = db.Column(UUID(), primary_key=True, default=uuid4, server_default=func.uuid_generate_v4(), index=True, comment='ID оценки')
    rating = db.Column(db.Float(), nullable=True, comment='Рейтинг фотографии.')
    photo_id = db.Column(UUID(), db.ForeignKey('photos.id', ondelete='CASCADE'), nullable=True, index=True, comment='ID фотографии.')
    user_id = db.Column(UUID(), db.ForeignKey('users.id', ondelete='CASCADE'), nullable=True, index=True, comment='ID пользователя.')
Ejemplo n.º 6
0
class TransactionLog(BaseModel):
    __tablename__ = 'transaction_log'
    TYPE = {1: 'paypal', 2: 'stripe'}
    STATUS = {1: 'success', -1: 'fail'}
    transaction_log_uuid = Column(String(36),
                                  primary_key=True,
                                  default=generate_uuid_str(),
                                  server_default=func.uuid_generate_v4())
    transaction_time = Column(DateTime(True),
                              nullable=False,
                              server_default=func.now())
    license_lrn_uuid = Column(String(36))
    license_switch_uuid = Column(String(36))
    user_uuid = Column(ForeignKey('user.user_uuid', ondelete='CASCADE'),
                       nullable=True,
                       index=True)
    type = Column(ChoiceType(TYPE), default=1)
    amount_total = Column(Numeric, nullable=False, server_default='0')
    amount_lrn = Column(Numeric, nullable=False, server_default='0')
    amount_switch = Column(Numeric, nullable=False, server_default='0')
    transaction_fee = Column(Numeric, nullable=False, server_default='0')
    transaction_id = Column(String(255))
    transaction_type = Column(String(255))
    from_ip = Column(String(36))
    transaction_src = Column(JSON())
    status = Column(ChoiceType(STATUS), default=-1)
    result = Column(Text())
    payment_uuid = Column(ForeignKey('payment.payment_uuid',
                                     ondelete='CASCADE'),
                          index=True)

    user_name = column_property(
        select([User.name
                ]).where(user_uuid == User.user_uuid).correlate_except(User))
Ejemplo n.º 7
0
class TBaseVisits(DB.Model):
    '''
        Table de centralisation des visites liées à un site
    '''
    __tablename__ = 't_base_visits'
    __table_args__ = {'schema': 'gn_monitoring'}
    id_base_visit = DB.Column(DB.Integer, primary_key=True)
    id_base_site = DB.Column(
        DB.Integer, ForeignKey('gn_monitoring.t_base_sites.id_base_site'))
    id_digitiser = DB.Column(DB.Integer,
                             ForeignKey('utilisateurs.t_roles.id_role'))

    visit_date_min = DB.Column(DB.DateTime)
    visit_date_max = DB.Column(DB.DateTime)
    # geom = DB.Column(Geometry('GEOMETRY', 4326))
    comments = DB.Column(DB.DateTime)
    uuid_base_visit = DB.Column(UUID(as_uuid=True),
                                default=select([func.uuid_generate_v4()]))

    digitiser = relationship(User,
                             primaryjoin=(User.id_role == id_digitiser),
                             foreign_keys=[id_digitiser])

    observers = DB.relationship(
        User,
        secondary=corVisitObserver,
        primaryjoin=(corVisitObserver.c.id_base_visit == id_base_visit),
        secondaryjoin=(corVisitObserver.c.id_role == User.id_role),
        foreign_keys=[
            corVisitObserver.c.id_base_visit, corVisitObserver.c.id_role
        ])
Ejemplo n.º 8
0
class TBaseVisits(DB.Model):
    """
        Table de centralisation des visites liées à un site
    """

    __tablename__ = "t_base_visits"
    __table_args__ = {"schema": "gn_monitoring"}
    id_base_visit = DB.Column(DB.Integer, primary_key=True)
    id_base_site = DB.Column(
        DB.Integer, ForeignKey("gn_monitoring.t_base_sites.id_base_site")
    )
    id_digitiser = DB.Column(
        DB.Integer,
        ForeignKey("utilisateurs.t_roles.id_role")
    )
    id_dataset = DB.Column(
        DB.Integer,
        ForeignKey("gn_meta.t_datasets.id_dataset")
    )
    # Pour le moment non défini comme une clé étrangère
    #   pour les questions de perfs
    #   a voir en fonction des usage
    id_module = DB.Column(DB.Integer)

    visit_date_min = DB.Column(DB.DateTime)
    visit_date_max = DB.Column(DB.DateTime)
    id_nomenclature_tech_collect_campanule = DB.Column(DB.Integer)
    id_nomenclature_grp_typ = DB.Column(DB.Integer)
    comments = DB.Column(DB.DateTime)
    uuid_base_visit = DB.Column(
        UUID(as_uuid=True), default=select([func.uuid_generate_v4()])
    )

    meta_create_date = DB.Column(DB.DateTime)
    meta_update_date = DB.Column(DB.DateTime)

    digitiser = relationship(
        User,
        primaryjoin=(User.id_role == id_digitiser),
        foreign_keys=[id_digitiser]
    )

    observers = DB.relationship(
        User,
        secondary=corVisitObserver,
        primaryjoin=(corVisitObserver.c.id_base_visit == id_base_visit),
        secondaryjoin=(corVisitObserver.c.id_role == User.id_role),
        foreign_keys=[corVisitObserver.c.id_base_visit,
                      corVisitObserver.c.id_role],
    )

    dataset = relationship(
        TDatasets,
        lazy="joined",
        primaryjoin=(TDatasets.id_dataset == id_dataset),
        foreign_keys=[id_dataset]
    )
Ejemplo n.º 9
0
class MyModel(DB.Model):
    __tablename__ = "my_table"
    __table_args__ = {"schema": "my_schema"}
    my_pk = DB.Column(DB.Integer, primary_key=True)
    my_field = DB.Column(
        UUID(as_uuid=True), default=select([func.uuid_generate_v4()])
    )
    geom_local = DB.Column(
        Geometry("GEOMETRY", current_app.config["LOCAL_SRID"]))
def upgrade():
    op.create_table(
        'downloads',
        sa.Column(
            'id',
            postgresql.UUID(),
            server_default=func.uuid_generate_v4(),
            nullable=False
        ),
        sa.Column('package_name', sa.UnicodeText(), nullable=False),
        sa.Column('package_version', sa.UnicodeText(), nullable=True),
        sa.Column(
            'distribution_type',
            sa.Enum(
                u'sdist',
                u'wheel',
                u'exe',
                u'egg',
                u'msi',
                name='distribution_type'
            ),
            nullable=True
        ),
        sa.Column(
            'python_type',
            sa.Enum(
                u'cpython',
                u'pypy',
                u'jython',
                u'ironpython',
                name='python_type'
            ),
            nullable=True
        ),
        sa.Column('python_release', sa.Text(), nullable=True),
        sa.Column('python_version', sa.Text(), nullable=True),
        sa.Column(
            'installer_type',
            sa.Enum(
                u'browser',
                u'pip',
                u'setuptools',
                u'distribute',
                u'bandersnatch',
                u'z3c.pypimirror',
                u'pep381client',
                name='installer_type'
            ),
            nullable=True
        ),
        sa.Column('installer_version', sa.Text(), nullable=True),
        sa.Column('operating_system', sa.Text(), nullable=True),
        sa.Column('operating_system_version', sa.Text(), nullable=True),
        sa.Column('download_time', sa.DateTime(), nullable=False),
        sa.Column('raw_user_agent', sa.Text(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
Ejemplo n.º 11
0
class User(Base):
    """This model represents an application user."""

    __tablename__ = 'user'
    id = sa.Column(pg.UUID,
                   primary_key=True,
                   server_default=func.uuid_generate_v4())
    username = sa.Column(sa.Text, nullable=False, unique=True)
    password_hash = sa.Column(pg.BYTEA, nullable=False)
Ejemplo n.º 12
0
class TBaseSites(DB.Model):
    """
        Table centralisant les données élémentaire des sites
    """

    __tablename__ = "t_base_sites"
    __table_args__ = {"schema": "gn_monitoring"}
    id_base_site = DB.Column(DB.Integer, primary_key=True)
    id_inventor = DB.Column(
        DB.Integer,
        ForeignKey("utilisateurs.t_roles.id_role")
    )
    id_digitiser = DB.Column(
        DB.Integer,
        ForeignKey("utilisateurs.t_roles.id_role")
    )
    id_nomenclature_type_site = DB.Column(DB.Integer)
    base_site_name = DB.Column(DB.Unicode)
    base_site_description = DB.Column(DB.Unicode)
    base_site_code = DB.Column(DB.Unicode)
    first_use_date = DB.Column(DB.DateTime)
    geom = DB.Column(Geometry("GEOMETRY", 4326))
    uuid_base_site = DB.Column(
        UUID(as_uuid=True), default=select([func.uuid_generate_v4()])
    )

    meta_create_date = DB.Column(DB.DateTime)
    meta_update_date = DB.Column(DB.DateTime)

    digitiser = relationship(
        User,
        primaryjoin=(User.id_role == id_digitiser),
        foreign_keys=[id_digitiser]
    )
    inventor = relationship(
        User,
        primaryjoin=(User.id_role == id_inventor),
        foreign_keys=[id_inventor]
    )

    t_base_visits = relationship(
        "TBaseVisits", lazy="select", cascade="all,delete-orphan"
    )

    modules = DB.relationship(
        "TModules",
        lazy="select",
        enable_typechecks=False,
        secondary=corSiteModule,
        primaryjoin=(corSiteModule.c.id_base_site == id_base_site),
        secondaryjoin=(corSiteModule.c.id_module == TModules.id_module),
        foreign_keys=[corSiteModule.c.id_base_site, corSiteModule.c.id_module],
    )

    def get_geofeature(self, recursif=True):
        return self.as_geofeature("geom", "id_base_site", recursif)
Ejemplo n.º 13
0
class Photo(db.Model):
    __tablename__ = 'photos'

    id = db.Column(UUID(),
                   primary_key=True,
                   default=uuid4,
                   server_default=func.uuid_generate_v4(),
                   index=True,
                   comment='Id photo.')  # noqa
    path = db.Column(db.String(), nullable=False,
                     comment='Путь до фотографии')  # noqa
Ejemplo n.º 14
0
class Switch(BaseModel):
    __tablename__ = 'switch'
    switch_uuid = Column \
        (String(36), primary_key=True, default=generate_uuid_str(),
         server_default=func.uuid_generate_v4())
    switch_ip = Column(String(16))
    enabled = Column(Boolean, default=True)
    current_port_count = Column(Integer())
    minute_remaining = Column(Integer())
    expired_on = Column(DateTime(True), nullable=True)
    email = Column(String(256))
Ejemplo n.º 15
0
class BibOrganismes(DB.Model):
    __tablename__ = "bib_organismes"
    __table_args__ = {"schema": "utilisateurs", "extend_existing": True}
    id_organisme = DB.Column(DB.Integer, primary_key=True)
    uuid_organisme = DB.Column(UUID(as_uuid=True),
                               default=select([func.uuid_generate_v4()]))
    nom_organisme = DB.Column(DB.Unicode)
    cp_organisme = DB.Column(DB.Unicode)
    ville_organisme = DB.Column(DB.Unicode)
    tel_organisme = DB.Column(DB.Unicode)
    fax_organisme = DB.Column(DB.Unicode)
    email_organisme = DB.Column(DB.Unicode)
Ejemplo n.º 16
0
class TBaseSites(DB.Model):
    '''
        Table centralisant les données élémentaire des sites
    '''
    __tablename__ = 't_base_sites'
    __table_args__ = {'schema': 'gn_monitoring'}
    id_base_site = DB.Column(DB.Integer, primary_key=True)
    id_inventor = DB.Column(
        DB.Integer,
        ForeignKey('utilisateurs.t_roles.id_role')
    )
    id_digitiser = DB.Column(
        DB.Integer,
        ForeignKey('utilisateurs.t_roles.id_role')
    )
    id_nomenclature_type_site = DB.Column(DB.Integer)
    base_site_name = DB.Column(DB.Unicode)
    base_site_description = DB.Column(DB.Unicode)
    base_site_code = DB.Column(DB.Unicode)
    first_use_date = DB.Column(DB.DateTime)
    geom = DB.Column(Geometry('GEOMETRY', 4326))
    uuid_base_site = DB.Column(
        UUID(as_uuid=True),
        default=select([func.uuid_generate_v4()])
    )

    digitiser = relationship("TRoles", foreign_keys=[id_digitiser])
    inventor = relationship("TRoles", foreign_keys=[id_digitiser])

    t_base_visits = relationship(
        "TBaseVisits",
        lazy='joined',
        cascade="all,delete-orphan"
    )

    applications = DB.relationship(
        'TApplications',
        secondary=corSiteApplication,
        primaryjoin=(
            corSiteApplication.c.id_base_site == id_base_site
        ),
        secondaryjoin=(
            corSiteApplication.c.id_application == TApplications.id_application
        ),
        foreign_keys=[
            corSiteApplication.c.id_base_site,
            corSiteApplication.c.id_application
        ]
    )

    def get_geofeature(self, recursif=True):
        return self.as_geofeature('geom_4326', 'id_base_site', recursif)
Ejemplo n.º 17
0
class Payment(BaseModel):
    __tablename__ = 'payment'
    TYPE = {1: 'paypal', 2: 'stripe'}
    payment_uuid = Column(String(36),
                          primary_key=True,
                          default=generate_uuid_str(),
                          server_default=func.uuid_generate_v4())
    user_uuid = Column(ForeignKey('user.user_uuid', ondelete='CASCADE'),
                       index=True)
    license_lrn_uuid = Column(ForeignKey('license_lrn.license_lrn_uuid',
                                         ondelete='CASCADE'),
                              nullable=True,
                              index=True)
    license_switch_uuid = Column(ForeignKey(
        'license_switch.license_switch_uuid', ondelete='CASCADE'),
                                 nullable=True,
                                 index=True)
    switch_uuid = Column(String(64), index=True)
    amount_lrn = Column(Numeric, nullable=False, server_default='0')
    amount_switch = Column(Numeric, nullable=False, server_default='0')
    #amount_total = Column(Numeric, nullable=False, server_default='0')
    paid_time = Column(DateTime(True),
                       nullable=False,
                       server_default=func.now())
    type = Column(ChoiceType(TYPE), default=1)
    description = Column(Text)

    user = relationship('User')

    amount_total = column_property(amount_lrn.op('+')(amount_switch))
    user_email = column_property(
        select([User.email
                ]).where(User.user_uuid == user_uuid).correlate_except(User))

    @property
    def license_uuid(self):
        if self.license_lrn_uuid:
            return self.license_lrn_uuid
        if self.license_switch_uuid:
            return self.license_switch_uuid
        return None

    @property
    def license(self):
        if self.license_lrn_uuid:
            return LicenseLrn.get(self.license_lrn_uuid)
        if self.license_switch_uuid:
            return LicenseSwitch.get(self.license_switch_uuid)
        return None

    def apply_mail(self, template_name):
        return _apply_mail(self, template_name, 'payment')
Ejemplo n.º 18
0
class Plan(BaseModel):
    __tablename__ = 'plan'
    TYPE = {
        1: 'switch pay per port',
        2: 'switch pay per minute',
        3: 'LRN pay per CPS',
        4: 'LRN pay per DIP'
    }
    plan_uuid = Column(String(36),
                       primary_key=True,
                       default=generate_uuid_str(),
                       server_default=func.uuid_generate_v4())

    type = Column(ChoiceType(TYPE), default=1)
    amount = Column(Numeric, nullable=False, server_default='0')
Ejemplo n.º 19
0
class Account(Base, Timestamp):
    """A bank account."""

    __tablename__ = 'accounts'

    id = Column(UUID(as_uuid=True), primary_key=True, server_default=func.uuid_generate_v4())
    iban = Column(String(34), nullable=False, unique=True, index=True)
    bic = Column(String(11), nullable=False, index=True)

    def __init__(self, iban: str, bic: str):
        self.iban = iban
        self.bic = bic

    def __repr__(self):
        return f"<Account {self.id} with IBAN {self.iban}>"
Ejemplo n.º 20
0
class Transaction(Base, Timestamp):
    """A single transaction."""

    __tablename__ = 'transactions'

    id = Column(UUID(as_uuid=True), primary_key=True, server_default=func.uuid_generate_v4())

    account_id = Column(UUID(as_uuid=True), ForeignKey('accounts.id'), nullable=False, index=True)
    account = relationship('Account', backref=backref('transctions', cascade='all, delete-orphan'))

    def __init__(self, iban, bic):
        self.iban = iban
        self.bic = bic

    def __repr__(self):
        return f"{self.iban} {self.bic}"
Ejemplo n.º 21
0
class CorCountingOccurrence(DB.Model):
    __tablename__ = "cor_counting_occtax"
    __table_args__ = {"schema": "pr_occtax"}
    id_counting_occtax = DB.Column(DB.Integer, primary_key=True)
    unique_id_sinp_occtax = DB.Column(UUID(as_uuid=True),
                                      default=select([func.uuid_generate_v4()
                                                      ]))
    id_occurrence_occtax = DB.Column(
        DB.Integer,
        ForeignKey("pr_occtax.t_occurrences_occtax.id_occurrence_occtax"))
    id_nomenclature_life_stage = DB.Column(DB.Integer)
    id_nomenclature_sex = DB.Column(DB.Integer)
    id_nomenclature_obj_count = DB.Column(DB.Integer)
    id_nomenclature_type_count = DB.Column(DB.Integer)
    count_min = DB.Column(DB.Integer)
    count_max = DB.Column(DB.Integer)
Ejemplo n.º 22
0
class User(db.Model):
    __tablename__ = 'users'
    __hiden_keys__ = ('password', )

    id = db.Column(UUID(),
                   primary_key=True,
                   default=uuid4,
                   server_default=func.uuid_generate_v4(),
                   comment='ID пользователя')  # noqa

    login = db.Column(db.String(),
                      nullable=False,
                      comment='Логин пользователя')  # noqa
    password = db.Column(db.LargeBinary(),
                         nullable=False,
                         comment='Пароль пользователя')  # noqa
Ejemplo n.º 23
0
class TOccurrencesOccurrence(DB.Model):
    __tablename__ = "t_occurrences_occtax"
    __table_args__ = {"schema": "pr_occtax"}
    id_occurrence_occtax = DB.Column(DB.Integer, primary_key=True)
    id_releve_occtax = DB.Column(
        DB.Integer, ForeignKey("pr_occtax.t_releves_occtax.id_releve_occtax"))
    id_nomenclature_obs_technique = DB.Column(DB.Integer)
    id_nomenclature_bio_condition = DB.Column(DB.Integer)
    id_nomenclature_bio_status = DB.Column(DB.Integer)
    id_nomenclature_naturalness = DB.Column(DB.Integer)
    id_nomenclature_exist_proof = DB.Column(DB.Integer)
    id_nomenclature_observation_status = DB.Column(DB.Integer)
    id_nomenclature_blurring = DB.Column(DB.Integer)
    id_nomenclature_source_status = DB.Column(DB.Integer)
    determiner = DB.Column(DB.Unicode)
    id_nomenclature_determination_method = DB.Column(DB.Integer)
    id_nomenclature_behaviour = DB.Column(DB.Integer)
    cd_nom = DB.Column(DB.Integer, ForeignKey(Taxref.cd_nom))
    nom_cite = DB.Column(DB.Unicode)
    meta_v_taxref = DB.Column(
        DB.Unicode,
        default=select(
            [func.gn_commons.get_default_parameter("taxref_version")]),
    )
    sample_number_proof = DB.Column(DB.Unicode)
    digital_proof = DB.Column(DB.Unicode)
    non_digital_proof = DB.Column(DB.Unicode)
    comment = DB.Column(DB.Unicode)

    #additional fields dans occtax MET 28/09/2020
    additional_fields = DB.Column(JSONB)

    unique_id_occurence_occtax = DB.Column(
        UUID(as_uuid=True),
        default=select([func.uuid_generate_v4()]),
    )
    cor_counting_occtax = relationship(
        "CorCountingOccurrence",
        lazy="joined",
        cascade="all,delete-orphan",
        uselist=True,
        backref=DB.backref("occurence", lazy="joined"),
    )

    taxref = relationship(Taxref, lazy="joined")

    readonly_fields = ["id_occurrence_occtax", "id_releve_occtax", "taxref"]
Ejemplo n.º 24
0
class Notification(BaseModel, ModelUsingFiles):
    __tablename__ = 'notification'

    notification_uuid = Column(String(36),
                               primary_key=True,
                               default=generate_uuid_str(),
                               server_default=func.uuid_generate_v4())
    user_uuid = Column(ForeignKey('user.user_uuid', ondelete='CASCADE'),
                       nullable=True,
                       index=True)

    subject = Column(String(64), nullable=False)
    content = Column(Text, nullable=False)
    created_on = Column(DateTime(True),
                        nullable=False,
                        server_default=func.now())
    user = relationship('User')
Ejemplo n.º 25
0
class BaseModel(db.Model):
    __abstract__ = True

    id = db.Column(UUID(),
                   primary_key=True,
                   default=uuid4,
                   server_default=func.uuid_generate_v4(),
                   comment='ID')
    create_datetime = db.Column(db.DateTime(),
                                nullable=False,
                                default=datetime.utcnow,
                                server_default=func.now(),
                                comment='UTC create datetime')
    update_datetime = db.Column(db.DateTime(),
                                nullable=False,
                                default=datetime.utcnow,
                                server_default=func.now(),
                                comment='UTC update datetime')
Ejemplo n.º 26
0
def pk(*foreign_key_column_names: str) -> sa.Column:
    """A UUID primary key.

    Return a standard primary key of type UUID for use in models. If the
    any foreign_key_column_names are supplied, the primary key will
    reference the given columns.

    :param foreign_key_column_names: column names of the referenced foreign
                                    keys (should be 'table_name.column_name')
    :return: a SQLAlchemy Column for a UUID primary key.
    """
    args = [pg.UUID]
    args.extend(map(fk, foreign_key_column_names))
    kwargs = {
        'primary_key': True,
        'server_default': func.uuid_generate_v4(),
    }
    return sa.Column(*args, **kwargs)
Ejemplo n.º 27
0
class PackageLrn(BaseModel):
    __tablename__ = 'package_lrn'
    TYPE = {3: 'LRN pay per CPS', 4: 'LRN pay per DIP'}
    package_lrn_uuid = Column \
        (String(36), primary_key=True, default=generate_uuid_str(),
         server_default=func.uuid_generate_v4())
    package_name = Column(String(64), unique=True)
    cps = Column(Integer())
    type = Column(ChoiceType(TYPE), default=3)
    lrn_port = Column(Integer())
    dip_count = Column(Integer())
    amount = Column(Integer())
    enabled = Column(Boolean, default=True)
    licenses = relationship('LicenseLrn',
                            uselist=True,
                            back_populates='package')
    create_on = Column(DateTime(True),
                       nullable=True,
                       server_default=func.now())
Ejemplo n.º 28
0
def upgrade():
    op.create_table(
        'downloads',
        sa.Column('id',
                  postgresql.UUID(),
                  server_default=func.uuid_generate_v4(),
                  nullable=False),
        sa.Column('package_name', sa.UnicodeText(), nullable=False),
        sa.Column('package_version', sa.UnicodeText(), nullable=True),
        sa.Column('distribution_type',
                  sa.Enum(u'sdist',
                          u'wheel',
                          u'exe',
                          u'egg',
                          u'msi',
                          name='distribution_type'),
                  nullable=True),
        sa.Column('python_type',
                  sa.Enum(u'cpython',
                          u'pypy',
                          u'jython',
                          u'ironpython',
                          name='python_type'),
                  nullable=True),
        sa.Column('python_release', sa.Text(), nullable=True),
        sa.Column('python_version', sa.Text(), nullable=True),
        sa.Column('installer_type',
                  sa.Enum(u'browser',
                          u'pip',
                          u'setuptools',
                          u'distribute',
                          u'bandersnatch',
                          u'z3c.pypimirror',
                          u'pep381client',
                          name='installer_type'),
                  nullable=True),
        sa.Column('installer_version', sa.Text(), nullable=True),
        sa.Column('operating_system', sa.Text(), nullable=True),
        sa.Column('operating_system_version', sa.Text(), nullable=True),
        sa.Column('download_time', sa.DateTime(), nullable=False),
        sa.Column('raw_user_agent', sa.Text(), nullable=False),
        sa.PrimaryKeyConstraint('id'))
Ejemplo n.º 29
0
class Bib_Organismes(GenericRepository):
    """
    Model de la table Bib_Organismes

    """
    __tablename__ = 'bib_organismes'
    __table_args__ = {'schema': 'utilisateurs'}
    id_organisme = db.Column(db.Integer, primary_key=True)
    uuid_organisme = db.Column(UUID(as_uuid=True),
                               default=select([func.uuid_generate_v4()]))
    nom_organisme = db.Column(db.Unicode)
    adresse_organisme = db.Column(db.Unicode)
    cp_organisme = db.Column(db.Unicode)
    ville_organisme = db.Column(db.Unicode)
    tel_organisme = db.Column(db.Unicode)
    fax_organisme = db.Column(db.Unicode)
    email_organisme = db.Column(db.Unicode)
    url_organisme = db.Column(db.Unicode)
    url_logo = db.Column(db.Unicode)
    id_parent = db.Column(db.Integer)
Ejemplo n.º 30
0
class corRoleRelevesOccurrence(DB.Model):
    __tablename__ = "cor_role_releves_occtax"
    __table_args__ = {"schema": "pr_occtax"}
    unique_id_cor_role_releve = DB.Column(
        "unique_id_cor_role_releve",
        UUID(as_uuid=True),
        default=select([func.uuid_generate_v4()]),
        primary_key=True,
    )
    id_releve_occtax = DB.Column(
        "id_releve_occtax",
        DB.Integer,
        ForeignKey("pr_occtax.t_releves_occtax.id_releve_occtax"),
        primary_key=False,
    )
    id_role = DB.Column(
        "id_role",
        DB.Integer,
        ForeignKey("utilisateurs.t_roles.id_role"),
        primary_key=False,
    )
Ejemplo n.º 31
0
class Balance(Base, Timestamp):
    """An immutable account balance at a certain point in time.

    Account balances may not be updated once they are created.
    """

    __tablename__ = 'balances'

    id = Column(UUID(as_uuid=True), primary_key=True, server_default=func.uuid_generate_v4())
    balance = Column(Numeric(), nullable=False, index=True)
    currency = Column(String(3), nullable=False, index=True)

    account_id = Column(UUID(as_uuid=True), ForeignKey('accounts.id'), nullable=False, index=True)
    account = relationship('Account', backref=backref('balances', cascade='all, delete-orphan'))

    def __init__(self, balance: str, currency: str, account: Account):
        self.balance = Decimal(balance)
        self.currency = currency
        self.account = account

    def __repr__(self):
        return f"<Balance {self.id} at {self.created_at} ({self.balance} {self.currency})"
Ejemplo n.º 32
0
class THabitatsOcchab(DB.Model):
    __tablename__ = "t_habitats"
    __table_args__ = {"schema": "pr_occhab"}
    id_habitat = DB.Column(DB.Integer, primary_key=True)
    id_station = DB.Column(DB.Integer,
                           ForeignKey("pr_occhab.t_stations.id_station"))
    unique_id_sinp_hab = DB.Column(UUID(as_uuid=True),
                                   default=select([func.uuid_generate_v4()]))
    cd_hab = DB.Column(DB.Integer, ForeignKey('ref_habitats.habref.cd_hab'))
    nom_cite = DB.Column(DB.Unicode)
    id_nomenclature_determination_type = DB.Column(
        DB.Integer, ForeignKey(TNomenclatures.id_nomenclature))
    determiner = DB.Column(DB.Unicode)
    id_nomenclature_collection_technique = DB.Column(
        DB.Integer, ForeignKey(TNomenclatures.id_nomenclature))
    recovery_percentage = DB.Column(DB.Float)
    id_nomenclature_abundance = DB.Column(
        DB.Integer, ForeignKey(TNomenclatures.id_nomenclature))
    technical_precision = DB.Column(DB.Unicode)
    id_nomenclature_sensitvity = DB.Column(DB.Integer)

    habref = DB.relationship("Habref", lazy="joined")
Ejemplo n.º 33
0
            - user : a TRole object
            - user_cruved: object return by cruved_for_user_in_app(user)
        """
        return {
            action: self.user_is_allowed_to(user, level)
            for action, level in user_cruved.items()
        }


corRoleRelevesOccurrence = DB.Table(
    "cor_role_releves_occtax",
    DB.MetaData(schema="pr_occtax"),
    DB.Column(
        "unique_id_cor_role_releve",
        UUID(as_uuid=True),
        default=select([func.uuid_generate_v4()]),
        primary_key=True,
    ),
    DB.Column(
        "id_releve_occtax",
        DB.Integer,
        ForeignKey("pr_occtax.t_releves_occtax.id_releve_occtax"),
        primary_key=False,
    ),
    DB.Column(
        "id_role",
        DB.Integer,
        ForeignKey("utilisateurs.t_roles.id_role"),
        primary_key=False,
    ),
)