(event, sms=None)
event can be a MessagingEvent or MessagingSubEvent
event can be a MessagingEvent or MessagingSubEvent
event can be a MessagingEvent or MessagingSubEvent
def get_status_display(event, sms=None):
    """
    event can be a MessagingEvent or MessagingSubEvent
    """
    # If sms without error, short circuit to the sms status display
    if event.status != MessagingEvent.STATUS_ERROR and sms:
        return get_sms_status_display(sms)

    # If survey without error, short circuit to the survey status display
    if (isinstance(event, MessagingSubEvent) and
            event.status == MessagingEvent.STATUS_COMPLETED and
            event.xforms_session_id):
        return _(event.xforms_session.status)

    status = event.status
    error_code = event.error_code

    # If we have a MessagingEvent with no error_code it means there's
    # an error in the subevent
    if status == MessagingEvent.STATUS_ERROR and not error_code:
        error_code = MessagingEvent.ERROR_SUBEVENT_ERROR

    # If we have a MessagingEvent that's completed but it's tied to
    # unfinished surveys, then mark it as being in progress
    if (
        isinstance(event, MessagingEvent) and
        event.status == MessagingEvent.STATUS_COMPLETED and
        MessagingSubEvent.objects.filter(
            parent_id=event.pk,
            content_type=MessagingEvent.CONTENT_SMS_SURVEY,
            # without this line, django does a left join which is not what we want
            xforms_session_id__isnull=False,
            xforms_session__session_is_open=True
        ).count() > 0
    ):
        status = MessagingEvent.STATUS_IN_PROGRESS

    status = dict(MessagingEvent.STATUS_CHOICES).get(status, '-')
    error_message = (MessagingEvent.ERROR_MESSAGES.get(error_code, None)
                     if error_code else None)
    error_message = _(error_message) if error_message else ''
    if event.additional_error_text:
        error_message += ' %s' % event.additional_error_text

    # Sometimes the additional information from touchforms has < or >
    # characters, so we need to escape them for display
    if error_message:
        return '%s - %s' % (_(status), html.escape(error_message))
    else:
        return _(status)
def get_status_display ( event , sms = None ) : # If sms without error, short circuit to the sms status display if event . status != MessagingEvent . STATUS_ERROR and sms : return get_sms_status_display ( sms ) # If survey without error, short circuit to the survey status display if ( isinstance ( event , MessagingSubEvent ) and event . status == MessagingEvent . STATUS_COMPLETED and event . xforms_session_id ) : return _ ( event . xforms_session . status ) status = event . status error_code = event . error_code # If we have a MessagingEvent with no error_code it means there's # an error in the subevent if status == MessagingEvent . STATUS_ERROR and not error_code : error_code = MessagingEvent . ERROR_SUBEVENT_ERROR # If we have a MessagingEvent that's completed but it's tied to # unfinished surveys, then mark it as being in progress if ( isinstance ( event , MessagingEvent ) and event . status == MessagingEvent . STATUS_COMPLETED and MessagingSubEvent . objects . filter ( parent_id = event . pk , content_type = MessagingEvent . CONTENT_SMS_SURVEY , # without this line, django does a left join which is not what we want xforms_session_id__isnull = False , xforms_session__session_is_open = True ) . count ( ) > 0 ) : status = MessagingEvent . STATUS_IN_PROGRESS status = dict ( MessagingEvent . STATUS_CHOICES ) . get ( status , '-' ) error_message = ( MessagingEvent . ERROR_MESSAGES . get ( error_code , None ) if error_code else None ) error_message = _ ( error_message ) if error_message else '' if event . additional_error_text : error_message += ' %s' % event . additional_error_text # Sometimes the additional information from touchforms has < or > # characters, so we need to escape them for display if error_message : return '%s - %s' % ( _ ( status ) , html . escape ( error_message ) ) else : return _ ( status )