def get_subhandler_classes(): subhandler_classes = {} for conversation_type in configured_conversation_types().keys(): conv_def = get_conversation_definition(conversation_type) if conv_def is None or conv_def.api_dispatcher_cls is None: continue subhandler_classes[conversation_type] = conv_def.api_dispatcher_cls return subhandler_classes
def get_subhandler_classes(): subhandler_classes = {} for conversation_type in configured_conversation_types().keys(): conv_def = get_conversation_definition(conversation_type) if conv_def is None or conv_def.api_dispatcher_cls is None: continue subhandler_classes[conversation_type] = ( conv_def.api_dispatcher_cls) return subhandler_classes
def send_user_account_summary(user): user_api = vumi_api_for_user(user) contact_store = user_api.contact_store conv_store = user_api.conversation_store contact_keys = contact_store.list_contacts() uniques = get_uniques(contact_store, contact_keys=contact_keys, plucker=attrgetter('msisdn')) conversation_keys = conv_store.list_conversations() all_conversations = [] bunches = conv_store.conversations.load_all_bunches(conversation_keys) for bunch in bunches: all_conversations.extend([user_api.wrap_conversation(conv) for conv in bunch]) all_conversations.sort(key=(lambda conv: conv.created_at), reverse=True) active_conversations = {} known_types = configured_conversation_types() for conv in all_conversations: conv_list = active_conversations.setdefault( known_types.get(conv.conversation_type, 'Unknown'), []) if conv.get_status() == CONVERSATION_RUNNING: conv_list.append(conv) message_count = get_messages_count(all_conversations) message_count_friendly = dict((known_types.get(conv_type), value) for conv_type, value in message_count.items()) total_messages_sent = sum(conv_type['sent'] for conv_type in message_count.values()) total_messages_received = sum(conv_type['received'] for conv_type in message_count.values()) total_message_count = total_messages_received + total_messages_sent send_mail('Vumi Go Account Summary', render_to_string( 'account/account_summary_mail.txt', { 'all_conversations': all_conversations, 'user': user, 'unique_identifier': 'contact number', 'total_uniques': len(uniques), 'total_contacts': len(contact_keys), 'total_messages_received': total_messages_received, 'total_messages_sent': total_messages_sent, 'total_message_count': total_message_count, 'message_count': message_count, 'message_count_friendly': message_count_friendly, 'active_conversations': active_conversations, }), settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)
def handle_command_import(self, *apps, **options): raw_conv_data = json.load(self.load_file(options)) allowed_keys = [ 'conversation_type', 'description', 'name', 'config', ] new_conv_data = dict([(key, raw_conv_data[key]) for key in allowed_keys]) conversation_type = new_conv_data['conversation_type'] if conversation_type not in config.configured_conversation_types(): raise CommandError('Invalid conversation_type: %s' % ( conversation_type,)) conversation = self.user_api.new_conversation(**new_conv_data) self.stdout.write(json.dumps(conversation.get_data()))
def handle_command_import(self, *apps, **options): raw_conv_data = json.load(self.load_file(options)) allowed_keys = [ 'conversation_type', 'description', 'name', 'config', ] new_conv_data = dict([(key, raw_conv_data[key]) for key in allowed_keys]) conversation_type = new_conv_data['conversation_type'] if conversation_type not in config.configured_conversation_types(): raise CommandError('Invalid conversation_type: %s' % (conversation_type, )) conversation = self.user_api.new_conversation(**new_conv_data) self.stdout.write(json.dumps(conversation.get_data()))
def test_configured_conversation_types(self): conv_types = configured_conversation_types() self.assertEqual(conv_types['bulk_message'], 'Group Message')
def test_configured_conversation_types(self): conv_types = configured_conversation_types() self.assertEqual(conv_types['bulk_message'], 'Group Message')