Skip to content

Activity tags

hypha.apply.activity.templatetags.activity_tags

register module-attribute

register = Library()

display_author

display_author(activity, user)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def display_author(activity, user):
    if user.is_applicant and (
        activity.user.is_apply_staff
        or activity.user.is_finance
        or activity.user.is_contracting
    ):
        return settings.ORG_LONG_NAME
    if isinstance(activity.related_object, Review) and activity.source.user == user:
        return "Reviewer"
    return activity.user.get_full_name_with_group()
user_can_see_related(activity, user)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def user_can_see_related(activity, user):
    if not activity.related_object:
        return False

    if user.is_apply_staff:
        return True

    if isinstance(activity.related_object, (Determination, Contract)):
        return True

    return False

display_for

display_for(activity, user)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def display_for(activity, user):
    try:
        message_data = json.loads(activity.message)
    except json.JSONDecodeError:
        return activity.message
    else:
        # A message with only numbers (int) is valid json so check we have "real" json.
        if not isinstance(message_data, (dict, list)):
            return activity.message

    visibile_for_user = activity.visibility_for(user)

    if set(visibile_for_user) & {TEAM, REVIEWER}:
        return message_data[TEAM]

    return message_data[ALL]

visibility_options

visibility_options(activity, user)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def visibility_options(activity, user):
    choices = activity.visibility_choices_for(user)
    return json.dumps(choices)

visibility_display

visibility_display(visibility, user)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def visibility_display(visibility, user):
    if not user.is_apply_staff and not user.is_finance and not user.is_contracting:
        return f"{visibility} + {settings.ORG_SHORT_NAME} team"
    if visibility != TEAM:
        return f"{visibility} + team"
    return visibility

source_type

source_type(value)
Source code in hypha/apply/activity/templatetags/activity_tags.py
@register.filter
def source_type(value):
    if value and "submission" in value:
        return "Submission"
    return str(value).capitalize()