def setUp(self): # noinspection PyTypeChecker testing_intenum = IntEnum( 'Custom IntEnum', { 'val_1': -1, 'val_2': 10, 'val_3': 11, 'val_4': -3, }, ) self.testing_typeenum = TypeEnum(testing_intenum)
class User(db.Model): __tablename__ = 'users' # noinspection PyTypeChecker ROLE = IntEnum('Role', { 'staff': 0, 'superuser': 1, }) id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(30), unique=True, nullable=False) password = db.Column(db.String(100), nullable=False) name = db.Column(db.String(30)) surname = db.Column(db.String(30)) email = db.Column(db.String(320), nullable=False, unique=True) role = db.Column(TypeEnum(ROLE), nullable=False, default=ROLE.staff) bl = Resource('bl.user') def __repr__(self): return '{} ({})'.format(self.login, self.get_full_name()) def get_full_name(self): return '{} {}'.format(self.name or '', self.surname or '').strip() def is_superuser(self): return self.role == self.ROLE.superuser
class UploadedImage(db.Model): __tablename__ = 'uploaded_images' IMG_CATEGORY = IntEnum( '', { 'other': 0, 'gallery': 1, }, ) id = db.Column(db.Integer, primary_key=True) name = db.Column(GUID, nullable=False) ext = db.Column(db.VARCHAR, nullable=False) img_category = db.Column( TypeEnum(IMG_CATEGORY), default=IMG_CATEGORY.other, nullable=False, ) title = db.Column(db.VARCHAR(32)) description = db.Column(db.VARCHAR(128)) __table_args__ = (db.UniqueConstraint( 'name', 'ext', 'img_category', ), ) bl = Resource('bl.uploadedimage')
class Page(db.Model): __tablename__ = 'pages' # noinspection PyTypeChecker TYPE = IntEnum('Page_type', { 'PROJECTS': 1, 'ABOUT': 2, 'CONTACTS': 3, 'MAINPAGE': 4, }) id = db.Column(db.Integer, primary_key=True) type = db.Column(TypeEnum(TYPE), unique=True, nullable=False) title = db.Column(db.VARCHAR(128)) _blocks = db.relationship( "BlockPageAssociation", order_by='BlockPageAssociation.position', collection_class=ordering_list('position'), cascade='save-update, merge, delete, delete-orphan', ) blocks = association_proxy( '_blocks', 'block', creator=lambda _pb: BlockPageAssociation(block=_pb)) bl = Resource('bl.page') def __str__(self): return '%s (%s)' % (self.title, self.url)
class PageBlock(db.Model): __tablename__ = 'pageblocks' # noinspection PyTypeChecker TYPE = IntEnum( 'Block_type', { 'img_left': 0, 'img_right': 1, 'no_img': 2, }, ) id = db.Column(db.Integer, primary_key=True) block_type = db.Column(TypeEnum(TYPE), default=TYPE.img_left, nullable=False) # header title = db.Column(db.VARCHAR(128), nullable=True) text = db.Column(db.Text) # used for mainpage short_description = db.Column(db.VARCHAR(256), nullable=True) image = db.Column(db.Text, nullable=True) bl = Resource('bl.pageblock') def __str__(self): return '%s: %s' % (self.title, self.text or self.short_description)
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('pages', sa.Column('type', TypeEnum(Page.TYPE), nullable=True)) op.create_unique_constraint('pages_type_key', 'pages', ['type']) op.drop_column('pages', 'url') op.execute('update pages set type = id') op.alter_column('pages', 'type', nullable=False)
def upgrade(): # commands auto generated by Alembic - please adjust! op.create_table( 'uploaded_images', sa.Column('uid', sa.VARCHAR(length=40), nullable=False), sa.Column('img_category', TypeEnum(UploadedImage.IMG_CATEGORY), nullable=False), sa.Column('title', sa.VARCHAR(length=32), nullable=True), sa.Column('description', sa.VARCHAR(length=128), nullable=True), sa.PrimaryKeyConstraint('uid', 'img_category'))
class TestTypeEnumConversion(TestCase): def setUp(self): # noinspection PyTypeChecker testing_intenum = IntEnum( 'Custom IntEnum', { 'val_1': -1, 'val_2': 10, 'val_3': 11, 'val_4': -3, }, ) self.testing_typeenum = TypeEnum(testing_intenum) def test_positive_bind(self): for good_value in self.testing_typeenum._enum: processed_type = self.testing_typeenum.process_bind_param( good_value, dialect=None, ) processed_int = self.testing_typeenum.process_bind_param( good_value.value, dialect=None, ) self.assertEqual(processed_type, good_value.value) self.assertEqual(processed_int, good_value.value) def test_negative_bind(self): bad_value = 0 # selfcheck: self.assertNotIn( bad_value, self.testing_typeenum._enum.__members__.values(), msg="Test selfcheck failed. Please update the test", ) with self.assertRaises(TypeError): self.testing_typeenum.process_bind_param( bad_value, dialect=None, ) def test_none_param(self): processed = self.testing_typeenum.process_bind_param( None, dialect=None, ) self.assertIsNone(processed) def test_process_literal_param(self): processed = self.testing_typeenum.process_literal_param( -1, dialect=None, ) self.assertEqual(processed, self.testing_typeenum._enum.val_1)
class MailTemplate(db.Model): __tablename__ = 'mailtemplates' # noinspection PyTypeChecker MAIL = IntEnum('Mail', { 'CV': 0, 'REPLY': 1, }) id = db.Column(db.Integer, primary_key=True) mail = db.Column(TypeEnum(MAIL), nullable=False) title = db.Column(db.String, nullable=False) subject = db.Column(db.String(79), nullable=False) html = db.Column(db.Text, nullable=False) help_msg = db.Column(db.Text) updated_at = db.Column(db.Date, onupdate=datetime.datetime.now, default=datetime.datetime.now) bl = Resource('bl.mailtemplate') user_id = db.Column(db.Integer, db.ForeignKey('users.id')) who_updated = db.relationship('User') def __repr__(self): return str(self.title)
def upgrade(): # commands auto generated by Alembic - please adjust! op.create_table( 'category', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=50), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'), ) op.create_table( 'city', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=20), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'), ) op.create_table( 'pageblocks', sa.Column('id', sa.Integer(), nullable=False), sa.Column('block_type', TypeEnum(PageBlock.TYPE), nullable=False), sa.Column('title', sa.VARCHAR(length=128), nullable=True), sa.Column('text', sa.Text(), nullable=True), sa.Column('short_description', sa.VARCHAR(length=256), nullable=True), sa.Column('image', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), ) op.create_table( 'pagechunks', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.Text(), nullable=True), sa.Column('text', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'), ) op.create_table( 'pages', sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.VARCHAR(length=128), nullable=True), sa.Column('url', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), ) op.create_table( 'users', sa.Column('id', sa.Integer(), nullable=False), sa.Column('login', sa.String(length=30), nullable=False), sa.Column('password', sa.String(length=100), nullable=False), sa.Column('name', sa.String(length=30), nullable=True), sa.Column('surname', sa.String(length=30), nullable=True), sa.Column('email', sa.String(length=30), nullable=False), sa.Column('role', TypeEnum(User.ROLE), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('login'), ) op.create_table( 'block_page_association', sa.Column('page_id', sa.Integer(), nullable=False), sa.Column('block_id', sa.Integer(), nullable=False), sa.Column('position', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['block_id'], ['pageblocks.id'], ), sa.ForeignKeyConstraint( ['page_id'], ['pages.id'], ), sa.PrimaryKeyConstraint('page_id', 'block_id'), ) op.create_table( 'tokens', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('token', sa.String(), nullable=False), sa.ForeignKeyConstraint( ['user_id'], ['users.id'], ), sa.PrimaryKeyConstraint('id'), ) op.create_table( 'vacancy', sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.String(length=100), nullable=False), sa.Column('short_description', sa.String(length=300), nullable=False), sa.Column('text', sa.Text(), nullable=False), sa.Column('category_id', sa.Integer(), nullable=True), sa.Column('name_in_url', sa.String(length=50), nullable=False), sa.Column('visits', sa.Integer(), nullable=False), sa.Column('salary', sa.String(length=50), nullable=True), sa.Column('description', sa.String(length=200), nullable=True), sa.Column('keywords', sa.String(length=1000), nullable=True), sa.Column('city_id', sa.Integer(), nullable=True), sa.Column('hide', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint( ['category_id'], ['category.id'], ), sa.ForeignKeyConstraint( ['city_id'], ['city.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name_in_url'), )
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('mailtemplates', sa.Column('mail', TypeEnum(MailTemplate.MAIL), nullable=False, server_default=sa.DefaultClause("0"))) op.drop_column('mailtemplates', 'slug')