Exemplo n.º 1
0
    def _create_dash(self, name, author):
        tmp_time = time.time()
        meta = {'author': author, 'name': name, 'time_modified': tmp_time}
        default_option = {"x": [], "y": []}
        content = {
            "0": {"x": 0, "y": 5, "width": 6, "height": 5, "key": "none", "type": "none", "option": default_option},
            "1": {"x": 6, "y": 5, "width": 6, "height": 5, "key": "none", "type": "none", "option": default_option},
            "2": {"x": 0, "y": 0, "width": 6, "height": 5, "key": "none", "type": "none", "option": default_option},
            "3": {"x": 6, "y": 0, "width": 6, "height": 5, "key": "none", "type": "none", "option": default_option},
        }

        dash_id = r_db.zcount(config.DASH_ID_KEY, '-inf', '+inf') + 1
        meta['time_modified'] = tmp_time
        meta['id'] = dash_id
        meta['author'] = author
        meta['name'] = name
        for i in content:
            content[i].update({'graph_name': 'graph name ' + i, 'id': i})

        content = dict(grid=content, name=meta['name'], id=dash_id)
        r_db.zadd(config.DASH_ID_KEY, dash_id, tmp_time)
        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(content))

        return (dash_id, meta, content)
Exemplo n.º 2
0
    def create_dash(self, name, author):
        tmp_time = time.time()
        meta = {'author': author, 'name': name, 'time_modified': tmp_time}
        default_option = {"x": [], "y": []}
        content = {
            "0": {
                "x": 0,
                "y": 5,
                "width": 6,
                "height": 5,
                "key": "none",
                "type": "none",
                "option": default_option
            },
            "1": {
                "x": 6,
                "y": 5,
                "width": 6,
                "height": 5,
                "key": "none",
                "type": "none",
                "option": default_option
            },
            "2": {
                "x": 0,
                "y": 0,
                "width": 6,
                "height": 5,
                "key": "none",
                "type": "none",
                "option": default_option
            },
            "3": {
                "x": 6,
                "y": 0,
                "width": 6,
                "height": 5,
                "key": "none",
                "type": "none",
                "option": default_option
            },
        }

        dash_id = r_db.zcount(config.DASH_ID_KEY, '-inf', '+inf') + 1
        meta['time_modified'] = tmp_time
        meta['id'] = dash_id
        meta['author'] = author
        meta['name'] = name
        for i in content:
            content[i].update({'graph_name': 'graph name ' + i, 'id': i})

        content = dict(grid=content, name=meta['name'], id=dash_id)
        r_db.zadd(config.DASH_ID_KEY, dash_id, tmp_time)
        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(content))

        return meta
Exemplo n.º 3
0
    def _update_dash(self, dash_id, data):
        current_time = time.time()

        meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id))
        meta.update({'name': '' + data['name'],
                     'time_modified': int(current_time)})
        content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id))
        content.update(data)

        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data))

        updated = {
            "meta": r_db.hget(config.DASH_META_KEY, dash_id),
            "content": r_db.hget(config.DASH_CONTENT_KEY, dash_id),
        }

        return updated
Exemplo n.º 4
0
    def _update_dash(self, dash_id, data):
        current_time = time.time()

        meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id))
        meta.update({
            'name': '' + data['name'],
            'time_modified': int(current_time)
        })
        content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id))
        content.update(data)

        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data))

        updated = {
            "meta": r_db.hget(config.DASH_META_KEY, dash_id),
            "content": r_db.hget(config.DASH_CONTENT_KEY, dash_id),
        }

        return updated
Exemplo n.º 5
0
    def put(self, dash_id=0):
        """Update a dash meta and content, return updated dash content.

        Args:
            dash_id: dashboard id.

        Returns:
            A dict containing the updated content of that dashboard, not include the meta info.
        """
        data = request.get_json()
        current_time = time.time()

        meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id))
        meta.update({'name': '' + data['name'],
                     'time_modified': int(current_time)})
        content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id))
        content.update(data)

        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data))

        return build_response(dict(data=dash_id, code=200))
Exemplo n.º 6
0
    def put(self, dash_id=0):
        """Update a dash meta and content, return updated dash content.

        Args:
            dash_id: dashboard id.

        Returns:
            A dict containing the updated content of that dashboard, not include the meta info.
        """
        data = request.get_json()
        current_time = time.time()

        meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id))
        meta.update({
            'name': '' + data['name'],
            'time_modified': int(current_time)
        })
        content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id))
        content.update(data)

        r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta))
        r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data))

        return build_response(dict(data=dash_id, code=200))