db = app.db class Venue(app.model.PcObject, app.model.HasThumbMixin, app.model.ProvidableMixin, db.Model): id = db.Column(db.BigInteger, primary_key=True) name = db.Column(db.String(140), nullable=False) address = db.Column(db.String(200), nullable=True) latitude = db.Column(db.Numeric(8, 5), nullable=True) longitude = db.Column(db.Numeric(8, 5), nullable=True) Venue.__ts_vector__ = create_tsvector( cast(coalesce(Venue.name, ''), TEXT) ) Venue.__table_args__ = ( Index( 'idx_venue_fts', Venue.__ts_vector__, postgresql_using='gin' ), ) app.model.Venue = Venue
type = db.Column(db.Enum(app.model.EventType), nullable=True) name = db.Column(db.String(140), nullable=False) description = db.Column(db.Text, nullable=True) conditions = db.Column(db.String(120), nullable=True) ageMin = db.Column(db.Integer, nullable=True) ageMax = db.Column(db.Integer, nullable=True) #TODO (from schema.org) #doorTime (datetime) #eventStatus #isAccessibleForFree (boolean) #typicalAgeRange → = $ageMin-$ageMax accessibility = db.Column(db.Binary(1), nullable=False, default=bytes([0])) mediaUrls = db.Column(ARRAY(db.String(120)), nullable=False, default=[]) durationMinutes = db.Column(db.Integer, nullable=False) Event.__ts_vector__ = create_tsvector(cast(coalesce(Event.name, ''), TEXT)) Event.__table_args__ = (Index('idx_event_fts', Event.__ts_vector__, postgresql_using='gin'), ) app.model.Event = Event
def is_active(self): return True def is_anonymous(self): return False def populateFromDict(self, dct): super(User, self).populateFromDict(dct) if dct.__contains__('password') and dct['password']: self.setPassword(dct['password']) def setPassword(self, newpass): self.clearTextPassword = newpass self.password = bcrypt.hashpw(newpass.encode('utf-8'), bcrypt.gensalt()) def hasRights(self, roleType): return Role.query\ .filter((Role.userId == self.id) & (Role.type == roleType))\ .first() is not None User.__ts_vector__ = create_tsvector( cast(coalesce(User.email, ''), TEXT), cast(coalesce(User.publicName, ''), TEXT), ) User.__table_args__ = (Index('idx_event_fts', User.__ts_vector__, postgresql_using='gin'), )
siren = db.Column( db.String(9), nullable=True, unique=True ) # FIXME: should not be nullable, is until we have all SIRENs filled in the DB def make_admin(self, admin): if admin: user_offerer = app.model.UserOfferer() user_offerer.offerer = self user_offerer.user = admin user_offerer.rights = app.model.RightsType.admin return user_offerer def errors(self): errors = super(Offerer, self).errors() if self.siren is not None\ and not len(self.siren) == 9: errors.addError('siren', 'Ce code SIREN est invalide') return errors Offerer.__ts_vector__ = create_tsvector( cast(coalesce(Offerer.name, ''), TEXT), cast(coalesce(Offerer.address, ''), TEXT), cast(coalesce(Offerer.siren, ''), TEXT)) Offerer.__table_args__ = (Index('idx_offerer_fts', Offerer.__ts_vector__, postgresql_using='gin'), ) app.model.Offerer = Offerer
db.Enum(ThingType), db.CheckConstraint( "\"type\" <> 'Book' OR \"extraData\"->>'prix_livre' SIMILAR TO '[0-9]+(.[0-9]*|)'", name='check_thing_book_has_price'), db.CheckConstraint( "\"type\" <> 'Book' OR NOT \"extraData\"->'author' IS NULL", name='check_thing_book_has_author'), db.CheckConstraint( "\"type\" <> 'Book' OR \"idAtProviders\" SIMILAR TO '[0-9]{13}'", name='check_thing_book_has_ean13'), nullable=False) name = db.Column(db.String(140), nullable=False) description = db.Column(db.Text, nullable=True) mediaUrls = db.Column(ARRAY(db.String(120)), nullable=False, default=[]) Thing.__ts_vector__ = create_tsvector( cast(coalesce(Thing.name, ''), TEXT), coalesce(Thing.extraData['author'].cast(TEXT), ''), coalesce(Thing.extraData['byArtist'].cast(TEXT), ''), ) Thing.__table_args__ = (Index('idx_thing_fts', Thing.__ts_vector__, postgresql_using='gin'), ) app.model.Thing = Thing
errors.addError('siret', 'Le code SIRET doit correspondre à un établissement de votre structure') return errors @listens_for(Venue, 'before_insert') def before_insert(mapper, connect, self): self.store_department_code() @listens_for(Venue, 'before_update') def before_update(mapper, connect, self): self.store_department_code() Venue.__ts_vector__ = create_tsvector( cast(coalesce(Venue.name, ''), TEXT), cast(coalesce(Venue.address, ''), TEXT), cast(coalesce(Venue.siret, ''), TEXT) ) Venue.__table_args__ = ( Index( 'idx_venue_fts', Venue.__ts_vector__, postgresql_using='gin' ), ) app.model.Venue = Venue