Beispiel #1
0
def user(db, lang, username=None, format=None):
    params, username, errors = _user(db, lang, username)

    for error in errors:
        error["subtitle"] = i10n_select_auto(error["subtitle"], lang)
        error["title"] = i10n_select_auto(error["title"], lang)
        error["menu"] = i10n_select_auto(error["menu"], lang)

    if not params.users:
        return template('byuser/index')

    count = len(errors)

    if format == 'rss':
        response.content_type = "application/rss+xml"
        return template('byuser/byuser.rss',
                        username=username,
                        users=params.users,
                        count=count,
                        errors=errors,
                        website=utils.website + '/' + lang[0])
    else:
        return template('byuser/byuser',
                        username=username,
                        users=params.users,
                        count=count,
                        errors=errors,
                        website=utils.website + '/' + lang[0],
                        main_website=utils.main_website,
                        remote_url_read=utils.remote_url_read,
                        html_escape=html_escape)
Beispiel #2
0
def user(db, lang, username=None, format=None):
    params, username, errors = _user(db, lang, username)

    for error in errors:
        error["subtitle"] = i10n_select_auto(error["subtitle"], lang)
        error["title"] = i10n_select_auto(error["title"], lang)
        error["menu"] = i10n_select_auto(error["menu"], lang)
        error['timestamp'] = str(error['timestamp'])

    count = len(errors)

    if format == 'rss':
        response.content_type = "application/rss+xml"
        return template('byuser/byuser.rss',
                        username=username,
                        users=params.users,
                        count=count,
                        errors=errors,
                        website=utils.website + '/' + lang[0])
    else:
        return dict(username=username,
                    users=params.users,
                    count=count,
                    errors=list(map(dict, errors)),
                    website=utils.website + '/' + lang[0],
                    main_website=utils.main_website,
                    remote_url_read=utils.remote_url_read)
Beispiel #3
0
def index(db, lang, format):
    if "false-positive" in request.path:
        title = _("False positives")
        gen = "false-positive"
    elif "done" in request.path:
        title = _("Fixed issues")
        gen = "done"
    else:
        title = _("Information")
        gen = "error"

    params = Params()
    params.status = {
        "error": "open",
        "false-positive": "false",
        "done": "done"
    }[gen]
    params.fixable = None

    items = query_meta._items_menu(db, lang)
    for res in items:
        if params.item == str(res["item"]):
            title += ' - ' + res['menu']['auto']

    params.limit = request.params.get('limit', type=int, default=100)
    if params.limit > 10000:
        params.limit = 10000

    params.full = True
    errors = query._gets(db, params)
    for error in errors:
        error["subtitle"] = i10n_select_auto(error["subtitle"], lang)
        error["title"] = i10n_select_auto(error["title"], lang)
        error["menu"] = i10n_select_auto(error["menu"], lang)

    if format == 'rss':
        response.content_type = 'application/rss+xml'
        tpl = 'errors/list.rss'
    elif format == 'gpx':
        response.content_type = 'application/gpx+xml'
        tpl = 'errors/list.gpx'
    elif format == 'kml':
        response.content_type = 'application/vnd.google-earth.kml+xml'
        tpl = 'errors/list.kml'
    elif format == 'josm':
        objects = set(
            sum(
                map(
                    lambda error: list(
                        map(
                            lambda elem: elem['type'].lower() + str(elem[
                                'id']), error['elems'] or [])), errors), []))
        response.status = 302
        response.set_header(
            'Location',
            'http://localhost:8111/load_object?objects=%s' % ','.join(objects))
        return
    elif format == 'csv':
        output = io.StringIO()
        writer = csv.writer(output)
        h = [
            'uuid', 'source', 'item', 'class', 'level', 'title', 'subtitle',
            'country', 'analyser', 'timestamp', 'username', 'lat', 'lon',
            'elems'
        ]
        hh = {'source': 'source_id'}
        writer.writerow(h)
        for res in errors:
            usernames = list(
                map(lambda elem: elem.get("username", ""), res['elems'] or []))
            elems = '_'.join(
                map(
                    lambda elem: {
                        'N': 'node',
                        'W': 'way',
                        'R': 'relation'
                    }[elem['type']] + str(elem['id']), res['elems'] or []))
            writer.writerow(
                list(
                    map(
                        lambda a: usernames if a == 'username' else elems
                        if a == 'elems' else res[a],
                        map(lambda y: hh.get(y, y), h))))
        response.content_type = 'text/csv'
        return output.getvalue()
    else:
        countries = query_meta._countries(db)
        items = list(map(dict, items))

        if params.item:
            params.limit = None
            errors_groups = query._count(
                db,
                params,
                [
                    "markers_counts.item", "markers.source_id",
                    "markers.class", "sources.country", "sources.analyser",
                    "updates_last.timestamp"
                ],
                ["items", "class"],
                [
                    "min(items.menu::text)::jsonb AS menu",
                    "min(class.title::text)::jsonb AS title"
                ],
            )

            total = 0
            for res in errors_groups:
                res["title"] = i10n_select_auto(res["title"], lang)
                res["menu"] = i10n_select_auto(res["menu"], lang)
                if res["count"] != -1:
                    total += res["count"]
        else:
            errors_groups = []
            total = 0

        if gen in ("false-positive", "done"):
            opt_date = "date"
        else:
            opt_date = None

        errors_groups = list(map(dict, errors_groups))
        for res in errors_groups:
            res['timestamp'] = str(res['timestamp'])
        errors = list(map(dict, errors))
        for res in errors:
            res['timestamp'] = str(res['timestamp'])
            if 'date' in res:
                res['date'] = str(res['date'])
        return dict(countries=countries,
                    items=items,
                    errors_groups=errors_groups,
                    total=total,
                    errors=errors,
                    gen=gen,
                    opt_date=opt_date,
                    website=utils.website,
                    main_website=utils.main_website,
                    remote_url_read=utils.remote_url_read)

    return template(tpl,
                    items=items,
                    errors=errors,
                    query=request.query_string,
                    lang=lang[0],
                    gen=gen,
                    title=title,
                    website=utils.website,
                    main_website=utils.main_website,
                    remote_url_read=utils.remote_url_read)