Beispiel #1
0
def get_target_programs():
    result = dict()
    schemas = db.get_schemas()
    for schema in schemas:
        data = schema["cached_data"]
        if not data:
            data = _load_targets_data(schema["url"])
            if not data:
                continue
            schema["cached_data"] = json.dumps(data)
            db.update_schema(schema)
        else:
            data = json.loads(data)

        targets = data["target_programs"]
        for target in targets:
            result.setdefault(
                target,
                {
                    "targetProgram": target,
                    "description": targets[target]["description"],
                    "versions": list(),
                    "urls": dict(),
                },
            )
            result[target]["versions"].append(data["id"])
            result[target]["urls"][data["id"]] = schema["url"]

    return [result[k] for k in result]
Beispiel #2
0
    def get(self):
        """Get a list of all available schemas."""
        results = db.get_schemas()
        openid = api_utils.get_user_id()
        for result in results:
            if result['openid'] != openid:
                result['openid'] = None
        results = sorted(results,
            cmp=lambda x, y: cmp(x['description'], y['description'])
                if x['openid'] == y['openid'] else -1 if x['openid'] else 1)

        # TODO: add paging

        page = {'results': results,
                'pagination': {
                    'current_page': 1,
                    'total_pages': 1
                }}
        return page