class Release(db.Model): id = db.Column(db.Integer, primary_key=True) description = db.Column(UnicodeText, nullable=False) download_url = db.Column(db.String(2048, convert_unicode=True)) home_page = db.Column(db.String(2048, convert_unicode=True)) version = db.Column(db.String(80, convert_unicode=True)) keywords = db.Column(db.String(255, convert_unicode=True)) md5_digest = db.Column(db.String(32), nullable=False) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow) package_id = db.Column(db.Integer, db.ForeignKey('package.id', name='_fk_release_package'), nullable=False) package = db.relationship( 'Package', backref=db.backref('releases', lazy='dynamic', cascade='all, delete-orphan'), lazy='joined', ) def __repr__(self): return "<Release {0.version} for package {0.package.name}>".format( self)
class Package(db.Model): """Represent a simple package """ id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255, convert_unicode=True), nullable=False, unique=True) summary = db.Column(db.String(255, convert_unicode=True)) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow) maintainers = db.relationship('User', secondary=package_maintainers, lazy='dynamic', backref='packages') @property def sorted_releases(self): releases = self.releases.all() return sorted(releases, key=lambda r: parse_version(r.version), reverse=True) @property def latest_release(self): return next(iter(self.sorted_releases), None) def __repr__(self): return "<Package {0.name}>".format(self)
class User(db.Model): ROLES = ['admin', 'developer', 'installer', 'maintainer'] id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), nullable=False, unique=True) email = db.Column(db.String(255), nullable=False, unique=True) password_hash = db.Column(db.String(255), nullable=False) is_active = db.Column(db.Boolean, default=True) role = db.Column(db.String(80), nullable=True) @validates('role') def validate_role(self, key, role): assert role in self.ROLES or role is None return role @property def is_authenticated(self): return True @property def is_anonymous(self): return False @property def is_admin(self): return self.role == 'admin' def get_id(self): try: return unicode(self.id) except NameError: return str(self.id) def __repr__(self): return "<User {0.username}>".format(self)
class User(db.Model): ROLES = ['admin', 'developer', 'installer', 'maintainer'] id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), nullable=False, unique=True) email = db.Column(db.String(255), nullable=False, unique=True) password_hash = db.Column(db.String(255), nullable=False) is_active = db.Column(db.Boolean, default=True) role = db.Column(db.String(80), nullable=True) @validates('role') def validate_role(self, key, role): assert role in self.ROLES or role is None return role @property def is_authenticated(self): return True @property def is_anonymous(self): return False @property def is_admin(self): return self.role == 'admin' @staticmethod def email_is_in_use(email): q = db.session.query(User.id).filter(User.email == email) return db.session.query(q.exists()).scalar() @staticmethod def username_is_in_use(username): q = db.session.query(User.id).filter(User.username == username) return db.session.query(q.exists()).scalar() def get_id(self): try: return unicode(self.id) except NameError: return str(self.id) def __repr__(self): return "<User {0.username}>".format(self)
import datetime from pkg_resources import parse_version from extrapypi.extensions import db package_maintainers = db.Table( 'package_maintainers', db.Column( 'package_id', db.Integer, db.ForeignKey('package.id', name='_fk_package_maintainers_package')), db.Column('user_id', db.Integer, db.ForeignKey('user.id', name='_fk_package_maintainers_user')), ) class Package(db.Model): """Represent a simple package """ id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255, convert_unicode=True), nullable=False, unique=True) summary = db.Column(db.String(255, convert_unicode=True)) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow) maintainers = db.relationship('User', secondary=package_maintainers, lazy='dynamic', backref='packages')