예제 #1
0
 def _create_connection(self, phone_number, reporter=None):
     if not hasattr(self, 'backend'):
         try:
             self.backend = PersistantBackend.objects.get(
                 slug="MockBackend")
         except PersistantBackend.DoesNotExist:
             self.backend = PersistantBackend(slug="MockBackend")
             self.backend.save()
     pconnection = PersistantConnection(backend=self.backend,
                                        reporter=None,
                                        identity=phone_number)
     pconnection.save()
     return pconnection
예제 #2
0
def __combined_message_log_row(row):
    reporter = None
    connection = None

    # order of fields output by combined_message_log:
    #   [0] direction           [1] message_id      [2] message_date
    #   [3] message_text        [4] reporter_id     [5] reporter_first_name
    #   [6] reporter_last_name  [7] backend_id      [8] backend_title
    #   [9] backend_slug       [10] connection_id  [11] connection_identity

    # if this message is linked to a reporter, create a Reporter object
    # (so we can call the  methods like full_name) without hitting the
    # database each time. note that not all fields were fetched, so the
    # object won't work fully, but enough to display it
    if row[4] is not None:
        reporter = Reporter(first_name=row[5], last_name=row[6], pk=row[4])

    # likewise for a backend+connection, if this message isn't
    # linked to a reporter. combined_message_log can't filter
    # by connections (yet), but they must be displayed
    if row[7] is not None:
        backend = PersistantBackend(title=row[8], slug=row[9], id=row[7])

        connection = PersistantConnection(backend=backend,
                                          identity=row[11],
                                          id=row[10])

    # If the date object is already a datetime, don't bother
    # casting it.  Otherwise do.
    casted_date = row[2]
    if not isinstance(casted_date, datetime):
        casted_date = typecast_timestamp(row[2])
    return {
        "direction": row[0],
        "pk": row[1],
        "date": casted_date,
        "text": row[3],
        "reporter": reporter,
        "connection": connection
    }