How to use the pony.orm.Required function in pony

To help you get started, we’ve selected a few pony examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NiklasRosenstein / flux-ci / flux / models.py View on Github external
return (self.created + config.login_token_duration) < now


class Repository(db.Entity):
  """
  Represents a repository for which push events are being accepted. The Git
  server specified at the `clone_url` must accept the Flux server's public
  key.
  """

  _table_ = 'repos'

  id = orm.PrimaryKey(int)
  name = orm.Required(str)
  secret = orm.Optional(str)
  clone_url = orm.Required(str)
  build_count = orm.Required(int, default=0)
  builds = orm.Set('Build')
  ref_whitelist = orm.Optional(str)  # newline separated list of accepted Git refs

  def __init__(self, **kwargs):
    if 'id' not in kwargs:
      kwargs['id'] = (orm.max(x.id for x in Repository) or 0) + 1
    super().__init__(**kwargs)

  def url(self, **kwargs):
    return url_for('view_repo', path=self.name, **kwargs)

  def check_accept_ref(self, ref):
    whitelist = list(filter(bool, self.ref_whitelist.split('\n')))
    if not whitelist or ref in whitelist:
      return True
github tortoise / orm-benchmarks / src / pony / models.py View on Github external
db = Database()

test = int(os.environ.get('TEST', '1'))
if test == 1:
    class Journal(db.Entity):
        timestamp = Required(datetime, default=datetime.now)
        level = Required(int, size=16, index=True)
        text = Required(str, max_len=255, index=True)


if test == 2:
    class Journal(db.Entity):
        timestamp = Required(datetime, default=datetime.now)
        level = Required(int, size=16, index=True)
        text = Required(str, max_len=255, index=True)

        parent = Optional("Journal", reverse="children")
        children = Set("Journal", reverse="parent")
        related = Set("Journal", reverse="related_from")
        related_from = Set("Journal", reverse="related")


if test == 3:
    class Journal(db.Entity):
        timestamp = Required(datetime, default=datetime.now)
        level = Required(int, size=16, index=True)
        text = Required(str, max_len=255, index=True)

        col_float1 = Required(float, default=2.2)
        col_smallint1 = Required(int, size=16, default=2)
        col_int1 = Required(int, size=32, default=2000000)
github alin23 / spfy / spfy / cache / db.py View on Github external
genres=genres,
            images=images,
            popularity=artist.popularity,
        )


# pylint: disable=too-few-public-methods


class AudioFeatures(db.Entity):
    _table_ = "audio_features"
    KEYS = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
    id = PrimaryKey(str)  # pylint: disable=redefined-builtin
    acousticness = Required(float, min=0.0, max=1.0)
    danceability = Required(float, min=0.0, max=1.0)
    duration_ms = Required(int, min=0)
    energy = Required(float, min=0.0, max=1.0)
    instrumentalness = Required(float, min=0.0, max=1.0)
    key = Required(int, min=0, max=11)
    liveness = Required(float, min=0.0, max=1.0)
    loudness = Required(float, min=-60.0, max=0.0)
    mode = Required(bool)
    speechiness = Required(float, min=0.0, max=1.0)
    tempo = Required(float, min=0, max=1000)
    time_signature = Required(int)
    valence = Required(float, min=0.0, max=1.0)

    # pylint: disable=arguments-differ,signature-differs
    def to_dict(self, *args, **kwargs):
        _dict = super().to_dict(*args, **kwargs)
        if "mode" in _dict:
            _dict["mode"] = int(_dict["mode"])
github yetone / collipa / collipa / models / history.py View on Github external
# coding: utf-8

import time
from pony import orm
from ._base import db, BaseModel
import collipa.models


class History(db.Entity, BaseModel):
    user_id = orm.Required(int)
    content = orm.Required(orm.LongUnicode)

    created_at = orm.Required(int, default=int(time.time()))

    topic_id = orm.Optional(int)
    reply_id = orm.Optional(int)

    def __str__(self):
        return self.id

    def __repr__(self):
        return '' % self.id

    @property
    def item(self):
        if self.topic_id:
github yetone / collipa / collipa / models / collect_class.py View on Github external
# coding: utf-8

import time
from pony import orm
from ._base import db, BaseModel


class CollectClass(db.Entity, BaseModel):
    user_id = orm.Required(int)
    name = orm.Required(unicode)

    collect_count = orm.Required(int, default=0)

    created_at = orm.Required(int, default=int(time.time()))
    active = orm.Required(int, default=int(time.time()))

    description = orm.Optional(unicode)

    def __str__(self):
        return self.id

    def __repr__(self):
        return '' % self.id
github yetone / collipa / collipa / models / message.py View on Github external
# coding: utf-8

import time
from pony import orm
from ._base import db, BaseModel
import collipa.models


class Message(db.Entity, BaseModel):
    message_box1_id = orm.Required(int, default=0)
    message_box2_id = orm.Required(int, default=0)

    sender_id = orm.Required(int)
    receiver_id = orm.Required(int)

    content = orm.Required(orm.LongUnicode)

    """ 信息类型
        'message':        私信
    """
    role = orm.Required(unicode, default='message')

    """ 状态
        1:      已读
        0:      未读
    """
    status = orm.Required(int, default=0)

    created_at = orm.Required(int, default=int(time.time()))
github yetone / collipa / collipa / models / report.py View on Github external
# coding: utf-8

import time
from pony import orm
from ._base import db, BaseModel


class Report(db.Entity, BaseModel):
    user_id = orm.Required(int)

    created_at = orm.Required(int, default=int(time.time()))

    topic_id = orm.Optional(int)
    reply_id = orm.Optional(int)
    tweet_id = orm.Optional(int)
    album_id = orm.Optional(int)
    image_id = orm.Optional(int)

    def __str__(self):
        return self.id

    def __repr__(self):
        return '' % self.id

    def save(self):
github yetone / collipa / collipa / models / message_box.py View on Github external
class MessageBox(db.Entity, BaseModel):
    sender_id = orm.Required(int)
    receiver_id = orm.Required(int)

    """ 信息类型
        'message':        私信
    """
    role = orm.Required(unicode, default='message')

    """ 状态
        1:      已读
        0:      未读
    """
    status = orm.Required(int, default=0)

    created_at = orm.Required(int, default=int(time.time()))
    updated_at = orm.Required(int, default=int(time.time()))

    def __str__(self):
        return self.id

    def __repr__(self):
        return '' % self.id

    @property
    def sender(self):
        return collipa.models.User.get(id=self.sender_id)

    @property
    def receiver(self):
        return collipa.models.User.get(id=self.receiver_id)
github yetone / collipa / collipa / models / bill.py View on Github external
'reply-edit':       编辑评论            收入/支出
        'reply-hot':        评论变为热门        收入
        'reply-report':     评论变为举报        支出
        'thank':            主题/评论被感谢     收入/支出
        'thank-remove':     主题/评论感谢撤销   收入/支出
        'collect':          主题/评论被收藏     收入/支出
        'active-gift':      活跃赠送            收入
    """
    role = orm.Required(unicode, default='signup')

    """ 支收类型
        1   收入
        0   支出
    """
    category = orm.Required(int, default=1)
    created_at = orm.Required(int, default=int(time.time()))

    user_id = orm.Optional(int)

    topic_id = orm.Optional(int)
    reply_id = orm.Optional(int)

    spender_id = orm.Optional(int)
    incomer_id = orm.Optional(int)

    def __str__(self):
        return self.id

    def __repr__(self):
        return '' % self.id

    def save(self):
github yetone / collipa / collipa / models / node.py View on Github external
from ._base import db, BaseModel
from collipa import config
import collipa.models

from collipa.helpers import strip_tags
from collipa.extensions import mc


class Node(db.Entity, BaseModel):
    user_id = orm.Required(int, default=1)

    name = orm.Required(unicode, 80, unique=True)
    urlname = orm.Required(unicode, 80, unique=True)

    topic_count = orm.Required(int, default=0)
    follow_count = orm.Required(int, default=0)
    role = orm.Required(unicode, 10, default='node')

    created_at = orm.Required(int, default=int(time.time()))
    updated_at = orm.Required(int, default=int(time.time()))
    active = orm.Required(int, default=int(time.time()))

    description = orm.Optional(orm.LongUnicode)
    summary = orm.Optional(orm.LongUnicode)
    style = orm.Optional(unicode, 6000)

    icon_img = orm.Optional(unicode, 400)
    head_img = orm.Optional(unicode, 400)
    background_img = orm.Optional(unicode, 400)

    @property
    def url(self):