Beispiel #1
0
    def patch(self, asset_id):
        data = json.loads(request.data)
        with db.conn(settings['database']) as conn:

            asset = assets_helper.read(conn, asset_id)
            if not asset:
                raise Exception('Asset not found.')
            update_asset(asset, data)

            assets = assets_helper.read(conn)
            ids_of_active_assets = [
                x['asset_id'] for x in assets if x['is_active']
            ]

            asset = assets_helper.update(conn, asset_id, asset)

            try:
                ids_of_active_assets.remove(asset['asset_id'])
            except ValueError:
                pass
            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'],
                                            asset['asset_id'])

            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset_id)
Beispiel #2
0
    def test_set_order_empty(self):
        assets = [asset_x, asset_y, asset_z]

        assets_helper.create_multiple(self.conn, assets)
        assets_helper.save_ordering(self.conn, [])

        fetched = assets_helper.read(self.conn)

        self.assertEquals([0, 0, 0], [asset['play_order'] for asset in fetched])
Beispiel #3
0
    def test_set_order_empty(self):
        assets = [asset_x, asset_y, asset_z]

        assets_helper.create_multiple(self.conn, assets)
        assets_helper.save_ordering(self.conn, [])

        fetched = assets_helper.read(self.conn)

        self.assertEquals([0, 0, 0],
                          [asset['play_order'] for asset in fetched])
Beispiel #4
0
    def post(self):
        asset = prepare_asset_v1_2(request)
        if url_fails(asset['uri']):
            raise Exception("Could not retrieve file. Check the asset URL.")
        with db.conn(settings['database']) as conn:
            assets = assets_helper.read(conn)
            ids_of_active_assets = [x['asset_id'] for x in assets if x['is_active']]

            asset = assets_helper.create(conn, asset)

            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'], asset['asset_id'])
            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset['asset_id']), 201
Beispiel #5
0
    def test_set_order(self):
        assets = [asset_x, asset_y, asset_z, asset_w]
        for_order = [asset_y, asset_x]

        assets_helper.create_multiple(self.conn, assets)
        assets_helper.save_ordering(self.conn,
                                    [asset['asset_id'] for asset in for_order])

        fetched = assets_helper.read(self.conn)

        self.assertEquals([(0, asset_y['asset_id']), (1, asset_x['asset_id']),
                           (2, asset_z['asset_id']), (2, asset_w['asset_id'])],
                          [(asset['play_order'], asset['asset_id'])
                           for asset in fetched])
Beispiel #6
0
    def post(self):
        asset = prepare_asset_v1_2(request)
        if url_fails(asset['uri']):
            raise Exception("Could not retrieve file. Check the asset URL.")
        with db.conn(settings['database']) as conn:
            assets = assets_helper.read(conn)
            ids_of_active_assets = [x['asset_id'] for x in assets if x['is_active']]

            asset = assets_helper.create(conn, asset)

            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'], asset['asset_id'])
            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset['asset_id']), 201
Beispiel #7
0
    def test_set_order(self):
        assets = [asset_x, asset_y, asset_z, asset_w]
        for_order = [asset_y, asset_x]

        assets_helper.create_multiple(self.conn, assets)
        assets_helper.save_ordering(self.conn, [asset['asset_id'] for asset in for_order])

        fetched = assets_helper.read(self.conn)

        self.assertEquals(
            [(0, asset_y['asset_id']),
             (1, asset_x['asset_id']),
             (2, asset_z['asset_id']),
             (2, asset_w['asset_id'])],
            [(asset['play_order'], asset['asset_id']) for asset in fetched])
Beispiel #8
0
    def put(self, asset_id):
        asset = prepare_asset_v1_2(request, asset_id)
        with db.conn(settings['database']) as conn:
            assets = assets_helper.read(conn)
            ids_of_active_assets = [x['asset_id'] for x in assets if x['is_active']]

            asset = assets_helper.update(conn, asset_id, asset)

            try:
                ids_of_active_assets.remove(asset['asset_id'])
            except ValueError:
                pass
            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'], asset['asset_id'])

            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset_id)
Beispiel #9
0
    def put(self, asset_id):
        asset = prepare_asset_v1_2(request, asset_id)
        with db.conn(settings['database']) as conn:
            assets = assets_helper.read(conn)
            ids_of_active_assets = [x['asset_id'] for x in assets if x['is_active']]

            asset = assets_helper.update(conn, asset_id, asset)

            try:
                ids_of_active_assets.remove(asset['asset_id'])
            except ValueError:
                pass
            if asset['is_active']:
                ids_of_active_assets.insert(asset['play_order'], asset['asset_id'])

            assets_helper.save_ordering(conn, ids_of_active_assets)
            return assets_helper.read(conn, asset_id)
Beispiel #10
0
    def post(self):
        asset = prepare_asset_v1_2(request)
        if url_fails(asset['uri']):
            raise Exception("Could not retrieve file. Check the asset URL.")
        with db.conn(settings['database']) as conn:
            if (asset['mimetype'] == 'presentation'
                    or asset['mimetype'] == 'pdf'):
                createMultipleAssetsFromPresentationOrPdf(asset, conn)
                #return assets_helper.read(conn, asset['asset_id']),201
            else:
                assets = assets_helper.read(conn)
                ids_of_active_assets = [
                    x['asset_id'] for x in assets if x['is_active']
                ]

                asset = assets_helper.create(conn, asset)

                if asset['is_active']:
                    ids_of_active_assets.insert(asset['play_order'],
                                                asset['asset_id'])
                assets_helper.save_ordering(conn, ids_of_active_assets)
                return assets_helper.read(conn, asset['asset_id']), 201
Beispiel #11
0
 def post(self):
     with db.conn(settings['database']) as conn:
         assets_helper.save_ordering(conn,
                                     request.form.get('ids', '').split(','))
Beispiel #12
0
 def post(self):
     with db.conn(settings['database']) as conn:
         assets_helper.save_ordering(conn, request.form.get('ids', '').split(','))
Beispiel #13
0
def playlist_order():
    assets_helper.save_ordering(db_conn,
                                request.POST.get('ids', '').split(','))
Beispiel #14
0
def playlist_order():
    with db.conn(settings['database']) as conn:
        assets_helper.save_ordering(conn,
                                    request.POST.get('ids', '').split(','))
Beispiel #15
0
def playlist_order():
    assets_helper.save_ordering(db_conn, request.POST.get('ids', '').split(','))
Beispiel #16
0
def playlist_order():
    with db.conn(settings['database']) as conn:
        assets_helper.save_ordering(conn, request.POST.get('ids', '').split(','))