Пример #1
0
    def get(self, request, conversation):
        # TODO: Ideally we should display a nice message to the user
        #       if they access the page for a conversation that has
        #       already been started.  Currently we just display a 404
        #       page if the token no longer exists because it has
        #       already been used.

        token_manager = DjangoTokenManager(request.user_api.api.token_manager)
        token = request.GET.get('token')
        token_data = token_manager.verify_get(token)

        if not token_data:
            raise Http404

        params = token_data['extra_params']
        action_name = params.get('action_display_name')
        action_details = params.get('action_data').get('display', {})

        return self.render_to_response({
            'success': False,
            'conversation': conversation,
            'action_name': action_name,
            'action_details': action_details,
            'form': ConfirmConversationForm(initial={'token': token}),
        })
Пример #2
0
    def post(self, request, conversation):
        token = request.POST.get('token')
        token_manager = DjangoTokenManager(request.user_api.api.token_manager)
        token_data = token_manager.verify_get(token)
        if not token_data:
            raise Http404

        action_name = token_data['extra_params'].get('action_name')
        action_data = token_data['extra_params'].get('action_data', {})
        action = self.view_def.get_action(action_name)
        action_view = ConversationActionView(
            view_def=self.view_def, action=action)

        user_token, sys_token = token_manager.parse_full_token(token)
        confirmation_form = ConfirmConversationForm(request.POST)
        success = False
        if confirmation_form.is_valid():
            try:
                if token_manager.delete(user_token):
                    return action_view.perform_action(
                        request, conversation, action_data)
                else:
                    messages.warning("Conversation already confirmed!")
            # TODO: Better exception handling
            except ConversationSendError as error:
                messages.error(request, str(error))
        else:
            messages.error('Invalid confirmation form.')

        return self.render_to_response({
            'form': confirmation_form,
            'success': success,
            'conversation': conversation,
        })