def upgrade():
    from rockpack.mainsite.services.video.models import VideoInstanceLocaleMeta
    from rockpack.mainsite.helpers.db import add_base64_pk
    from rockpack.mainsite.core.dbapi import db

    ### commands auto generated by Alembic - please adjust! ###
    query = VideoInstanceLocaleMeta.query.filter()
    total = query.count()
    step = 400
    for i in xrange(0, total, step):
        print 'group', i, 'step', step
        for v in query.offset(i).limit(step):
            v.id = None
            add_base64_pk(None, None, v, prefix='vl')
            db.session.add(v)
        db.session.commit()

    op.execute("DROP SEQUENCE video_instance_locale_meta_seq CASCADE")
    op.alter_column('video_instance_locale_meta', u'id',
               type_=sa.CHAR(length=24),
               nullable=False)
Ejemplo n.º 2
0

@background_on_sqs
def _update_user(userid, just_registered=False):
    user = User.query.get(userid)

    if just_registered and 'AUTO_FOLLOW_USERS' in app.config:
        locales = app.config['ENABLED_LOCALES']
        locale = user.locale if user.locale in locales else locales[0]
        from .api import save_owner_activity
        for ownerid in app.config['AUTO_FOLLOW_USERS']:
            try:
                save_owner_activity(user.id, 'subscribe_all', ownerid, locale)
            except Exception:
                app.logger.warning('Unable to subscribe to %s', ownerid)

    if just_registered and not app.config.get('TESTING'):
        from rockpack.mainsite.services.oauth.models import ExternalFriend
        ExternalFriend.populate_friends(userid)


@models_committed.connect_via(app)
def on_models_committed(sender, changes):
    for obj, change in changes:
        if isinstance(obj, User):
            if change == 'insert':
                _update_user(obj.id, just_registered=True)


event.listen(User, 'before_insert', lambda m, c, t: add_base64_pk(m, c, t))
Ejemplo n.º 3
0
    instances = list(VideoInstance.query.filter(VideoInstance.video == target.id).values("id"))
    if instances:
        update_video_instance_date_updated([i[0] for i in instances], visible=target.visible)


@background_on_sqs
def _set_auto_tag(channel, video, tag):
    instance = VideoInstance.query.filter_by(channel=channel, video=video).first()
    if instance:
        if instance.tags:
            instance.tags += "," + tag
        else:
            instance.tags = tag
        instance.save()


@event.listens_for(VideoInstance, "before_update")
@event.listens_for(VideoInstance, "before_insert")
def _set_date_tagged(mapper, connection, target):
    if target.tags and get_history(target, "tags").has_changes():
        target.date_tagged = func.now()


event.listen(Video, "before_insert", add_video_pk)
event.listen(VideoInstanceLocaleMeta, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="vl"))
event.listen(VideoInstance, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="vi"))
event.listen(VideoRestriction, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="vr"))
event.listen(VideoThumbnail, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="vt"))
event.listen(Channel, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="ch"))
event.listen(ChannelLocaleMeta, "before_insert", lambda x, y, z: add_base64_pk(x, y, z, prefix="cl"))