def default(self, *args, **kwargs):
     if args:
         if kwargs.get('feature', None):
             return self.events(slug=sluggify(args[0]),
                                feature=sluggify(kwargs['feature']))
         else:
             return self.features(slug=sluggify(args[0]))
     else:
         raise HTTPRedirect('index')
示例#2
0
 def default(self, *args, **kwargs):
     if args:
         if kwargs.get('feature', None):
             return self.events(
                 slug=sluggify(args[0]),
                 feature=sluggify(kwargs['feature']))
         else:
             return self.features(slug=sluggify(args[0]))
     else:
         raise HTTPRedirect('index')
示例#3
0
def upgrade():
    if is_sqlite:
        with op.batch_alter_table(
                'attraction',
                reflect_kwargs=sqlite_reflect_kwargs) as batch_op:
            batch_op.add_column(
                sa.Column('slug',
                          sa.Unicode(),
                          server_default='',
                          nullable=False))
        with op.batch_alter_table(
                'attraction_feature',
                reflect_kwargs=sqlite_reflect_kwargs) as batch_op:
            batch_op.add_column(
                sa.Column('slug',
                          sa.Unicode(),
                          server_default='',
                          nullable=False))
    else:
        op.add_column(
            'attraction',
            sa.Column('slug', sa.Unicode(), server_default='', nullable=False))
        op.add_column(
            'attraction_feature',
            sa.Column('slug', sa.Unicode(), server_default='', nullable=False))

    connection = op.get_bind()
    for attraction in connection.execute(attraction_table.select()):
        connection.execute(attraction_table.update().where(
            attraction_table.c.id == attraction.id).values(
                slug=sluggify(attraction.name)))

    for feature in connection.execute(attraction_feature_table.select()):
        connection.execute(attraction_feature_table.update().where(
            attraction_feature_table.c.id == feature.id).values(
                slug=sluggify(feature.name)))

    if is_sqlite:
        with op.batch_alter_table(
                'attraction',
                reflect_kwargs=sqlite_reflect_kwargs) as batch_op:
            batch_op.create_unique_constraint(op.f('uq_attraction_slug'),
                                              ['slug'])
        with op.batch_alter_table(
                'attraction_feature',
                reflect_kwargs=sqlite_reflect_kwargs) as batch_op:
            batch_op.create_unique_constraint(
                op.f('uq_attraction_feature_slug'), ['slug', 'attraction_id'])
    else:
        op.create_unique_constraint(op.f('uq_attraction_slug'), 'attraction',
                                    ['slug'])
        op.create_unique_constraint(op.f('uq_attraction_feature_slug'),
                                    'attraction_feature',
                                    ['slug', 'attraction_id'])
示例#4
0
    def checkin(self, session, message='', **params):
        id = params.get('id')
        if not id:
            raise HTTPRedirect('index')

        try:
            uuid.UUID(id)
            filters = [Attraction.id == id]
        except Exception:
            filters = [Attraction.slug.startswith(sluggify(id))]

        attraction = session.query(Attraction).filter(*filters).first()
        if not attraction:
            raise HTTPRedirect('index')

        return {'attraction': attraction, 'message': message}
示例#5
0
    def checkin(self, session, message='', **params):
        id = params.get('id')
        if not id:
            raise HTTPRedirect('index')

        try:
            uuid.UUID(id)
            filters = [Attraction.id == id]
        except Exception:
            filters = [Attraction.slug.startswith(sluggify(id))]

        attraction = session.query(Attraction).filter(*filters).first()
        if not attraction:
            raise HTTPRedirect('index')

        return {'attraction': attraction, 'message': message}
示例#6
0
 def _sluggify_name(self):
     self.slug = sluggify(self.name)
示例#7
0
 def _sluggify_name(self):
     self.slug = sluggify(self.name)