예제 #1
0
파일: views.py 프로젝트: TouK/vumi-go
def new_conversation(request):
    if request.method == 'POST':
        form = NewConversationForm(request.user_api, request.POST)
        if form.is_valid():
            conversation_type = form.cleaned_data['conversation_type']

            view_def = get_conversation_view_definition(conversation_type)
            conv = request.user_api.new_conversation(
                conversation_type, name=form.cleaned_data['name'],
                description=form.cleaned_data['description'], config={},
                extra_endpoints=list(view_def.extra_static_endpoints),
            )
            messages.info(request, 'Conversation created successfully.')

            # Get a new view_def with a conversation object in it.
            view_def = get_conversation_view_definition(
                conv.conversation_type, conv)

            next_view = 'show'
            if view_def.is_editable:
                next_view = 'edit'

            return redirect(view_def.get_view_url(
                next_view, conversation_key=conv.key))
    else:
        form = NewConversationForm(request.user_api)
    return render(request, 'conversation/new.html', {
        'conversation_form': form,
    })
예제 #2
0
def new_conversation(request):
    if request.method == 'POST':
        form = NewConversationForm(request.user_api, request.POST)
        if form.is_valid():
            conversation_type = form.cleaned_data['conversation_type']

            view_def = get_conversation_view_definition(conversation_type)
            conv = request.user_api.new_conversation(
                conversation_type,
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                config={},
                extra_endpoints=list(view_def.extra_static_endpoints),
            )
            messages.info(request, 'Conversation created successfully.')

            # Get a new view_def with a conversation object in it.
            view_def = get_conversation_view_definition(
                conv.conversation_type, conv)

            next_view = 'show'
            if view_def.is_editable:
                next_view = 'edit'

            return redirect(
                view_def.get_view_url(next_view, conversation_key=conv.key))
    else:
        form = NewConversationForm(request.user_api)
    return render(request, 'conversation/new.html', {
        'conversation_form': form,
    })
예제 #3
0
    def setup_conversations(self, user, conversations):
        user_api = vumi_api_for_user(user)
        for conv_info in conversations:
            conv_info = conv_info.copy()  # So we can modify it.
            self.conversation_info.append({
                'account': user.email,
                'key': conv_info['key'],
                'start': conv_info.pop('start', True),  # Don't pass to conv.
            })
            conversation_key = conv_info.pop('key')
            if user_api.get_wrapped_conversation(conversation_key):
                self.stderr.write(
                    'Conversation %s already exists. Skipping.\n' % (
                        conversation_key,))
                continue

            conversation_type = conv_info.pop('conversation_type')
            view_def = get_conversation_view_definition(conversation_type)
            config = conv_info.pop('config', {})
            batch_id = user_api.api.mdb.batch_start()
            # We bypass the usual mechanisms so we can set the key ourselves.
            conv = user_api.conversation_store.conversations(
                conversation_key, user_account=user_api.user_account_key,
                conversation_type=conversation_type,
                name=conv_info.pop('name'), config=config, batch=batch_id,
                extra_endpoints=view_def.get_endpoints(config), **conv_info)
            conv.save()
            self.stdout.write('Conversation %s created\n' % (conv.key,))
예제 #4
0
def conversation_screen(conv, view_name='show'):
    # FIXME: Unhack this when all apps have definition modules.
    try:
        view_def = get_conversation_view_definition(
            conv.conversation_type, conv)
    except AttributeError:
        return '/conversations/%s/' % (conv.key,)
    return view_def.get_view_url(view_name, conversation_key=conv.key)
예제 #5
0
def conversation_screen(conv, view_name='show'):
    # FIXME: Unhack this when all apps have definition modules.
    try:
        view_def = get_conversation_view_definition(conv.conversation_type,
                                                    conv)
    except AttributeError:
        return '/conversations/%s/' % (conv.key, )
    return view_def.get_view_url(view_name, conversation_key=conv.key)
예제 #6
0
파일: views.py 프로젝트: TouK/vumi-go
    def _create_conversation(self, request, conv_data):
        conversation_type = conv_data['conversation_type']

        view_def = get_conversation_view_definition(conversation_type)
        conversation = request.user_api.new_conversation(
            conversation_type, name=conv_data['name'],
            description=conv_data['description'], config={},
            extra_endpoints=list(view_def.extra_static_endpoints),
        )
        return view_def, conversation
예제 #7
0
    def _create_conversation(self, request, conv_data):
        conversation_type = conv_data['conversation_type']

        view_def = get_conversation_view_definition(conversation_type)
        conversation = request.user_api.new_conversation(
            conversation_type,
            name=conv_data['name'],
            description=conv_data['description'],
            config={},
            extra_endpoints=list(view_def.extra_static_endpoints),
        )
        return view_def, conversation
예제 #8
0
    def test_jsbox_report_layout_building_for_no_report_config(self):
        conv_helper = self.setup_conversation()
        conversation = conv_helper.get_conversation()

        view_def = get_conversation_view_definition(
            conversation.conversation_type)
        default_reports_view = ConversationReportsView(view_def=view_def)
        default_layout = default_reports_view.build_layout(conversation)

        view = JSBoxReportsView(view_def=view_def)
        layout = view.build_layout(conversation)

        self.assertEqual(layout.get_config(), default_layout.get_config())
예제 #9
0
    def test_jsbox_report_layout_building_for_no_report_config(self):
        conv_helper = self.setup_conversation()
        conversation = conv_helper.get_conversation()

        view_def = get_conversation_view_definition(
            conversation.conversation_type)
        default_reports_view = ConversationReportsView(view_def=view_def)
        default_layout = default_reports_view.build_layout(conversation)

        view = JSBoxReportsView(view_def=view_def)
        layout = view.build_layout(conversation)

        self.assertEqual(layout.get_config(), default_layout.get_config())
예제 #10
0
파일: views.py 프로젝트: TouK/vumi-go
def conversation_action(request, conversation_key, action_name):
    conv = conversation_or_404(request.user_api, conversation_key)
    view_def = get_conversation_view_definition(
        conv.conversation_type, conv)
    view = view_def.get_action_view(action_name)
    return view(request, conv)
예제 #11
0
파일: views.py 프로젝트: TouK/vumi-go
def conversation(request, conversation_key, path_suffix):
    conv = conversation_or_404(request.user_api, conversation_key)
    view_def = get_conversation_view_definition(
        conv.conversation_type, conv)
    view = view_def.get_view(path_suffix)
    return view(request, conv)
예제 #12
0
 def get_view_url(self, view):
     view_def = base_utils.get_conversation_view_definition(
         self.conversation_type)
     return view_def.get_view_url(
         view, conversation_key=self.conversation_key)
예제 #13
0
 def test_get_conversation_view_definition_obsolete_conv_type(self):
     self.monkey_patch(
         go.base.utils, 'obsolete_conversation_types',
         lambda: set(['old_conv']))
     view_def = get_conversation_view_definition('old_conv')
     self.assertEqual(view_def._conv_def.conversation_type, 'old_conv')
예제 #14
0
def conversation_action(request, conversation_key, action_name):
    conv = conversation_or_404(request.user_api, conversation_key)
    view_def = get_conversation_view_definition(conv.conversation_type, conv)
    view = view_def.get_action_view(action_name)
    return view(request, conv)
예제 #15
0
def conversation(request, conversation_key, path_suffix):
    conv = conversation_or_404(request.user_api, conversation_key)
    view_def = get_conversation_view_definition(conv.conversation_type, conv)
    view = view_def.get_view(path_suffix)
    return view(request, conv)
예제 #16
0
 def test_get_conversation_view_definition(self):
     view_def = get_conversation_view_definition('bulk_message')
     from go.apps.bulk_message.view_definition import (
         ConversationViewDefinition,)
     self.assertTrue(isinstance(view_def, ConversationViewDefinition))
예제 #17
0
 def test_get_conversation_view_definition_with_conv(self):
     dummy_conv = object()
     view_def = get_conversation_view_definition('bulk_message', dummy_conv)
     self.assertTrue(view_def._conv_def.conv is dummy_conv)
예제 #18
0
파일: test_base.py 프로젝트: TouK/vumi-go
 def test_get_conversation_view_definition(self):
     view_def = utils.get_conversation_view_definition('bulk_message', None)
     conv_def = view_def._conv_def
     self.assertTrue(isinstance(view_def, ConversationViewDefinitionBase))
     self.assertTrue(isinstance(conv_def, ConversationDefinitionBase))
     self.assertEqual('bulk_message', conv_def.conversation_type)
예제 #19
0
 def test_get_conversation_view_definition(self):
     view_def = utils.get_conversation_view_definition('bulk_message', None)
     conv_def = view_def._conv_def
     self.assertTrue(isinstance(view_def, ConversationViewDefinitionBase))
     self.assertTrue(isinstance(conv_def, ConversationDefinitionBase))
     self.assertEqual('bulk_message', conv_def.conversation_type)
예제 #20
0
 def get_view_url(self, view):
     view_def = base_utils.get_conversation_view_definition(
         self.conversation_type)
     return view_def.get_view_url(view,
                                  conversation_key=self.conversation_key)