Exemplo n.º 1
0
def export_conversation_messages_unsorted(account_key, conversation_key):
    """
    Export the messages from a conversation as they come from the message
    store. Completely unsorted.

    :param str account_key:
        The account holder's account account_key
    :param str conversation_key:
        The key of the conversation we want to export the messages for.
    """
    user_api = VumiUserApi.from_config_sync(
        account_key, settings.VUMI_API_CONFIG)
    user_profile = UserProfile.objects.get(user_account=account_key)
    conversation = user_api.get_wrapped_conversation(conversation_key)

    io = StringIO()
    writer = UnicodeDictWriter(io, conversation_export_field_names)
    writer.writeheader()

    for messages in load_messages_in_chunks(conversation, 'inbound'):
        for message in messages:
            writer.writerow(row_for_inbound_message(message))

    for messages in load_messages_in_chunks(conversation, 'outbound'):
        for message in messages:
            mdb = user_api.api.mdb
            writer.writerow(row_for_outbound_message(message, mdb))

    email_export(user_profile, conversation, io)
Exemplo n.º 2
0
def export_conversation_messages_unsorted(account_key, conversation_key):
    """
    Export the messages from a conversation as they come from the message
    store. Completely unsorted.

    :param str account_key:
        The account holder's account account_key
    :param str conversation_key:
        The key of the conversation we want to export the messages for.
    """
    user_api = VumiUserApi.from_config_sync(account_key,
                                            settings.VUMI_API_CONFIG)
    user_profile = UserProfile.objects.get(user_account=account_key)
    conversation = user_api.get_wrapped_conversation(conversation_key)

    io = StringIO()
    writer = UnicodeDictWriter(io, conversation_export_field_names)
    writer.writeheader()

    for messages in load_messages_in_chunks(conversation, 'inbound'):
        for message in messages:
            writer.writerow(row_for_inbound_message(message))

    for messages in load_messages_in_chunks(conversation, 'outbound'):
        for message in messages:
            mdb = user_api.api.mdb
            writer.writerow(row_for_outbound_message(message, mdb))

    email_export(user_profile, conversation, io)
Exemplo n.º 3
0
 def test_writerow(self):
     io = StringIO()
     writer = UnicodeDictWriter(io, self.headers)
     writer.writeheader()
     writer.writerow({
         self.col1: u'føø',
         self.col2: u'bär',
     })
     reader = csv.reader(StringIO(io.getvalue()))
     reader.next()   # header
     row = reader.next()
     self.assertEqual(
         [u'føø'.encode('utf-8'), u'bär'.encode('utf-8')],
         row)