Esempio n. 1
0
def new_router(request):
    if request.method == 'POST':
        form = NewRouterForm(request.user_api, request.POST)
        if form.is_valid():
            router_type = form.cleaned_data['router_type']

            view_def = get_router_view_definition(router_type)
            router = request.user_api.new_router(
                router_type, name=form.cleaned_data['name'],
                description=form.cleaned_data['description'], config={},
                extra_inbound_endpoints=list(
                    view_def.extra_static_inbound_endpoints),
                extra_outbound_endpoints=list(
                    view_def.extra_static_outbound_endpoints),
            )
            messages.info(request, 'Conversation created successfully.')

            # Get a new view_def with a conversation object in it.
            view_def = get_router_view_definition(
                router.router_type, router)

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

            return redirect(view_def.get_view_url(
                next_view, router_key=router.key))
    else:
        form = NewRouterForm(request.user_api)
    return render(request, 'router/new.html', {
        'router_form': form,
    })
Esempio n. 2
0
    def setup_routers(self, user, routers):
        user_api = vumi_api_for_user(user)
        for router_info in routers:
            router_info = router_info.copy()  # So we can modify it.
            self.router_info.append({
                'account': user.email,
                'key': router_info['key'],
                'start': router_info.pop('start', True),
            })
            router_key = router_info.pop('key')
            if user_api.get_router(router_key):
                self.stderr.write(
                    'Router %s already exists. Skipping.\n' % (
                        router_key,))
                continue

            router_type = router_info.pop('router_type')
            view_def = get_router_view_definition(router_type)
            config = router_info.pop('config', {})
            extra_inbound_endpoints = view_def.get_inbound_endpoints(config)
            extra_outbound_endpoints = view_def.get_outbound_endpoints(config)
            batch_id = user_api.api.mdb.batch_start()

            # We bypass the usual mechanisms so we can set the key ourselves.
            router = user_api.router_store.routers(
                router_key, user_account=user_api.user_account_key,
                router_type=router_type, name=router_info.pop('name'),
                config=config, extra_inbound_endpoints=extra_inbound_endpoints,
                extra_outbound_endpoints=extra_outbound_endpoints,
                batch=batch_id, **router_info)
            router.save()
            self.stdout.write('Router %s created\n' % (router.key,))
Esempio n. 3
0
 def test_get_router_view_definition_obsolete_router_type(self):
     self.monkey_patch(
         go.base.utils, 'obsolete_router_types',
         lambda: set(['old_router']))
     view_def = get_router_view_definition('old_router')
     self.assertEqual(view_def._router_def.router_type, 'old_router')
Esempio n. 4
0
 def test_get_router_view_definition_with_router(self):
     dummy_router = object()
     view_def = get_router_view_definition('keyword', dummy_router)
     self.assertTrue(view_def._router_def.router is dummy_router)
Esempio n. 5
0
 def test_get_router_view_definition(self):
     view_def = get_router_view_definition('keyword')
     from go.routers.keyword.view_definition import (
         RouterViewDefinition,)
     self.assertTrue(isinstance(view_def, RouterViewDefinition))
Esempio n. 6
0
 def get_view_url(self, view, router_key):
     view_def = get_router_view_definition("keyword", None)
     return view_def.get_view_url(view, router_key=router_key)
Esempio n. 7
0
def router_screen(router, view_name='show'):
    view_def = get_router_view_definition(router.router_type, router)
    return view_def.get_view_url(view_name, router_key=router.key)
Esempio n. 8
0
 def get_view_url(self, view, router_key):
     view_def = get_router_view_definition('keyword', None)
     return view_def.get_view_url(view, router_key=router_key)
Esempio n. 9
0
 def get_view_url(self, view):
     view_def = base_utils.get_router_view_definition(
         self.router_type)
     return view_def.get_view_url(
         view, router_key=self.router_key)
Esempio n. 10
0
def router(request, router_key, path_suffix):
    router = router_or_404(request.user_api, router_key)
    view_def = get_router_view_definition(router.router_type, router)
    view = view_def.get_view(path_suffix)
    return view(request, router)