Ejemplo n.º 1
0
class HttpPlayback(Base):
    __tablename__ = "HttpPlayback"

    id = Column(Integer, primary_key=True, autoincrement=True)
    timestamp = Column(BigInteger, nullable=False)
    url = Column(Text, index=True, nullable=False)
    method = Column(SQLEnum(HttpRequestMethod), nullable=False)
    request_type = Column(SQLEnum(HttpRequestType), nullable=False)
    request_params = Column(JSON)
    request_json = Column(JSON)
    response_type = Column(SQLEnum(HttpResponseType), nullable=False)
    response_code = Column(Integer, nullable=False)
    response_text = Column(Text)
    response_json = Column(JSON)
Ejemplo n.º 2
0
class Tournament(db.Model):
    __tablename__ = 'tournaments'

    id = Column(Integer, primary_key=True)
    title = Column(String(1024), nullable=False)
    logo = Column(String(1024))
    discipline = Column(String(256), nullable=False)
    discipline_type = Column(SQLEnum(DisciplineType), nullable=False)
    type = Column(SQLEnum(TournamentType), nullable=False)
    start_time = Column(DateTime, nullable=False)
    state = Column(SQLEnum(TournamentState), nullable=False)
    sequence = Column(String(4096))

    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    creator = relationship('User', backref=backref('organized'))
Ejemplo n.º 3
0
class IndividualPlan(Base):
    __tablename__ = 'individual_plans'

    @classmethod
    def create_monthly(
        cls,
        name: PlanName,
        fee: Money,
        max_no_of_pauses: int,
    ) -> 'IndividualPlan':
        return IndividualPlan(
            name=name,
            status=Status.Deactivated,
            fee_amount=fee.amount,
            fee_currency=fee.currency,
            max_no_of_pauses=max_no_of_pauses,
            renewal=Renewal.Month,
        )

    id = Column(UUIDType(binary=True), primary_key=True, default=uuid1)
    name: PlanName = Column(
        String(100),
        nullable=False,
        index=True,
        unique=True,
    )
    status: Status = Column(
        SQLEnum(Status, create_constraint=False, native_enum=False),
        nullable=False,
    )
    max_no_of_pauses = Column(Integer, nullable=False)
    fee_amount: Decimal = Column(Float(asdecimal=True), nullable=False)
    fee_currency: Currency = Column(CurrencyType, nullable=False)
    renewal: Renewal = Column(
        SQLEnum(Renewal, create_constraint=False, native_enum=False),
        nullable=False,
    )
    when_created = Column(DateTime, nullable=False, default=datetime.utcnow)
    when_updated = Column(DateTime, nullable=True, onupdate=datetime.utcnow)

    def activate(self) -> None:
        self.status = Status.Activated

    def deactivate(self) -> None:
        self.status = Status.Deactivated

    def is_active(self) -> bool:
        return self.status == Status.Activated
Ejemplo n.º 4
0
class Activity(AbstractPassing, Base):
    __tablename__ = 'activities'
    idx = Column(Integer, primary_key=True)
    activity = Column(SQLEnum(ActivityEnum), nullable=False)  # could be enum
    groupIdx = Column(Integer, ForeignKey('groups.idx'))
    # can an activity be done in a vehicle? Is it relevant? Can it be unambiguously identified?
    startTime = Column(DateTime)
    endTime = Column(DateTime)
    zoneIdx = Column(Integer, ForeignKey('zones.idx'))
    pointIdx = Column(Integer, ForeignKey('points.idx'))

    group = relationship('Group')
    zone = relationship('Zone')
    point = relationship('Point')

    def __init__(self,
                 startTime,
                 endTime,
                 zone,
                 activity='unknown',
                 p=None,
                 group=None,
                 person=None,
                 transport=None,
                 vehicle=None):
        self.activity = activity
        self.startTime = startTime
        self.endTime = endTime
        self.zone = zone
        self.point = p
        self.initPersonGroupPassing(group, person, transport, vehicle)
Ejemplo n.º 5
0
class Mode(Base):
    'personal, because in a group (family), some might have a scooter or rollers'
    __tablename__ = 'modes'
    idx = Column(Integer, primary_key=True)
    personIdx = Column(Integer, ForeignKey('persons.idx'))
    vehicleIdx = Column(Integer, ForeignKey('vehicles.idx'))
    transport = Column(SQLEnum(ModeEnum), nullable=False)
    startTime = Column(DateTime)  # None first time if only one group
    pointIdx = Column(Integer, ForeignKey('points.idx'))

    person = relationship('Person', backref=backref('modes'))
    vehicle = relationship('Vehicle')
    point = relationship('Point')

    def __init__(self,
                 transport,
                 person,
                 vehicle=None,
                 startTime=None,
                 p=None):
        self.person = person
        self.transport = transport
        self.vehicle = vehicle
        self.startTime = startTime
        self.point = p

    @staticmethod
    def initGroup(transport, group, vehicle=None, startTime=None):
        return [Mode(transport, p, startTime) for p in group.getPersons()]
Ejemplo n.º 6
0
class Person(Base):
    __tablename__ = 'persons'
    idx = Column(Integer, primary_key=True)
    # groupIdx = Column(Integer, ForeignKey('groups.idx'))
    age = Column(SQLEnum(AgeEnum), nullable=True)
    gender = Column(SQLEnum(GenderEnum), nullable=False)
    disability = Column(
        Boolean
    )  #Column(SQLEnum(DisabilityEnum), nullable=True)  # could be enum
    stroller = Column(
        Boolean
    )  # the booleans could be strings or enum to have more information
    bag = Column(Boolean)
    animal = Column(Boolean)

    # group = relationship('Group', backref = backref('persons'))

    def __init__(self,
                 age='unknown',
                 gender='unknown',
                 disability=False,
                 stroller=False,
                 bag=False,
                 animal=False):
        self.age = age
        self.gender = gender
        self.disability = disability
        self.stroller = stroller
        self.bag = bag
        self.animal = animal

    def getAgeNum(self):
        if str.isnumeric(self.age):
            return int(self.age)
        elif '.' in self.age:
            try:
                return float(self.age)
            except ValueError:
                pass
        else:
            return self.age

    def getGroups(self):
        if len(self.groupBelongings) > 0:
            return [gb.group for gb in self.groupBelongings]
        else:
            return None
Ejemplo n.º 7
0
class DataCollector(Base):
    __tablename__ = "data_collector"
    id = Column(BigIntegerType, primary_key=True, autoincrement=True)
    data_collector_type_id = Column(BigIntegerType,
                                    ForeignKey("data_collector_type.id"),
                                    nullable=False)
    type = relationship("DataCollectorType", lazy="joined")
    policy = relationship("Policy", lazy="joined")
    name = Column(String(120), nullable=False)
    organization_id = Column(BigIntegerType,
                             ForeignKey("organization.id"),
                             nullable=True)
    created_at = Column(DateTime(timezone=True), nullable=False)
    ip = Column(String(120), nullable=False)
    port = Column(String(120), nullable=False)
    user = Column(String(120), nullable=True)
    password = Column(String(120), nullable=False)
    ssl = Column(Boolean, nullable=False)
    organization_id = Column(BigInteger,
                             ForeignKey("organization.id"),
                             nullable=False)
    policy_id = Column(BigInteger, ForeignKey("policy.id"), nullable=False)
    deleted_at = Column(DateTime(timezone=True), nullable=True)
    status = Column(SQLEnum(DataCollectorStatus))

    @classmethod
    def find_one_by_ip_port_and_dctype_id(cls, dctype_id, ip, port):
        return session.query(cls).filter(cls.ip == ip).filter(
            cls.data_collector_type_id == dctype_id).filter(
                cls.port == port).first()

    @classmethod
    def find_one_by_name_and_dctype_id(cls, dctype_id, name):
        return session.query(cls).filter(
            cls.data_collector_type_id == dctype_id, cls.name == name).first()

    @classmethod
    def get(cls, id):
        return session.query(cls).get(id)

    @classmethod
    def count(cls):
        return session.query(func.count(cls.id)).scalar()

    @classmethod
    def number_of_devices(cls, data_collector_id):
        ndev = session.query(Device.dev_eui).\
                filter(not_(Device.pending_first_connection)).\
                filter(Device.data_collector_id == data_collector_id).\
                distinct().count()
        return ndev

    def is_ttn(self):
        return self.type.type == 'ttn_collector'

    def save(self):
        session.add(self)
        session.flush()
        commit()
Ejemplo n.º 8
0
class SilegLog(Base):

    __tablename__ = 'sileg_log'

    type = Column(SQLEnum(SilegLogTypes))
    entity_id = Column(String)
    authorizer_id = Column(String)
    data = Column(String)
Ejemplo n.º 9
0
class Phone(Base):

    __tablename__ = 'phones'

    number = Column(String)
    type = Column(SQLEnum(PhoneTypes))

    user_id = Column(String, ForeignKey('users.id'))
Ejemplo n.º 10
0
class Mail(Base):

    __tablename__ = 'mails'

    type = Column(SQLEnum(MailTypes))
    email = Column(String)
    confirmed = Column(DateTime())
    user_id = Column(String, ForeignKey('users.id'))
Ejemplo n.º 11
0
class UsersLog(Base):

    __tablename__ = 'users_log'

    type = Column(SQLEnum(UserLogTypes))
    entity_id = Column(String)
    authorizer_id = Column(String)
    data = Column(String)
Ejemplo n.º 12
0
class IssueMixin:
    """Generic attributes that are shared by issues and PRs."""

    number = Column(String, primary_key=True)
    opened = Column(DateTime, nullable=False)
    closed = Column(DateTime)
    labels = Column(postgresql.ARRAY(String), nullable=False, default=[])
    author_association = Column(SQLEnum(AuthorAssociation), nullable=False)
Ejemplo n.º 13
0
class Vehicle(Base):
    __tablename__ = 'vehicles'
    idx = Column(Integer, primary_key=True)
    category = Column(SQLEnum(VehicleEnum), nullable=False)
    trailer = Column(Boolean)

    def __init__(self, category, trailer=False):
        self.category = category
        self.trailer = trailer
Ejemplo n.º 14
0
class Note(Base, DictMixin):
    __tablename__ = 'notes'

    id = Column(Integer, primary_key=True)
    title = Column(String(128))
    keys_str = Column(String(128))
    text = Column(String(2048))
    category = Column(SQLEnum(NoteCategory))
    note_type = Column(SQLEnum(NoteType))
    _code_lexer = Column(Integer, default=None)

    @property
    def keys(self):
        return self.keys_str

    @keys.getter
    def keys(self):
        if self.keys_str:
            return self.keys_str.split(",")
        else:
            return None

    @keys.setter
    def keys(self, kbd_keys: List[str]):
        self.keys_str = ",".join(kbd_keys)

    @property
    def code_lexer(self) -> Optional[str]:
        return self._code_lexer

    @code_lexer.getter
    def code_lexer(self):
        if self._code_lexer:
            try:
                return get_lexer_by_name(self._code_lexer)
            except ClassNotFound as e:
                logger.exception(e)
                return get_lexer_by_name("Python")

        return None

    @code_lexer.setter
    def code_lexer(self, value):
        self._code_lexer = value
Ejemplo n.º 15
0
class Function(Base):

    __tablename__ = 'functions'

    name = Column(String)
    type = Column(SQLEnum(FunctionTypes))
    description = Column(String)
    level = Column(Integer)

    """
Ejemplo n.º 16
0
class Phone(Base):

    __tablename__ = 'phones'
    
    id = Column(String, primary_key=True)
    created = Column(DateTime)
    deleted = Column(DateTime)

    number = Column(String)
    type = Column(SQLEnum(PhoneTypes))
    person_id = Column(String, ForeignKey('persons.id'))
Ejemplo n.º 17
0
class IdentityNumber(Base):

    __tablename__ = 'identity_numbers'

    type = Column(SQLEnum(IdentityNumberTypes))
    number = Column(String)

    user_id = Column(String, ForeignKey('users.id'))

    file_id = Column(String, ForeignKey('files.id'))
    file = relationship('File')
Ejemplo n.º 18
0
class Degree(Base):

    __tablename__ = 'degree'

    type = Column(SQLEnum(DegreeTypes))
    title = Column(String)
    start = Column(DateTime)

    person_id = Column(String, ForeignKey('persons.id'))

    file_id = Column(String, ForeignKey('files.id'))
    file = relationship('File')
Ejemplo n.º 19
0
class Book(Base):
    required = {'format': str, 'title': str, 'contributors': dict}

    __tablename__ = 'book'
    id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
    sha256 = Column(String(64), nullable=False, unique=True)
    cataloguing = Column(String(255), nullable=False)
    title = Column(String(255), nullable=False)
    isbn = Column(String(20))
    year = Column(String(4))
    language = Column(String(5))
    format = Column(SQLEnum(BookFormat), nullable=False)
    contributors = relationship("BookContributor", back_populates="book")

    @classmethod
    def maker(cls, data: dict):
        book_format = BookFormat.parse(data['format'])
        raw_title = data['title']
        clean_title = authority.title(raw_title)
        ordering_title = authority.ordering_title(raw_title)
        return Book(
            title=clean_title,
            cataloguing=ordering_title,
            format=book_format,
            # sha256
            isbn=data['isbn'] if 'isbn' in data else None,
            year=data['year'] if 'year' in data else None,
            language=data['language'] if 'language' in data else None)

    def generate_sha256(self):
        unique_key = self.title + "|" \
                     + self.format.name + "|" \
                     + "-".join([c.contributor.sha256 for c in self.contributors])
        self.sha256 = authority.sha56(unique_key)

    def json(self):
        return {
            k: self._for_json(k)
            for k in self.__dir__()
            if k in ('id', 'sha256', 'cataloguing', 'title', 'isbn', 'year',
                     'language', 'format', 'contributors')
        }

    def _for_json(self, attribute: str):
        value = getattr(self, attribute)
        if attribute == 'format':
            return value.name
        if attribute == 'contributors':
            return [c.contributor_json() for c in value]
        return value

    def __repr__(self):
        return f"<Book(cataloguing='{self.cataloguing}', title='{self.title}', format='{self.format.name}'>"
Ejemplo n.º 20
0
class PullRequest(Base, IssueMixin):
    """A GitHub Pull Request."""

    __tablename__ = "pull_request"

    author = Column(ForeignKey("user.id"), nullable=False)
    changed_files = Column(Integer, nullable=False)
    additions = Column(Integer, nullable=False)
    deletions = Column(Integer, nullable=False)
    total_commits = Column(Integer, nullable=False)
    status = Column(SQLEnum(StatusCheckStatus), nullable=False)
    merged = Column(Boolean)
Ejemplo n.º 21
0
class Line(Base):
    __tablename__ = 'lines'
    idx = Column(Integer, primary_key=True)
    name = Column(String)
    type = Column(SQLEnum(LineTypeEnum), nullable=True)
    # define lines for access counting: add type? - AccessLine?

    points = relationship('Point', secondary=pointLineAssociation)

    def __init__(self, name, type, x1, y1, x2, y2):
        self.name = name
        self.points = [Point(x1, y1), Point(x2, y2)]
Ejemplo n.º 22
0
class Mail(Base):

    __tablename__ = 'mails'

    id = Column(String, primary_key=True)
    created = Column(DateTime)
    deleted = Column(DateTime)

    type = Column(SQLEnum(MailTypes))
    email = Column(String)
    confirmed = Column(DateTime()) 
    person_id = Column(String, ForeignKey('persons.id'))
class DeviceCounters(db.Model):
    __tablename__ = 'device_counters'
    device_id = Column(BigInteger,
                       ForeignKey("device.id"),
                       nullable=False,
                       primary_key=True)
    counter_type = Column(SQLEnum(CounterType),
                          nullable=False,
                          primary_key=True)
    hour_of_day = Column(Integer, nullable=False, primary_key=True)
    value = Column(BigInteger, nullable=False, default=0)
    last_update = Column(DateTime(timezone=True), nullable=False)
Ejemplo n.º 24
0
class PersonalLeaveLicense(Base):

    __tablename__ = 'personal_leave_licenses'

    user_id = Column(String)
    license_id = Column(String, ForeignKey('personal_leave_licenses.id'))

    type = Column(SQLEnum(LicenseTypes))

    start = Column(Date)
    end = Column(Date)
    end_type = Column(SQLEnum(LicenseEndTypes))

    historic = Column(Boolean, default=False)

    exp = Column(String)
    res = Column(String)
    cor = Column(String)

    comments = Column(String)
    perceive_salary = Column(Boolean, default=False)
Ejemplo n.º 25
0
class Card(Base):

    __tablename__ = 'cards'

    id = Column(String, primary_key=True)
    created = Column(DateTime)
    deleted = Column(DateTime)

    person_id = Column(String, ForeignKey('persons.id'))
    type = Column(SQLEnum(CardTypes))
    number = Column(String)
    code = Column(String)
    brand = Column(String)
Ejemplo n.º 26
0
class IdentityNumber(Base):

    __tablename__ = 'identity_numbers'

    id = Column(String, primary_key=True)
    created = Column(DateTime)
    deleted = Column(DateTime)

    type = Column(SQLEnum(IdentityNumberTypes))
    number = Column(String)
    person_id = Column(String, ForeignKey('persons.id'))

    file_id = Column(String, ForeignKey('files.id'))
    file = relationship('File')
Ejemplo n.º 27
0
class DataCollector(Base):
    __tablename__ = "data_collector"
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    data_collector_type_id = Column(BigInteger,
                                    ForeignKey("data_collector_type.id"),
                                    nullable=False)
    name = Column(String(120), nullable=False)
    description = Column(String(1000), nullable=False)
    created_at = Column(DateTime(timezone=True), nullable=False)
    ip = Column(String(120), nullable=True)
    port = Column(String(120), nullable=True)
    user = Column(String(120), nullable=False)
    password = Column(String(120), nullable=False)
    ssl = Column(Boolean, nullable=True)
    ca_cert = Column(Text, nullable=True)
    client_cert = Column(Text, nullable=True)
    client_key = Column(Text, nullable=True)
    gateway_id = Column(String(100), nullable=True)
    organization_id = Column(BigInteger,
                             ForeignKey("organization.id"),
                             nullable=False)
    policy_id = Column(BigInteger, ForeignKey("policy.id"), nullable=False)
    deleted_at = Column(DateTime(timezone=True), nullable=True)
    status = Column(SQLEnum(DataCollectorStatus))
    verified = Column(Boolean, nullable=False, default=False)

    @classmethod
    def find_one_by_ip_port_and_dctype_id(cls, dctype_id, ip, port):
        return session.query(cls).filter(cls.ip == ip).filter(
            cls.data_collector_type_id == dctype_id).filter(
                cls.port == port).first()

    @classmethod
    def find_one(cls, id=None):
        query = session.query(cls)

        if id:
            query = query.filter(cls.id == id)

        return query.first()

    @classmethod
    def count(cls):
        return session.query(func.count(cls.id)).scalar()

    def save(self):
        session.add(self)
        session.flush()
        session.commit()
Ejemplo n.º 28
0
class DesignationLeaveLicense(Base):

    __tablename__ = 'designation_leave_licenses'

    designation_id = Column(String, ForeignKey('designations.id'))
    designation = relationship('Designation', foreign_keys=[designation_id])

    license_id = Column(String, ForeignKey('designation_leave_licenses.id'))

    start = Column(Date)
    end = Column(Date)
    end_type = Column(SQLEnum(LicenseEndTypes))

    historic = Column(Boolean, default=False)

    exp = Column(String)
    res = Column(String)
    cor = Column(String)

    type = Column(SQLEnum(LicenseTypes))

    comments = Column(String)

    perceive_salary = Column(Boolean, default=False)
class Kid(db.Model):
    __tablename__ = 'kids'
    id = Column(Integer, primary_key=True)
    phone_number = Column(String(12), unique=True)
    account_id = Column(String(128), unique=True, nullable=False)
    name = Column(String(256), nullable=False)
    birth_date = Column(String(12), nullable=False)
    goal = Column(String(1024))
    points = Column(Integer, nullable=False, default=100)
    avatar = Column(String(512))
    mentorship = Column(SQLEnum(MentorshipState),
                        nullable=False,
                        default=MentorshipState.not_enough_points)
    tasks = relationship('Task')
    interests = relationship('Tag', secondary='interests')
    likes = relationship('Mentor', secondary='likes')
Ejemplo n.º 30
0
class Team(db.Model):
    __tablename__ = 'teams'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    tournament_id = Column(Integer,
                           ForeignKey('tournaments.id'),
                           nullable=False)
    state = Column(SQLEnum(TeamState),
                   nullable=False,
                   default=TeamState.registered)
    title = Column(String)
    place = Column(Integer)

    captain = relationship('User', backref=backref('c_teams'))
    tournament = relationship('Tournament', backref=backref('participants'))
    players = relationship('User', secondary=players, backref=backref('teams'))