Exemple #1
0
 def GET_AUTH(self, capsule_id, slide_id, channel):
     try:
         EditorCapsule.selectBy(id=int(capsule_id),
                                channel=channel).getOne()
         return EditorSlide.selectBy(
             id=int(slide_id),
             capsule=int(capsule_id)).getOne().to_json_api()
     except SQLObjectNotFound:
         raise web.notfound()
 def render_page(self, channel, capsules=None):
     now = datetime.datetime.now()
     if capsules is None:
         capsules_all = EditorCapsule.selectBy(channel=channel.id)
         capsules = capsules_all.filter(EditorCapsule.q.validity_to > now)
         expired_capsules = capsules_all.filter(
             EditorCapsule.q.validity_to <= now)
     else:
         capsules_all = capsules
         expired_capsules = capsules_all.filter(
             EditorCapsule.q.validity_to <= now)
         capsules = capsules_all.filter(EditorCapsule.q.validity_to > now)
     if 'capsule_validity' in channel.plugin_config:
         validity = int(channel.plugin_config['capsule_validity'])
     else:
         validity = int(
             channel.plugin.channels_params['capsule_validity']['default'])
     vertical = channel.get_config_param('vertical')
     default_from = datetime.datetime.now()
     time_delta = datetime.timedelta(hours=validity)
     default_to = default_from + time_delta
     return self.renderer.capsules(
         channel=channel,
         capsules=capsules,
         expired_capsules=expired_capsules,
         capsules_all=capsules_all,
         default_from=default_from.replace(microsecond=0).isoformat(),
         default_to=default_to.replace(microsecond=0).isoformat(),
         vertical=vertical)
Exemple #3
0
    def POST_AUTH(self, capsule_id, channel):
        try:
            post_data = flask.request.get_json(force=True)
        except JSONDecodeError:
            resp.badrequest()

        try:
            c = EditorCapsule.selectBy(id=int(capsule_id),
                                       channel=channel).getOne()
        except SQLObjectNotFound:
            resp.notfound()

        if {'duration', 'template', 'content'} != set(post_data.keys()):
            resp.badrequest()
        try:
            s = EditorSlide(s_order=c.slides.count(), capsule=c, **post_data)
        except SQLObjectIntegrityError:
            resp.badrequest()

        EditorSlide.rectify_s_order(c.id)
        response = resp.created()
        response.header[
            'Location'] = '/channels/{}/api/capsules/{}/slides/{}'.format(
                channel.id, capsule_id, s.id)
        return response
Exemple #4
0
 def GET(self, channel):
     capsules = EditorCapsule.selectBy(channel=channel).filter(
         EditorCapsule.q.validity_to > datetime.now()).orderBy('c_order')
     list_to_render = []
     for c in capsules:
         list_to_render.append(c.to_plugin_capsule())
     PluginManager.dereference_assets(list_to_render)
     return self.ictv_renderer.preview_capsules(list_to_render)
Exemple #5
0
 def DELETE_AUTH(self, capsule_id, channel):
     try:
         c = EditorCapsule.selectBy(id=int(capsule_id),
                                    channel=channel).getOne()
         c.destroySelf()
     except SQLObjectNotFound:
         raise web.notfound()
     raise web.nocontent()
Exemple #6
0
    def DELETE_AUTH(self, capsule_id, slide_id, channel):
        try:
            c = EditorCapsule.selectBy(id=int(capsule_id),
                                       channel=channel).getOne()
            EditorSlide.selectBy(id=int(slide_id),
                                 capsule=c).getOne().destroySelf()
        except SQLObjectNotFound:
            resp.notfound()

        resp.nocontent()
Exemple #7
0
    def PATCH_AUTH(self, capsule_id, channel):
        try:
            post_data = json.loads(web.data().decode())
        except JSONDecodeError:
            raise web.badrequest()

        try:
            c = EditorCapsule.selectBy(id=int(capsule_id),
                                       channel=channel).getOne()
        except SQLObjectNotFound:
            raise web.notfound()

        if 'name' in post_data and len(post_data['name']) < 3:
            raise web.badrequest()

        if 'validity' in post_data:
            validity_from, validity_to = post_data['validity']
            if not (type(validity_from) == type(validity_to) ==
                    int) or validity_to < validity_from:
                raise web.badrequest()
            try:
                validity_from, validity_to = datetime.fromtimestamp(
                    validity_from), datetime.fromtimestamp(validity_to)
            except (TypeError, ValueError):
                raise web.badrequest()
            post_data['validity_from'] = validity_from
            post_data['validity_to'] = validity_to
            del post_data['validity']

        update_dict = {
            k: v
            for k, v in filter(
                lambda x: x[0] in
                ['name', 'theme', 'validity_from', 'validity_to'],
                post_data.items())
        }
        try:
            c.set(**update_dict)
        except DuplicateEntryError:
            raise web.badrequest()

        raise web.nocontent()
Exemple #8
0
    def PATCH_AUTH(self, capsule_id, slide_id, channel):
        try:
            post_data = json.loads(web.data().decode())
        except JSONDecodeError:
            raise web.badrequest()

        try:
            c = EditorCapsule.selectBy(id=int(capsule_id),
                                       channel=channel).getOne()
            s = EditorSlide.selectBy(id=int(slide_id), capsule=c).getOne()
        except SQLObjectNotFound:
            raise web.notfound()

        update_dict = {
            k: v
            for k, v in filter(
                lambda x: x[0] in ['duration', 'template', 'content'],
                post_data.items())
        }
        s.set(**update_dict)

        raise web.nocontent()
Exemple #9
0
    def POST_AUTH(self, channel):
        try:
            post_data = flask.request.get_json(force=True)
        except JSONDecodeError:
            resp.badrequest()

        if {'name', 'theme', 'validity'} != set(post_data.keys()):
            resp.badrequest()

        if 'name' in post_data and len(post_data['name']) < 3:
            resp.badrequest()

        validity_from, validity_to = post_data['validity']
        if not (type(validity_from) == type(validity_to) ==
                int) or validity_to < validity_from:
            resp.badrequest()
        try:
            validity_from, validity_to = datetime.fromtimestamp(
                validity_from), datetime.fromtimestamp(validity_to)
        except (TypeError, ValueError):
            resp.badrequest()

        try:
            c = EditorCapsule(
                name=post_data['name'],
                theme=post_data['theme'],
                validity_from=validity_from,
                validity_to=validity_to,
                channel=channel,
                c_order=EditorCapsule.selectBy(channel=channel).count())
        except DuplicateEntryError:
            resp.badrequest()
        EditorCapsule.rectify_c_order(channel.id)
        response = resp.created()
        response.headers['Location'] = '/channels/{}/api/capsules/{}'.format(
            channel.id, c.id)
        return response
Exemple #10
0
    def POST_AUTH(self, channel):
        try:
            post_data = json.loads(web.data().decode())
        except JSONDecodeError:
            raise web.badrequest()

        if {'name', 'theme', 'validity'} != set(post_data.keys()):
            raise web.badrequest()

        if 'name' in post_data and len(post_data['name']) < 3:
            raise web.badrequest()

        validity_from, validity_to = post_data['validity']
        if not (type(validity_from) == type(validity_to) ==
                int) or validity_to < validity_from:
            raise web.badrequest()
        try:
            validity_from, validity_to = datetime.fromtimestamp(
                validity_from), datetime.fromtimestamp(validity_to)
        except (TypeError, ValueError):
            raise web.badrequest()

        try:
            c = EditorCapsule(
                name=post_data['name'],
                theme=post_data['theme'],
                validity_from=validity_from,
                validity_to=validity_to,
                channel=channel,
                c_order=EditorCapsule.selectBy(channel=channel).count())
        except DuplicateEntryError:
            raise web.badrequest()
        EditorCapsule.rectify_c_order(channel.id)
        web.header('Location',
                   '/channels/{}/api/capsules/{}'.format(channel.id, c.id))
        raise web.created()
Exemple #11
0
    def POST_AUTH(self, capsule_id, channel):
        try:
            post_data = json.loads(web.data().decode())
        except JSONDecodeError:
            raise web.badrequest()

        try:
            c = EditorCapsule.selectBy(id=int(capsule_id),
                                       channel=channel).getOne()
        except SQLObjectNotFound:
            raise web.notfound()

        if {'duration', 'template', 'content'} != set(post_data.keys()):
            raise web.badrequest()
        try:
            s = EditorSlide(s_order=c.slides.count(), capsule=c, **post_data)
        except SQLObjectIntegrityError:
            raise web.badrequest()

        EditorSlide.rectify_s_order(c.id)
        web.header(
            'Location', '/channels/{}/api/capsules/{}/slides/{}'.format(
                channel.id, capsule_id, s.id))
        raise web.created()
Exemple #12
0
 def GET_AUTH(self, channel):
     return [
         c.to_json_api() for c in EditorCapsule.selectBy(channel=channel)
     ]
Exemple #13
0
 def GET_AUTH(self, capsule_id, channel):
     try:
         return EditorCapsule.selectBy(
             id=int(capsule_id), channel=channel).getOne().to_json_api()
     except SQLObjectNotFound:
         resp.notfound()