def do_upgrade(): """Implement your upgrades here.""" if not op.has_table('oauth2CLIENT'): op.create_table( 'oauth2CLIENT', db.Column('name', db.String(length=40), nullable=True), db.Column('description', db.Text(), nullable=True), db.Column('website', URLType(), nullable=True), db.Column('user_id', db.Integer(15, unsigned=True), nullable=True), db.Column('client_id', db.String(length=255), nullable=False), db.Column('client_secret', db.String(length=255), nullable=False), db.Column('is_confidential', db.Boolean(), nullable=True), db.Column('is_internal', db.Boolean(), nullable=True), db.Column('_redirect_uris', db.Text(), nullable=True), db.Column('_default_scopes', db.Text(), nullable=True), db.ForeignKeyConstraint(['user_id'], ['user.id'], ), db.PrimaryKeyConstraint('client_id'), mysql_charset='utf8', mysql_engine='MyISAM' ) else: warnings.warn("*** Creation of table 'oauth2CLIENT' skipped!") if not op.has_table('oauth2TOKEN'): op.create_table( 'oauth2TOKEN', db.Column('id', db.Integer(15, unsigned=True), autoincrement=True, nullable=False), db.Column('client_id', db.String(length=40), nullable=False), db.Column('user_id', db.Integer(15, unsigned=True), nullable=True), db.Column('token_type', db.String(length=255), nullable=True), db.Column('access_token', db.String(length=255), nullable=True), db.Column('refresh_token', db.String(length=255), nullable=True), db.Column('expires', db.DateTime(), nullable=True), db.Column('_scopes', db.Text(), nullable=True), db.Column('is_personal', db.Boolean(), nullable=True), db.Column('is_internal', db.Boolean(), nullable=True), db.ForeignKeyConstraint( ['client_id'], ['oauth2CLIENT.client_id'],), db.ForeignKeyConstraint(['user_id'], ['user.id'], ), db.PrimaryKeyConstraint('id'), db.UniqueConstraint('access_token'), db.UniqueConstraint('refresh_token'), mysql_charset='utf8', mysql_engine='MyISAM' ) else: warnings.warn("*** Creation of table 'oauth2TOKEN' skipped!")
class Item(Base): """Item.""" __tablename__ = 'toranoana_item' id = Column(Integer, primary_key=True) code = Column(String, unique=True, nullable=False) title = Column(String, nullable=False) image_url = Column(URLType(), nullable=False) price = Column(Integer, nullable=False) stock = Column( ChoiceType(Stock, impl=Integer()), nullable=False, ) genre_id = Column(Integer, ForeignKey(Genre.id), nullable=False) genre = relationship(Genre) male_target = Column( ChoiceType(Target, impl=Integer()), nullable=False, default=Target.nobody, ) female_target = Column( ChoiceType(Target, impl=Integer()), nullable=False, default=Target.nobody, ) authors = relationship( Author, secondary='toranoana_itemauthor', backref='items', ) circles = relationship( Circle, secondary='toranoana_itemcircle', backref='items', ) tags = relationship( Tag, secondary='toranoana_itemtag', backref='items', ) couplings = relationship( Coupling, secondary='toranoana_itemcoupling', backref='items', ) characters = relationship( Character, secondary='toranoana_itemcharacter', backref='items', ) checked_datetime = DateTimeColumn(nullable=False) checked_timezone = TimezoneColumn() checked_at = DateTimeAtColumn('checked') updated_datetime = DateTimeColumn(nullable=False) updated_timezone = TimezoneColumn() updated_at = DateTimeAtColumn('updated') is_deleted = Column(Boolean, default=False, nullable=False) @hybrid_property def url(self) -> str: if self.male_target != Target.nobody: return { Target.common: ( 'https://ec.toranoana.shop/tora/ec/item/{code}/' ), Target.adult: 'https://ec.toranoana.jp/tora_r/ec/item/{code}/', }[self.male_target].format(code=self.code) return { Target.common: 'https://ec.toranoana.shop/joshi/ec/item/{code}/', Target.adult: 'https://ec.toranoana.jp/joshi_r/ec/item/{code}/', }[self.female_target].format(code=self.code)
class Client(db.Model): """A client is the app which want to use the resource of a user. It is suggested that the client is registered by a user on your site, but it is not required. The client should contain at least these information: client_id: A random string client_secret: A random string client_type: A string represents if it is confidential redirect_uris: A list of redirect uris default_redirect_uri: One of the redirect uris default_scopes: Default scopes of the client But it could be better, if you implemented: allowed_grant_types: A list of grant types allowed_response_types: A list of response types validate_scopes: A function to validate scopes """ __tablename__ = 'oauth2CLIENT' name = db.Column( db.String(40), info=dict(label=_('Name'), description=_('Name of application (displayed to users).'), validators=[validators.DataRequired()])) """Human readable name of the application.""" description = db.Column(db.Text(), default=u'', info=dict( label=_('Description'), description=_( 'Optional. Description of the application' ' (displayed to users).'), )) """Human readable description.""" website = db.Column( URLType(), info=dict( label=_('Website URL'), description=_('URL of your application (displayed to users).'), ), default=u'', ) user_id = db.Column(db.ForeignKey('user.id')) """Creator of the client application.""" client_id = db.Column(db.String(255), primary_key=True) """Client application ID.""" client_secret = db.Column(db.String(255), unique=True, index=True, nullable=False) """Client application secret.""" is_confidential = db.Column(db.Boolean, default=True) """Determine if client application is public or not.""" is_internal = db.Column(db.Boolean, default=False) """Determins if client application is an internal application.""" _redirect_uris = db.Column(db.Text) """A newline-separated list of redirect URIs. First is the default URI.""" _default_scopes = db.Column(db.Text) """A space-separated list of default scopes of the client. The value of the scope parameter is expressed as a list of space-delimited, case-sensitive strings. """ user = db.relationship('User') """Relationship to user.""" @property def allowed_grant_types(self): """Return allowed grant types.""" return current_app.config['OAUTH2_ALLOWED_GRANT_TYPES'] @property def allowed_response_types(self): """Return allowed response types.""" return current_app.config['OAUTH2_ALLOWED_RESPONSE_TYPES'] # def validate_scopes(self, scopes): # return self._validate_scopes @property def client_type(self): """Return client type.""" if self.is_confidential: return 'confidential' return 'public' @property def redirect_uris(self): """Return redirect uris.""" if self._redirect_uris: return self._redirect_uris.splitlines() return [] @redirect_uris.setter def redirect_uris(self, value): """Validate and store redirect URIs for client.""" if isinstance(value, six.text_type): value = value.split("\n") value = [v.strip() for v in value] for v in value: validate_redirect_uri(v) self._redirect_uris = "\n".join(value) or "" @property def default_redirect_uri(self): """Return default redirect uri.""" try: return self.redirect_uris[0] except IndexError: pass @property def default_scopes(self): """List of default scopes for client.""" if self._default_scopes: return self._default_scopes.split(" ") return [] @default_scopes.setter def default_scopes(self, scopes): """Set default scopes for client.""" validate_scopes(scopes) self._default_scopes = " ".join(set(scopes)) if scopes else "" def validate_scopes(self, scopes): """Validate if client is allowed to access scopes.""" try: validate_scopes(scopes) return True except ScopeDoesNotExists: return False def gen_salt(self): """Generate salt.""" self.reset_client_id() self.reset_client_secret() def reset_client_id(self): """Reset client id.""" self.client_id = gen_salt( current_app.config.get('OAUTH2_CLIENT_ID_SALT_LEN')) def reset_client_secret(self): """Reset client secret.""" self.client_secret = gen_salt( current_app.config.get('OAUTH2_CLIENT_SECRET_SALT_LEN'))
def downgrade(): op.create_table( "toranoana_author", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_character", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("name_ko", sa.String(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_circle", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_coupling", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("name_ko", sa.String(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_genre", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("name_ko", sa.String(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_tag", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("name_ko", sa.String(), nullable=True), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_item", sa.Column("id", sa.Integer(), nullable=False), sa.Column("code", sa.String(), nullable=False), sa.Column("title", sa.String(), nullable=False), sa.Column("image_url", URLType(), nullable=False), sa.Column("price", sa.Integer(), nullable=False), sa.Column("stock", ChoiceType(Stock, impl=sa.Integer()), nullable=False), sa.Column("genre_id", sa.Integer(), nullable=False), sa.Column( "male_target", ChoiceType(Target, impl=sa.Integer()), nullable=False, ), sa.Column( "female_target", ChoiceType(Target, impl=sa.Integer()), nullable=False, ), sa.Column("checked_datetime", sa.DateTime(timezone=True), nullable=False), sa.Column("checked_timezone", TimezoneType(), nullable=True), sa.Column("updated_datetime", sa.DateTime(timezone=True), nullable=False), sa.Column("updated_timezone", TimezoneType(), nullable=True), sa.Column("is_deleted", sa.Boolean(), nullable=False), sa.ForeignKeyConstraint( ["genre_id"], ["toranoana_genre.id"], ), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("code"), ) op.create_table( "toranoana_watch", sa.Column("id", sa.Integer(), nullable=False), sa.Column("print_target_id", sa.String(), nullable=False), sa.Column("genre_id", sa.Integer(), nullable=True), sa.Column("male", ChoiceType(Target, impl=sa.Integer()), nullable=False), sa.Column("female", ChoiceType(Target, impl=sa.Integer()), nullable=False), sa.ForeignKeyConstraint( ["genre_id"], ["toranoana_genre.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_table( "toranoana_itemauthor", sa.Column("item_id", sa.Integer(), nullable=False), sa.Column("author_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["author_id"], ["toranoana_author.id"], ), sa.ForeignKeyConstraint( ["item_id"], ["toranoana_item.id"], ), sa.PrimaryKeyConstraint("item_id", "author_id"), ) op.create_table( "toranoana_itemcharacter", sa.Column("item_id", sa.Integer(), nullable=False), sa.Column("character_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["character_id"], ["toranoana_character.id"], ), sa.ForeignKeyConstraint( ["item_id"], ["toranoana_item.id"], ), sa.PrimaryKeyConstraint("item_id", "character_id"), ) op.create_table( "toranoana_itemcircle", sa.Column("item_id", sa.Integer(), nullable=False), sa.Column("circle_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["circle_id"], ["toranoana_circle.id"], ), sa.ForeignKeyConstraint( ["item_id"], ["toranoana_item.id"], ), sa.PrimaryKeyConstraint("item_id", "circle_id"), ) op.create_table( "toranoana_itemcoupling", sa.Column("item_id", sa.Integer(), nullable=False), sa.Column("coupling_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["coupling_id"], ["toranoana_coupling.id"], ), sa.ForeignKeyConstraint( ["item_id"], ["toranoana_item.id"], ), sa.PrimaryKeyConstraint("item_id", "coupling_id"), ) op.create_table( "toranoana_itemtag", sa.Column("item_id", sa.Integer(), nullable=False), sa.Column("tag_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["item_id"], ["toranoana_item.id"], ), sa.ForeignKeyConstraint( ["tag_id"], ["toranoana_tag.id"], ), sa.PrimaryKeyConstraint("item_id", "tag_id"), )