def google_analytics_callback_view(request): module = None try: state = request.GET['state'] module = UserDashboardModule.objects.get(pk=state) redirect_uri = request.build_absolute_uri(reverse('google-analytics-callback')) client = GoogleAnalyticsClient(redirect_uri=redirect_uri) client.set_credential_from_request(request) ModuleCredentialStorage(module).put(client.credential) except (FlowExchangeError, ValueError, ServerNotFoundError): messages.error(request, _('API request failed.')) except KeyError: return HttpResponse(_('Bad arguments')) except UserDashboardModule.DoesNotExist: return HttpResponse(_('Module not found')) return redirect(reverse('update_module', kwargs={'pk': module.pk}))
def google_analytics_grant_view(request, pk): redirect_uri = request.build_absolute_uri( reverse('jet-dashboard:google-analytics-callback')) client = GoogleAnalyticsClient(redirect_uri=redirect_uri) return redirect(client.get_oauth_authorize_url(pk))