class Document(DeclarativeBase): __tablename__ = 'docu' uid = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(16), unique=True) content = Column('content_col', UploadedFileField) photo = Column(UploadedFileField(upload_type=UploadedImageWithThumb)) second_photo = Column(UploadedFileField(filters=(WithThumbnailFilter((12, 12), 'PNG'),)))
class Document(DeclarativeBase): __tablename__ = 'docu' uid = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(16), unique=True) content = Column('content_col', UploadedFileField) photo = Column(UploadedFileField(upload_type=UploadedImageWithThumb)) second_photo = Column(UploadedFileField(filters=(WithThumbnailFilter((12, 12), 'PNG'),))) targeted_content = Column(UploadedFileField(upload_storage='another_alias')) type = Column(Text, nullable=True) __mapper_args__ = { 'polymorphic_on': 'type' }
class User(BASE_MODEL, ZopseduBase, UserMixin): """Simple user data model""" __tablename__ = 'users' id = Column(Integer, primary_key=True) username = Column(String(80), unique=True) password = Column(String(255)) email = Column(String(255), unique=True) profile_photo = Column( UploadedFileField(upload_storage="local", upload_type=UploadedAvatar)) avatar = Column(UploadedFileField( upload_type=UploadedAvatar)) # default upload storage kullanilir. durumu = Column(Boolean, default=True) session_id = Column(String(500)) roles = relationship("Role", secondary="user_roles") person = relationship("Person", uselist=False) ozgecmis = relationship("Ozgecmis", uselist=False) # s3 tanimlanmis ise bu sekilde kullanilabilir # avatar = Column(UploadedFileField(upload_storage="s3")) def __repr__(self): return '<User %r>' % self.username @property def is_authenticated(self): return session.get('is_authenticated', False) @property def is_active(self): return True @property def is_anonymous(self): return session.get('is_anonymous', False) def get_role(self, role_id): """ User'in rolleri icinden verilen id'ye sahip rolü döndürür. Args: role_id(str): Returns: Role or None """ if isinstance(role_id, str): role_id = int(role_id) role = Role.query.filter_by(id=role_id).first() return role
class BlogPost(Base): __tablename__ = 'blog_posts' title = db.Column(Text(), nullable=False) url_id = db.Column(Text(), nullable=False) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='blog_images')) author = db.Column(Text(), nullable=False) body_html = db.Column(Text(), nullable=False) # Whether to render the post on the portfolio page is_portfolio = db.Column(db.Boolean, default=False, nullable=False) portfolio_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='blog_images')) portfolio_title = db.Column(Text()) portfolio_description = db.Column(Text()) is_published = db.Column(db.Boolean, default=False, nullable=False)
def upgrade(): op.create_table( 'presentation', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('title', sa.String(32), nullable=False), sa.Column('description', sa.Unicode), sa.Column('date', sa.Date, nullable=False), sa.Column('thumbnail', UploadedFileField(upload_type=UploadedImageWithThumb)), sa.Column('repo_url', sa.Unicode(512)), ) op.create_table( 'presentation_author', sa.Column('presentation_id', sa.Integer, sa.ForeignKey('presentation.id'), primary_key=True), sa.Column('user_id', sa.Integer, sa.ForeignKey('tg_user.user_id'), primary_key=True), ) op.create_table( 'presentation_file', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('presentation_id', sa.Integer, sa.ForeignKey('presentation.id'), nullable=False), sa.Column('description', sa.String(32), nullable=False), sa.Column('file', UploadedFileField, nullable=False), )
class Post(Base, Model, Timestamp): __tablename__ = "post" caption = Column(String(256)) image = Column(UploadedFileField(), nullable=False) user_id = Column(Integer, ForeignKey('user.id')) likes = relationship('Like', backref='owner', lazy='dynamic') comments = relationship('Comment', backref='owner', lazy='dynamic') @property def total_number_of_likes(self): like_count = 0 for _ in self.likes: like_count += 1 return like_count @property def post_comments(self): comments = [] for comment in self.comments: comment = dict(comment) comments.append( dict(user_id=comment.get('user_id'), comment=comment.get('comment'))) return comments @property def post_likes(self): likes = [] for like in self.likes: like = dict(like) likes.append(dict(user_id=like.get('user_id'))) return likes
def upgrade(): from depot.manager import DepotManager from depot.fields.upload import UploadedFile from depot.fields.sqlalchemy import UploadedFileField from kotti import DBSession, metadata from kotti.resources import File t = sa.Table('files', metadata) t.c.data.type = sa.LargeBinary() dn = DepotManager.get_default() update = t.update() conn = DBSession.connection() for obj in DBSession.query(File): uploaded_file = UploadedFile({'depot_name': dn, 'files': []}) uploaded_file._thaw() uploaded_file.process_content(obj.data, filename=obj.filename, content_type=obj.mimetype) stored_file = DepotManager.get().get(uploaded_file['file_id']) stmt = update.where(t.c.id == obj.id).values( data=uploaded_file.encode()) res = conn.execute(stmt) assert res.rowcount == 1 stored_file.last_modified = obj.modification_date log.info("Migrated {} bytes for File with pk {} to {}/{}".format( len(obj.data), obj.id, dn, uploaded_file['file_id'])) DBSession.flush() if DBSession.get_bind().name != 'sqlite': # not supported by sqlite op.alter_column('files', 'data', type_=UploadedFileField())
def upgrade(): op.create_table( 'banner', sa.Column('id', sa.Integer(), autoincrement=True, primary_key=True), sa.Column('photo', UploadedFileField(upload_type=UploadedImageWithThumb)), sa.Column('description', sa.Unicode(2048), unique=True) )
def file_value(cls): kwargs = getattr(cls, "__file_field_args__", {}) nullable = kwargs.pop("nullable", True) info = kwargs.pop("info", {}) info["type"] = ((FileIntent, FileStorage), "file") return db.Column(UploadedFileField(**kwargs), nullable=nullable, info=info)
class BlogImage(Base): __tablename__ = 'blog_images' blog_post_id = db.Column(db.String(t.LEN_UUID), db.ForeignKey('blog_posts.id'), nullable=False) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='blog_images')) blog_post = db.relationship('BlogPost', backref='images')
class Content(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String, nullable=False) subtitle = db.Column(db.String, nullable=False) cover_art = db.Column( UploadedFileField(upload_type=CustomUploadedImageWithThumb)) created_at = db.Column(db.DateTime, default=datetime.now) script = db.Column(db.Text, nullable=False) source = db.relationship("Source", backref="content", uselist=True, lazy="dynamic") audio = db.relationship("Audio", backref="content", uselist=True, lazy="dynamic") other = db.relationship("Other", backref="content", uselist=True, lazy="dynamic") download = db.relationship("Download", backref="content", uselist=True, lazy="dynamic") @property def cover_art_thumbnail(self): return self.cover_art.thumb_url @property def cover_art_full(self): return self.cover_art.url marshal = { 'id': fields.Integer, 'title': fields.String, 'subtitle': fields.String, 'cover_art_thumbnail': fields.String, 'created_at': fields.DateTime, } marshal_detailed = { 'id': fields.Integer, 'title': fields.String, 'subtitle': fields.String, 'cover_art_thumbnail': fields.String, 'cover_art_full': fields.String, 'created_at': fields.DateTime, 'script': fields.String, 'source': fields.List(fields.Nested(Source.marshal)), 'other': fields.List(fields.Nested(Other.marshal)), } def __repr__(self): return "<{} {}>".format(self.id, self.title)
def uploaded_file(cls): depot_args = dict(cls.__depot_args__) filters = depot_args.pop("filters", []) allowed_files = getattr(cls, "__allowed_file_types__", []) if allowed_files: filters.insert(0, FileTypeCheckFilter(filetypes=allowed_files)) return db.Column( UploadedFileField(filters=filters, **depot_args), nullable=False, info=dict(label=lazy_gettext("Select a file")), )
class CategoryImage(DeclarativeBase): __tablename__ = 'tgappcategories_images' _id = Column(Integer, autoincrement=True, primary_key=True) content = Column(UploadedFileField(upload_storage='category_image')) image_name = Column(Unicode(255)) category_id = Column(Integer, ForeignKey('tgappcategories_categories._id')) category = relationship('Category', backref='images')
class Note(db.Model): """ User model class. """ id = db.Column(db.Integer(), primary_key=True, autoincrement=True) title = db.Column(db.String(256), unique=False) create_time = db.Column(db.DateTime(), default=datetime.now) last_modified = db.Column(db.DateTime(), default=datetime.now) author, author_id = foreign_key("User", backref_name="notes") paper, paper_id = foreign_key("Paper", backref_name="notes") collectors = many_to_many("Note", "User", backref_name="collect_notes") owngroup = many_to_many("Note", "Group", backref_name="notes") content = db.Column(db.Text(), unique=False) annotation_file = db.Column(UploadedFileField())
class User(db.Model): """ User model class. """ id = db.Column(db.Integer(), primary_key=True, autoincrement=True) username = db.Column(db.String(32), unique=True) email = db.Column(db.String(64), unique=True) password = db.Column(db.Binary(32)) join_date = db.Column(db.DateTime(), default=datetime.now) active = db.Column(db.Boolean(), default=False) avatar = db.Column(UploadedFileField()) self_introduction = db.Column(db.Text(), unique=True) contribution = db.Column(db.Integer(), default=0) job = db.Column(db.String(64), unique=True)
class Story(Base): __tablename__ = 'stories' title = db.Column(Text(), nullable=False) author = db.Column(Text()) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb)) description = db.Column(Text(), nullable=False) text = db.Column(Text(), nullable=False) latitude = db.Column(db.Numeric(10, 7)) longitude = db.Column(db.Numeric(10, 7)) def __repr__(self): return f'<Story "{self.title}" {self.id}>'
class Paper(db.Model): """ Paper model class. """ id = db.Column(db.Integer(), primary_key=True, autoincrement=True) title = db.Column(db.String(256), unique=False) abstract = db.Column(db.Text(), unique=False) authors = db.Column(db.String(256), unique=False) conference = db.Column(db.String(128), unique=False) publish_date = db.Column(db.DateTime(), default=datetime.now) # Accurate to the day owners = many_to_many("Paper", "User", backref_name="papers") owngroup = many_to_many("Paper", "Group", backref_name="papers") collectors = many_to_many("Paper", "User", backref_name="collect_papers") paper_file = db.Column(UploadedFileField())
class Contact(DeclarativeBase): __tablename__ = 'contacts' id = Column(Integer, primary_key=True) contact_name = Column(Unicode(255), unique=True, nullable=False) contact_phonenumber = Column(Unicode(48), nullable=False) image = Column( UploadedFileField(upload_storage='contact_image', upload_type=UploadedImageWithThumb)) user_id = Column(Integer, ForeignKey('tg_user.user_id'), index=True, nullable=False)
class Organisation(BaseRequiresVerification): __tablename__ = 'organisations' display_name = db.Column(db.String(t.LEN_DISPLAY_NAME), nullable=False) description = db.Column(db.String(t.LEN_DESCRIPTION), nullable=False) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='images')) users = db.relationship('User', secondary=user_organisations_map, backref='organisations') departments = db.relationship('Department', backref='organisation') def __repr__(self): return f'<Organisation {self.display_name}>'
class Project(DeclarativeBase): """A model that defines a project that the club is working on.""" __tablename__ = 'projects' # Fields id = Column(Integer, autoincrement=True, primary_key=True) team_members = relationship(User, secondary=team_table, back_populates='projects') name = Column(Unicode(1024), unique=True, nullable=False) description = Column(Unicode(4096)) website = Column(Unicode(512)) repository = Column(Unicode(512)) video_url = Column(Unicode(512)) image = Column(UploadedFileField(upload_type=UploadedImageWithThumb))
class Presentation(DeclarativeBase): """A model that defines a club presentation. Presentations are slides, files, or other presentables that the club shares among its cohorts, usually during Meetings. They are displayed on the Presentation page. """ __tablename__ = 'presentation' id = Column(Integer, primary_key=True, autoincrement=True) title = Column(String(32), nullable=False) description = Column(Unicode) date = Column(Date, nullable=False) thumbnail = Column(UploadedFileField(upload_type=UploadedImageWithThumb)) repo_url = Column(Unicode(512)) _other_authors = Column(Unicode(512)) authors = relation( User, secondary=presentation_author_table, backref='presentations') files = relation(PresentationFile) @property def buttons(self): buttons = [ (self.repo_url, 'View repo', 'fa-code-fork') if self.repo_url else None, ] for file in self.files: buttons.append((file.url, file.description, file.icon)) return buttons @property def other_authors(self): if self._other_authors: return tuple(s for s in self._other_authors.split(',') if s) else: return tuple() @other_authors.setter def other_authors(self, oa): if isinstance(oa, str): self._other_authors = ','.join(s.strip() for s in oa.split(',') if s.strip()) elif isinstance(oa, Iterable): self._other_authors = ','.join(s.strip() for s in oa if s.strip())
class Department(BaseRequiresVerification): __tablename__ = 'departments' display_name = db.Column(db.String(t.LEN_DISPLAY_NAME), nullable=False) description = db.Column(db.String(t.LEN_DESCRIPTION), nullable=False) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='images')) organisation_id = db.Column(db.String(t.LEN_UUID), \ db.ForeignKey('organisations.id')) temp_organisation = db.Column(db.String(t.LEN_DISPLAY_NAME)) supporting_evidence = db.relationship('DepartmentFile', backref='department') users = db.relationship('User', secondary=user_departments_map, backref='departments') def __repr__(self): return f'<Department {self.display_name}>'
class User(Base, Model, Timestamp): __tablename__ = "user" email = Column(String(256), unique=True, index=True) display_picture = Column(UploadedFileField()) name = Column(String(256), nullable=False) username = Column(String(256), unique=True, index=True) password = Column(String(256), nullable=False) # if public display in common_feed and everyone, else only to subscribed status = Column(EnumChoiceType(UserType, impl=String(30)), index=True, nullable=False) posts = relationship('Post', backref='owner', lazy='dynamic') @property def all_posts(self): posts = [] for post in self.posts: posts.append("/" + self.username + "/posts/" + post.id) return posts
class File(BASE_MODEL, ZopseduBase): """Dosyalın saklandığı model""" __tablename__ = 'file' id = Column(Integer, autoincrement=True, primary_key=True) user_id = Column(Integer, ForeignKey("users.id")) content = Column( 'content', UploadedFileField(upload_storage="local", upload_type=AllowedUploadedFile)) uploaded_at = Column(DateTime) user = relationship("User") @property def file_object(self): """Kaydedilen contenti file like object olarak geri dondurur.""" fobj = BytesIO() fobj.write(self.content.file.read()) fobj.seek(0) return fobj
def upgrade(): op.drop_table('images') op.create_table( 'images', sa.Column('id', sa.Integer(), sa.ForeignKey('contents.id'), primary_key=True), sa.Column('filename', sa.Unicode(100)), sa.Column('mimetype', sa.String(100)), sa.Column('size', sa.Integer()), sa.Column('data', UploadedFileField())) DBSession.execute(""" INSERT INTO images (id, filename, mimetype, size, data) SELECT f.id, f.filename, f.mimetype, f.size, f.data FROM files f INNER JOIN nodes n ON f.id = n.id WHERE n.type = 'image'""") DBSession.execute(""" DELETE FROM files WHERE id IN (SELECT id FROM images)""")
class FlatFile(DeclarativeBase): __tablename__ = 'flatpages_file' uid = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(99), index=True, unique=True, nullable=False) file = Column(UploadedFileField(upload_storage='flatfiles'), nullable=False) updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) created_at = Column(DateTime, nullable=False, default=datetime.utcnow) author_id = Column(Integer, ForeignKey(primary_key(app_model.User))) author = relation(app_model.User) @cached_property def url(self): return plug_url('flatpages', '/flatfiles/' + self.file.file_id)
class User(UserMixin, Base): __tablename__ = 'auth_user' password = db.Column(db.String(192), nullable=False) primary_email = db.Column(db.String(128), nullable=False, unique=True, \ primary_key=True) email_verified = db.Column(db.Boolean, default=False, nullable=False) date_email_verified = db.Column(db.DateTime) display_name = db.Column(db.String(t.LEN_DISPLAY_NAME)) description = db.Column(db.String(t.LEN_DESCRIPTION)) display_image = db.Column(UploadedFileField( \ upload_type=UploadedImageWithThumb, upload_storage='images')) educational_institution = db.Column(db.String(t.LEN_DISPLAY_NAME)) can_create_departments = db.Column(db.Boolean, default=False, nullable=False) is_admin = db.Column(db.Boolean, default=False, nullable=False) email_addresses = db.relationship('Email', backref='user') matrix_addresses = db.relationship('Matrix', backref='user') developer = db.relationship('Developer', backref='user', uselist=False) def __repr__(self): return f'<User {self.name}>'
def upgrade(): op.create_table( 'projects', sa.Column('id', sa.Integer(), primary_key=True), sa.Column('name', sa.Unicode(1024), nullable=False), sa.Column('description', sa.Unicode(4096)), sa.Column('website', sa.Unicode(512)), sa.Column('repository', sa.Unicode(512)), sa.Column('video_url', sa.Unicode(512)), sa.Column('image', UploadedFileField(upload_type=UploadedImageWithThumb))) # Team XREF table op.create_table( 'team', sa.Column('user_id', sa.Integer(), sa.ForeignKey('tg_user.user_id'), nullable=False), sa.Column('project_id', sa.Integer(), sa.ForeignKey('projects.id'), nullable=False), sa.UniqueConstraint('user_id', 'project_id'))
def data(cls): return cls.__table__.c.get('data', Column(UploadedFileField(cls.data_filters)))
class BulkCSVUpload(Base, Model): __tablename__ = 'bulk_csv_upload' csv = Column(UploadedFileField(), nullable=False)