Beispiel #1
0
def get_archive(archive_id: str) -> Response:
    """Gets archive page."""
    data: Dict[str, Any] = {}
    response_headers: Dict[str, Any] = {}

    if archive_id == "list":
        return archive_index(archive_id, status=status.HTTP_200_OK)

    archive = ARCHIVES.get(archive_id, None)
    if not archive:
        cat_id = CATEGORIES.get(archive_id, {}).get("in_archive", None)
        archive = ARCHIVES.get(cat_id, None)
        if not archive:
            return archive_index(archive_id,
                                 status=status.HTTP_404_NOT_FOUND)
        else:
            archive_id = cat_id

    _write_expires_header(response_headers)

    subsumed_by = ARCHIVES_SUBSUMED.get(archive_id, None)
    if subsumed_by:
        data["subsumed_id"] = archive_id
        data["subsumed_category"] = CATEGORIES.get(archive_id, {})
        data["subsumed_by"] = subsumed_by
        subsuming_category = CATEGORIES.get(subsumed_by, {})
        data["subsuming_category"] = subsuming_category
        archive_id = subsuming_category.get("in_archive", None)
        archive = ARCHIVES.get(archive_id, None)

    years = years_operating(archive)

    data["years"] = years
    data["months"] = MONTHS
    data["days"] = DAYS
    
    data["archive_id"] = archive_id
    data["archive"] = archive
    data["list_form"] = ByMonthForm(archive_id, archive, years)
    data["stats_by_year"] = stats_by_year(archive_id, archive, years)
    data["category_list"] = category_list(archive_id)

    data["catchup_to"] = datetime.date.today() - datetime.timedelta(days=7)
    
    data["template"] = "archive/single_archive.html"
    return data, status.HTTP_200_OK, response_headers  # type: ignore
Beispiel #2
0
def archive_index(archive_id: str,
                  status: int) -> Tuple[Dict[str, Any], int, Dict[str, Any]]:
    """Landing page for when there is no archive specified."""
    data: Dict[str, Any] = {}
    data["bad_archive"] = archive_id

    archives = [(id, ARCHIVES[id]["name"]) for id in ARCHIVES.keys()
                if id not in ARCHIVES_SUBSUMED and not id.startswith("test")]
    archives.sort(key=lambda tpl: tpl[0])
    data["archives"] = archives

    defunct = [(id, ARCHIVES[id]["name"], ARCHIVES_SUBSUMED.get(id, ""))
               for id in ARCHIVES.keys() if "end_date" in ARCHIVES[id]]
    defunct.sort(key=lambda tpl: tpl[0])
    data["defunct"] = defunct

    data["template"] = "archive/archive_list_all.html"
    return data, status, {}