utils.py 642 B

1234567891011121314151617181920
  1. import logging
  2. from django.conf import settings
  3. logger = logging.getLogger(__name__)
  4. def get_title_from_labels(labels: list[str], user_context_labels: list[str] = []) -> str:
  5. title = "Unknown"
  6. task_context_labels: list = user_context_labels or settings.DEFAULT_TASK_CONTEXT_TAG_LIST
  7. for label in labels:
  8. # TODO We may also want to take a user list of labels instead
  9. if label in task_context_labels:
  10. title = label.capitalize()
  11. if title == "Unknown":
  12. logger.warning(
  13. "Missing a prefix and suffix tag for task",
  14. extra={"labels": labels},
  15. )
  16. return title