Esempio n. 1
0
 def _transform_classification(cls, clsn: Classification) -> Optional[dict]:
     category = clsn.get('category')
     if category is None:
         return None
     return {'group': clsn.get('group'),
             'archive': clsn.get('archive'),
             'category': category}
Esempio n. 2
0
 def _transform_classification(
         cls, clsn: Classification) -> Optional[Dict[Any, Any]]:
     category = clsn.get("category")
     if category is None:
         return None
     return {
         "group": clsn.get("group"),
         "archive": clsn.get("archive"),
         "category": category,
     }
Esempio n. 3
0
 def _transform_classification(
     clsn: Classification,
 ) -> Optional[Dict[str, Optional[str]]]:
     category = clsn.get("category")
     if category is None:
         return None
     return {  # type:ignore
         "group": clsn.get("group"),
         "archive": clsn.get("archive"),
         "category": category,
     }
Esempio n. 4
0
def display_classification(classification: Classification) -> str:
    """Generate a display-friendly label for a classification."""
    group = classification.get("group")
    category = classification.get("category")
    archive = classification.get("archive")
    parts = []
    if group is not None:
        parts.append(group.get("name",
                               taxonomy.get_group_display(group["id"])))
    if archive is not None:
        parts.append(
            archive.get("name", taxonomy.get_archive_display(archive["id"])))
    if category is not None:
        parts.append(
            category.get("name",
                         taxonomy.get_category_display(category["id"])))
    return "::".join(parts)
Esempio n. 5
0
def category_name(classification: Classification) -> str:
    """Get the category display name for a classification."""
    category = classification.get("category")
    if not category:
        raise ValueError("No category")
    return category.get("name", taxonomy.get_category_display(category["id"]))