Пример #1
0
class Host(db.Entity):
    ip = orm.PrimaryKey(str)
    name = orm.Optional(str)
    isup = orm.Optional(bool)
    os = orm.Optional(str)
    os_acc = orm.Optional(int)
    ports = orm.Optional(orm.IntArray)
    services = orm.Set("Service")
    initial_scan = orm.Optional(datetime)
    last_scan = orm.Optional(datetime)
    notes = orm.Optional(orm.LongStr)
Пример #2
0
class BalanceRecord(db.Entity):
    ID = po.PrimaryKey(int, auto=True)
    time = po.Required(datetime, default=datetime.utcnow(), unique=True)
    farm_event = po.Optional(bool, default=False)
    starting_balance = po.Optional(int)
    win_status = po.Optional(bool)
    bet_amt = po.Optional(int)
    bet_side = po.Optional(str)
    favored_side = po.Optional(str)
    bet_ratio = po.Optional(float)
    new_balance = po.Optional(int)
Пример #3
0
class Person(db.Entity):
    name = orm.Required(str, 40)
    lastName = orm.Required(str, max_len=40, unique=True)
    age = orm.Optional(int, max=60, min=10)
    nickName = orm.Optional(str, autostrip=False)
    middleName = orm.Optional(str, nullable=True)
    rate = orm.Optional(Decimal, precision=11)
    salaryRate = orm.Optional(Decimal, precision=13, scale=8)
    timeStmp = orm.Optional(datetime, precision=6)
    gpa = orm.Optional(float, py_check=lambda val: val >= 0 and val <= 5)
    vehicle = orm.Optional(str, column='car')
Пример #4
0
class Article(db.Entity):
    document = orm.Required("Document")

    title = orm.Required(str)
    abstract_path = orm.Required(str)
    processed_abstract_path = orm.Required(str)
    words_count = orm.Required(int)
    link_to_pdf = orm.Optional(str)
    authors = orm.Set("Author")
    date = orm.Required(datetime.datetime)
Пример #5
0
class CommandLog(db.Entity):
    command = orm.Required(str)
    param = orm.Optional(str, default='')

    # Use str here because pony uses str() to convert datetime before insert.
    # That puts datetime in wrong format to DB.
    ts = orm.Required(str, default=lambda: arrow.utcnow().isoformat())

    def ts_local(self):
        return arrow.get(self.ts).to(config.TIMEZONE)
Пример #6
0
class Post(db.Entity):
    id = p.PrimaryKey(int, auto=True)
    title = p.Required(str)
    description = p.Required(str, 1000)
    created = p.Optional(datetime, default=lambda: datetime.now())
    user = p.Required('User')

    def __str__(self):
        return f'<Post(id={self.id}, title={self.title}, description={self.description}, ' \
               f'created={self.created}, user={self.user})>'
Пример #7
0
class User(db.Entity):
    id = p.PrimaryKey(int, auto=True)
    username = p.Required(str)
    password = p.Required(str, 1000, unique=True)
    created = p.Optional(datetime, default=lambda: datetime.now())
    posts = p.Set(Post)

    def __str__(self):
        return f'<User(id={self.id}, username={self.username}, ' \
               f'password={self.password}, created={self.created})>'
Пример #8
0
class Chat(db.Entity):
    _table_ = 'chats'
    id = orm.PrimaryKey(int, auto=True)
    telegram_id = orm.Required(str, unique=True)
    main = orm.Required(int)
    active = orm.Required(int)
    name = orm.Optional(str)
    topics = orm.Set(lambda: Topic,
                     table='topics_for_chats',
                     column='topic_id')
Пример #9
0
class Zaubertricks(db.Entity):
    url = orm.PrimaryKey(str)
    Titel = orm.Required(str)
    Wirkung = orm.Required(str)
    Reichweite = orm.Required(str)
    Wirkungsdauer = orm.Required(str)
    Zielkategorie = orm.Required(str)
    Merkmal = orm.Required(str)
    Anmerkung = orm.Optional(str)
    Publikation = orm.Required(str)
Пример #10
0
    class ChannelPeer(db.Entity):
        """
        This binding stores public keys of IPv8 peers that sent us some GigaChannel data. It is used by the
        voting system.
        """

        rowid = orm.PrimaryKey(int, size=64, auto=True)
        public_key = orm.Required(bytes, unique=True)
        individual_votes = orm.Set("ChannelVote", reverse='voter')
        added_on = orm.Optional(datetime, default=datetime.utcnow)
Пример #11
0
class Project(Database.ODB.Entity):
    ID = orm.PrimaryKey(str)
    Title = orm.Required(str)
    Description = orm.Required(str)
    DateTime = orm.Required(str)
    Workflow = orm.Optional(orm.Json)
    Input = orm.Set("Input", cascade_delete=True)
    Analyzer = orm.Set("Analyzer", cascade_delete=True)
    Translator = orm.Set("Translator", cascade_delete=True)
    Output = orm.Set("Output", cascade_delete=True)
Пример #12
0
class KeyExchangeResponses(db.Entity):
    _table_ = ('public', 'KeyExchangeResponses')
    KeyExchangeResponseID = orm.PrimaryKey(int, auto=True)
    KeyExchangeRequestID = orm.Required("KeyExchangeRequests",
                                        reverse="KeyExchangeReq")
    MessageType = orm.Required(int)  # ISO-2
    SecondBitmap = orm.Required(bytes)  # P-1
    TransServiceID = orm.Required("TransServices",
                                  reverse="KeyExchangeResponseService")  # P-3
    TransmissionDateTime = orm.Required(str)  # P-7
    STAN = orm.Required(str)  # P-11
    LocalTransactionTime = orm.Required(str)  # P-12
    LocalTransactionDate = orm.Required(str)  # P-13
    FunctionCode = orm.Required(int)  # P-24
    AcquiringInstitutionIdentificationCode = orm.Optional(int)  # P-32
    ResponseCode = orm.Optional(int)  # P-39
    CardAcceptor = orm.Optional(int)  # P-41
    CardAcceptorCode = orm.Optional(int)  # P-42
    AddtionalData = orm.Optional(int)  # P-48
Пример #13
0
class Book(db.Entity):
    # Required field
    title = orm.Required(str)

    # Optional field (NULL is OK)
    num_pages = orm.Optional(int)

    # This defines the other half of the relationship between entities
    # (Note that the argument (data type) is the name of the other class)
    author = orm.Required(Author)
Пример #14
0
    class MetadataNode(db.ChannelNode):
        """
        This ORM class extends ChannelNode by adding metadata-storing attributes such as "title" and "tags".
        It implements methods for indexed text search based on the "title" field.
        It is not intended for direct use. Instead, other classes should derive from it.
        """

        _discriminator_ = METADATA_NODE

        # Serializable
        title = orm.Optional(str, default='')
        tags = orm.Optional(str, default='')

        # ACHTUNG! PONY BUG! This is a workaround for Pony not caching attributes from multiple inheritance!
        # Its real home is CollectionNode, but we are forced to put it here so it is loaded by default on all queries.
        # When Pony fixes it, we must move it back to CollectionNode for clarity.
        num_entries = orm.Optional(int, size=64, default=0)

        # Special class-level properties
        _payload_class = MetadataNodePayload
        payload_arguments = _payload_class.__init__.__code__.co_varnames[:
                                                                         _payload_class
                                                                         .
                                                                         __init__
                                                                         .
                                                                         __code__
                                                                         .
                                                                         co_argcount][
                                                                             1:]
        nonpersonal_attributes = db.ChannelNode.nonpersonal_attributes + (
            'title', 'tags')

        def to_simple_dict(self):
            """
            Return a basic dictionary with information about the channel.
            """
            simple_dict = super().to_simple_dict()
            simple_dict.update({
                "name": self.title,
                "category": self.tags,
            })

            return simple_dict
Пример #15
0
 class User(db.Entity):
     username = orm.Optional(str, unique=True)
     password_hash = orm.Optional(str)
     email = orm.Required(str, unique=True)
     dt_registered = orm.Optional(datetime.datetime)
     dt_last_visit = orm.Optional(datetime.datetime)
     verified = orm.Optional(bool)
     failed_login = orm.Optional(int)
     last_failed_login = orm.Optional(datetime.datetime)
Пример #16
0
class AbuseReport(db.Entity):
    """Жалоба на какой-либо объект:

    - story: на рассказ
    - storycomment: на комментарий к рассказу
    - newscomment: на комментарий к новости
    """

    target_type = orm.Required(str, 24)
    target_id = orm.Required(int)
    user = orm.Optional(Author)
    reason = orm.Required(orm.LongStr, lazy=False)
    created_at = orm.Required(datetime, 6, default=datetime.utcnow)
    updated_at = orm.Required(datetime, 6, default=datetime.utcnow)
    resolved_at = orm.Optional(datetime, 6)
    accepted = orm.Required(bool, default=False)
    ignored = orm.Required(bool, default=False)

    def __str__(self):
        username = self.user.username if self.user else 'N/A'

        if self.target_type == 'story':
            target_obj = Story.get(id=self.target_id)
            target = 'рассказ «{}»'.format(target_obj.title if target_obj else 'N/A')

        elif self.target_type == 'storycomment':
            target_obj = StoryComment.get(id=self.target_id)
            target = 'комментарий {} к рассказу «{}»'.format(
                target_obj.author.username if target_obj.author else (target_obj.author_username or 'N/A'),
                target_obj.story.title,
            )

        elif self.target_type == 'newscomment':
            target_obj = NewsComment.get(id=self.target_id)
            target = 'комментарий {} к новости «{}»'.format(
                target_obj.author.username if target_obj.author else (target_obj.author_username or 'N/A'),
                target_obj.newsitem.name,
            )
        else:
            target = self.target_type + '/' + str(self.target_id)

        return 'Жалоба от {} на {}'.format(username, target)
Пример #17
0
class Roles(db.Entity):
    _table_ = ('public', 'Roles')
    RoleID = orm.PrimaryKey(int, auto=True)
    RoleTitle = orm.Required(str)
    Description = orm.Optional(str, nullable=True)
    LatestUpdateDate = orm.Required(datetime, default=datetime.utcnow)
    UserRole = orm.Set("Users", reverse="RoleID")
    IsoRoleAccessesRole = orm.Set("IsoRoleAccesses", reverse="RoleID")
    NonIsoRoleAccessesRole = orm.Set("NonIsoRoleAccesses", reverse="RoleID")
    AdministrativeRoleAccessesRole = orm.Set("AdministrativeRoleAccesses",
                                             reverse="RoleID")
Пример #18
0
class Rating(db.Entity):
    """ Модель рейтинга """

    description = orm.Optional(orm.LongStr)
    name = orm.Required(str, 256)
    nsfw = orm.Required(bool, default=False)

    stories = orm.Set('Story')

    def __str__(self):
        return self.name
Пример #19
0
class Region(database.Entity):
    """
    Регион
    :name - название латиницей
    :readable_name - название на русском
    :purchases - список закупок в регионе
    """
    id = orm.PrimaryKey(int, auto=True)
    name = orm.Required(str, unique=True)
    readable_name = orm.Optional(str)
    purchases = orm.Set("Purchase")
Пример #20
0
class Penalty(db.Entity):

    class OBJ_TYPE(Enum):
        STUD = 'stud'
        GROUP = 'group'

    id = orm.PrimaryKey(int, auto=True)
    target = orm.Required(str)
    target_type = orm.Required(str)
    msg = orm.Optional(str, nullable=True)
    author = orm.Required(str)
Пример #21
0
class ChannelTypes(db.Entity):
    _table_ = ('public', 'ChannelTypes')
    ChannelTypeID = orm.PrimaryKey(int, auto=True)
    ChannelTypeTitle = orm.Required(str, unique=True)
    Description = orm.Optional(str, nullable=True)
    IsTokenRequired = orm.Required(bool)
    HasNoteSituation = orm.Required(bool)
    HasWithdrawalService = orm.Required(bool)
    HasDepositService = orm.Required(bool)
    LatestUpdateDate = orm.Required(datetime, default=datetime.utcnow)
    TerminalChannelType = orm.Set("Terminals", reverse="ChannelTypeID")
Пример #22
0
class Server(db.Entity):
    id = orm.PrimaryKey(int, size=64)
    channel_id = orm.Optional(int, size=64)
    webhook_url = orm.Optional(str)
    presents = orm.Set('Present', reverse='server')

    @orm.db_session
    def is_configured(self) -> bool:
        return (isinstance(self.channel_id, int)
                and isinstance(self.webhook_url, str))

    @orm.db_session
    def add_webhook(self, *, channel_id: int, webhook_url: str):
        self.channel_id = channel_id
        self.webhook_url = webhook_url

    @orm.db_session
    def remove_webhook(self):
        self.channel_id = None
        self.webhook_url = ''
class CinematicSequences(db.Entity):
    id = orm.PrimaryKey(int)
    sound_id = orm.Required(int)
    camera1 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera1_backlink')
    camera2 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera2_backlink')
    camera3 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera3_backlink')
    camera4 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera4_backlink')
    camera5 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera5_backlink')
    camera6 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera6_backlink')
    camera7 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera7_backlink')
    camera8 = orm.Optional('CinematicCamera', reverse='cinematic_sequences_camera8_backlink')

    chr_races_backlink = orm.Set('ChrRaces', reverse='cinematic_sequence')
Пример #24
0
 def test(self):
     obj = AddEntity('MyE', ['MyParentE'], {
         'int': orm.Required(int),
         'str': orm.Optional(str)
     })
     imports = set()
     s = serialize(obj, imports)
     self.assertEqual(
         s, "op.AddEntity('MyE', ['MyParentE'], "
         "{'int': orm.Required(int), 'str': orm.Optional(str)})")
     self.assertIn('from pony.migrate import diagram_ops as op', imports)
Пример #25
0
class Resource(db.Entity):
    Id = orm.PrimaryKey(uuid.UUID, default=uuid.uuid4, auto=True)
    PicHash = orm.Required(orm.LongStr)
    Name = orm.Required(str, py_check=lambda value: \
        isinstance(value, str) and\
        bool(re.match(r"^[a-zA-Z\u4e00-\u9fa5][a-zA-Z\u4e00-\u9fa5_\-0-9]*$", value)) and\
        len(value) <= 40
    )

    PicHeight = orm.Required(int, py_check=lambda value: not bool(value % 16))
    PicWidth = orm.Required(int, py_check=lambda value: not bool(value % 16))

    Model = orm.Optional(str, py_check=lambda i: i in ['steve', 'alex', 'none'], default="steve")
    Type = orm.Required(str, py_check=lambda i: i in ['skin', 'cape'])

    CreatedAt = orm.Required(datetime, default=datetime.now)
    Owner = orm.Required(lambda: Account)

    IsPrivate = orm.Required(bool, default=False)
    Protect = orm.Required(bool, default=False)

    Origin = orm.Optional("Resource")
    Forks = orm.Set("Resource")

    UsedforSkin = orm.Set("Character", reverse='Skin', lazy=True)
    UsedforCape = orm.Set("Character", reverse='Cape', lazy=True)


    def format_self(self, requestHash=False):
        result = {
            "id": self.Id,
            "name": self.Name,
            "createdAt": self.CreatedAt,
            "metadata": {
                "type": self.Type,
                "model": self.Model
            }
        }
        if requestHash:
            result['metadata']['hash'] = self.PicHash
        return result
Пример #26
0
class TelegramUser(db.Entity):
    id = PrimaryKey(int)
    username = orm.Optional(str, index=True, nullable=True)
    first_name = Required(str)
    last_name = orm.Optional(str, nullable=True)
    language_code = orm.Optional(str, nullable=True)
    chats = Set('TelegramChat')
    sent_messages = Set('TelegramMessage', reverse="sender")
    forwarded_messages = Set('TelegramMessage', reverse="forward_from")

    # for groups module
    ping_groups = Set('PingGroup')

    def to_user(self):
        return User({
            'id': self.id,
            'username': self.username,
            'first_name': self.first_name,
            'last_name': self.last_name,
            'language_code': self.language_code
        })
Пример #27
0
class Category(db.Entity):
    """ Categories """
    _table_ = 'mt_category'

    category_id = orm.PrimaryKey(int, column='category_id')
    blog = orm.Optional(Blog, column='category_blog_id')

    basename = orm.Optional(str, column='category_basename')
    name = orm.Optional(str, column='category_label')
    description = orm.Optional(str, column='category_description')
    parent = orm.Optional('Category', column='category_parent')
    children = orm.Set('Category')

    entries = orm.Set('Placement')

    @property
    def path(self):
        """ Get the full path to this category """
        if self.parent and self.parent.category_id:
            return self.parent.path + '/' + self.basename
        return self.basename
Пример #28
0
class CharacterGroup(db.Entity):
    """ Модель группы персонажа """

    name = orm.Required(str, 256)
    description = orm.Optional(orm.LongStr)

    characters = orm.Set('Character')

    bl = Resource('bl.charactergroup')

    def __str__(self):
        return self.name
Пример #29
0
class Classifier(db.Entity):
    """ Модель события """

    description = orm.Optional(orm.LongStr)
    name = orm.Required(str, 256)

    stories = orm.Set('Story')

    bl = Resource('bl.classifier')

    def __str__(self):
        return self.name
class DBMessage(db.Entity):
    type = orm.Discriminator(MSG_TYPE_TYPE)
    date = orm.Required(datetime, sql_default='CURRENT_TIMESTAMP')
    sequence_no = orm.Required(SEQUENCE_TYPE)
    node = orm.Optional(NODE_TYPE)
    value = orm.Optional(VALUE_TYPE)
    leader = orm.Optional(NODE_TYPE)
    sender = orm.Optional(NODE_TYPE)
    raw = orm.Optional(orm.Json)

    _discriminator_ = UNSET

    def from_db(self):
        clazz = MSG_TYPE_CLASS_MAP[self.type]
        assert issubclass(clazz, messages.Message)
        return clazz.from_dict(self.as_dict())
    # end def

    @classmethod
    def to_db(cls, msg):
        return cls(**msg.to_dict())