Ejemplo n.º 1
0
    name = Column(String(1024))
    account_user_id = Column('account_user', ForeignKey(AccountUser.id))

    video = relationship(Video, backref=backref('collaborators', cascade='all, delete-orphan'))
    account_user = relationship(
        AccountUser, backref=backref('collaborator_videos', cascade='all, delete-orphan'))

    @property
    def token(self):
        return self.get_token(self.id)

    @property
    def href(self):
        return url_for('api.videocollaborator', video_id=self.video_id, collaborator_id=self.id)

    @classmethod
    def get_token(cls, id):
        serializer = URLSafeSerializer(current_app.secret_key)
        return serializer.dumps(dict(collaborator=id))


class VideoSeoEmbed(db.Model):
    id = Column(Integer, primary_key=True)
    video_id = Column('video', ForeignKey(Video.id), nullable=False)
    link_url = Column(String(2048))
    title = Column(String(256), nullable=False)
    description = Column(String(256))


event.listen(Video, 'before_insert', genid())
Ejemplo n.º 2
0
@background_on_sqs
def _push_profile_changes_to_dolly(account_user_id, changes="ALL"):
    # TODO: assert first user in account only
    user = AccountUser.query.get(account_user_id)
    account = user and user.account
    if account and account.dolly_user:
        dolly_user = dolly.DollyUser(account.dolly_user, account.dolly_token)
        changed = lambda f: getattr(user, f, None) and (changes == "ALL" or f in changes)
        image_file = lambda filename, field: StringIO(
            download_file(media_bucket, user.get_image_filepath(account.id, filename, field))
        )
        if changed("display_name"):
            dolly_user.set_display_name(user.display_name)
        if changed("description"):
            dolly_user.set_description(user.description)
        if changed("avatar_filename"):
            dolly_user.set_avatar_image(image_file(user.avatar_filename, "avatar"))
        if changed("profile_cover_filename"):
            dolly_user.set_profile_image(image_file(user.profile_cover_filename, "profile_cover"))


@event.listens_for(AccountUser, "after_update")
def _account_user_after_update(mapper, connection, target):
    changes = [a for a in instance_state(target).committed_state if get_history(target, a).has_changes()]
    _push_profile_changes_to_dolly(target.id, changes)


event.listen(Account, "before_insert", genid())
event.listen(AccountUser, "before_insert", genid())