Exemplo n.º 1
0
def _update_query_with_classification(q: AdvancedQuery, data: MultiDict) \
        -> AdvancedQuery:
    q.classification = ClassificationList()
    archives = [('computer_science', 'cs'), ('economics', 'econ'),
                ('eess', 'eess'), ('mathematics', 'math'),
                ('q_biology', 'q-bio'), ('q_finance', 'q-fin'),
                ('statistics', 'stat')]
    for field, archive in archives:
        if data.get(field):
            # Fix for these typing issues is coming soon!
            #  See: https://github.com/python/mypy/pull/4397
            q.classification.append(
                Classification(archive={'id': archive})  # type: ignore
            )
    if data.get('physics') and 'physics_archives' in data:
        if 'all' in data['physics_archives']:
            q.classification.append(
                Classification(group={'id': 'grp_physics'})  # type: ignore
            )
        else:
            q.classification.append(
                Classification(  # type: ignore
                    group={'id': 'grp_physics'},
                    archive={'id': data['physics_archives']}))
    return q
Exemplo n.º 2
0
def _update_query_with_classification(q: AdvancedQuery,
                                      data: MultiDict) -> AdvancedQuery:
    q.classification = ClassificationList()
    archives = [
        ("computer_science", "cs"),
        ("economics", "econ"),
        ("eess", "eess"),
        ("mathematics", "math"),
        ("q_biology", "q-bio"),
        ("q_finance", "q-fin"),
        ("statistics", "stat"),
    ]
    for field, archive in archives:
        if data.get(field):
            # Fix for these typing issues is coming soon!
            #  See: https://github.com/python/mypy/pull/4397
            q.classification.append(
                Classification(archive={"id": archive})  # type: ignore
            )
    if data.get("physics") and "physics_archives" in data:
        if "all" in data["physics_archives"]:
            q.classification.append(
                Classification(group={"id": "grp_physics"})  # type: ignore
            )
        else:
            q.classification.append(
                Classification(  # type: ignore
                    group={"id": "grp_physics"},
                    archive={"id": data["physics_archives"]},
                ))
    return q