예제 #1
0
class Book(BaseRecord):
    title = StringField(size=300)
    pub_date = DateTimeField()
    avail_since = DateTimeField(auto_now_add=True)
    abstract = StringField(size=1000)
    isbn = StringField(size=50)
    author = ManyToOneRelation(Author, backref="books")
예제 #2
0
 def load_field_info(self, field_info):
     field_datatype = field_info["Type"]
     is_key = field_info['Key'] in ('P', 'U')
     field_name = field_info['Field']
     if field_datatype == "NUMBER" and (field_info['Precision'] == 0
                                        or field_info['Precision'] == None):
         return IntField(field_name, is_key=is_key)
     elif field_datatype == 'NUMBER' and field_info['Precision'] > 0:
         return DecimalField(field_name, is_key=is_key)
     elif field_datatype == 'NVARCHAR2':
         return StringField(field_name, is_key=is_key)
     elif field_datatype == 'VARCHAR2':
         return StringField(field_name, is_key=is_key)
     elif field_datatype == 'FLOAT':
         return DecimalField(field_name, is_key=is_key)
     elif field_datatype == 'CHAR':
         return StringField(field_name, is_key=is_key)
     elif field_datatype == 'TIMESTAMP(6)':
         return DatetimeField(field_name, is_key=is_key)
     elif field_datatype == 'CLOB':
         return StringField(field_name, is_key=is_key)
     elif field_datatype == 'DATE':
         return DatetimeField(field_name, is_key=is_key)
     else:
         raise Exception('Unsupportted type ' + field_datatype)
예제 #3
0
class Person(Model):

    __table__ = 'person'

    id = AutoPrimaryField(length=11)
    last_name = StringField(length=255)
    first_name = StringField(length=255)
    address = StringField(length=255)
    city = StringField(length=255)
예제 #4
0
class Comment(Model):
    __table__ = 'comments'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    blog_id = StringField(ddl='varchar(50)')
    user_id = StringField(ddl='varchar(50)')
    user_name = StringField(ddl='varchar(50)')
    user_image = StringField(ddl='varchar(500)')
    content = TextField()
    created_at = FloatField(default=time.time)
예제 #5
0
class User(Model):
    __table__ = 'users'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    email = StringField(ddl='varchar(50)')
    passwd = StringField(ddl='varchar(50)')
    admin = BooleanField()
    name = StringField(ddl='varchar(50)')
    image = StringField(ddl='varchar(500)')
    created_at = FloatField(default=time.time)
예제 #6
0
 def __init__(self):
     super().__init__()
     self.status = ForeignKeyField(title='Статус', col_name='status', target_model_class=LogStatusModel, target_fields=(('name', 'Статус'),))
     self.logged_table_name = StringField(col_name='table_name', title='Таблица')
     self.logged_table_pk = IntegerField(col_name='table_pk', title='Ключ')
     # TODO: fix creation
     self.datetime = TimestampField(col_name='change_time', title='Время')
예제 #7
0
class MultiLevelFieldGroup(BaseFieldGroup):
    cls = MultiLevelData
    cls_ctor_args = {}
    key2field = {
        "pos": Coord3DFieldGroup(),
        "direction": Vector3DFieldGroup(),
        "info": StringField(size=200)
    }
예제 #8
0
class User(Model):
    name = StringField(required=True)
    description = StringField()
    date_added = DateField()
    age = IntField()
    coins = FloatField()
    is_superuser = BooleanField()

    def __str__(self):
        return 'User {}'.format(self.name, self.age)

    def __repr__(self):
        return '<User {}>'.format(self.name, self.age)

    def update(self):
        pass

    class Meta:
        table_name = 'ormtable'
        order_by = ('name', )
예제 #9
0
class Blog(Model):
    __table__ = 'blogs'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    user_id = StringField(ddl='varchar(50)')
    user_name = StringField(ddl='varchar(50)')
    user_image = StringField(ddl='varchar(500)')
    name = StringField(ddl='varchar(50)')
    summary = StringField(ddl='varchar(200)')
    content = TextField()
    created_at = FloatField(default=time.time)
예제 #10
0
 def __init__(self):
     super().__init__()
     self.name = StringField(title='Предмет', col_name='name')
예제 #11
0
class Address(BaseRecord):
    author = OneToOneRelation(Author, backref="address")
    city = StringField(size=100)
    street = StringField(size=100)
    street_no = IntegerField()
    postal_code = IntegerField()
예제 #12
0
class Grade(Model):

    __table__ = 'grade'

    id = AutoPrimaryField(length=11)
    name = StringField(length=255)
예제 #13
0
class Author(BaseRecord):
    name = StringField(size=50)
    family_name = StringField(size=50)
    avail_since = DateTimeField(auto_now_add=True)
    birthday = DateTimeField()
예제 #14
0
 def __init__(self):
     super().__init__()
     self.name = StringField(title='Группа', col_name='name')
예제 #15
0
 def __init__(self):
     super().__init__()
     self.name = StringField(col_name='name', title='Название')
예제 #16
0
class Man(User):
    sex = StringField()

    class Meta:
        table_name = 'Man'
        order_by = ('-name', 'coins', 'sex')
예제 #17
0
 class MyModel(BaseRecord):
     word = StringField(size=40)
예제 #18
0
 def __init__(self):
     super().__init__()
     self.name = StringField('Название', col_name='name')
     self.order_number = IntegerField('Порядковый номер', col_name='order_number')
예제 #19
0
 def __init__(self):
     super().__init__()
     self.name = StringField('Статус', col_name='name')
예제 #20
0
 def prepare_query_value(self, op, value):
     if isinstance(value, basestring):
         from fields import StringField
         return StringField().prepare_query_value(op, value)
     return self.to_es(value)
예제 #21
0
    def test_fields(self):
        f = BaseField(name='test', model=MockModel(), unique=True)
        data = f.validate(data=None, _id='507f1f77bcf86cd799439011')
        self.assertIsNone(data)

        model = MockModel(count=10)

        with self.assertRaises(Exception):
            f = BaseField(name='test', model=model, unique=True)
            f.validate(data=None, _id='507f1f77bcf86cd799439011')

        f = AutoBaseField(name='test', model=MockModel())
        f.get_original('507f1f77bcf86cd799439011')

        with self.assertRaises(NotImplementedError):
            f.set(None)

        with self.assertRaises(Exception):
            f.validate(None)

        s = StringField('test', model=MockModel())
        data = s.validate('test')
        self.assertEqual(data, 'test')

        with self.assertRaises(Exception):
            s.validate(None)

        dt = DateTimeField('test', model=MockModel())
        dt.validate('2018-12-10 15:00:00.123')

        with self.assertRaises(Exception):
            dt.validate('invalid')

        nf = NumberField('test', model=MockModel())
        data = nf.validate(10)
        self.assertEqual(data, 10)

        with self.assertRaises(Exception):
            nf.validate('test')

        af = AutoField('test', model=MockModel())
        val = af.set()
        self.assertEqual(val, 1)

        self.assertEqual(af.set(_id='507f1f77bcf86cd799439011'), {})

        adt = AutoDateTimeField('test', model=MockModel(), create_only=True)
        today = datetime.now().today()

        time = adt.set()
        self.assertEqual(today.date(), time.date())

        new_time = adt.set(_id='507f1f77bcf86cd799439011')
        self.assertEqual(new_time, {})

        bf = BooleanField('test', model=MockModel())
        data = bf.validate(True)
        self.assertTrue(data)

        with self.assertRaises(Exception):
            bf.validate('test')

        fk = ForeignKeyField('test', model=MockModel(), to='test')
        with self.assertRaises(Exception):
            fk.validate('507f1f77bcf86cd799439011')