def process_request(self, req): # Makes each Django view have an access to 'zato.odb' and 'zato.setttings_db' attributes # of the request object. The attributes are SQLAlchemy sessions tied databases defined in app's settings.py req.zato = Bunch() req.zato.odb = SASession() req.zato.settings_db = settings_db req.zato.args = Bunch() # Arguments read from URL # Whether this request to web-admin was served over TLS req.zato.is_tls = req.META.get('HTTP_X_FORWARDED_PROTO', '').lower() == 'https' # Whether communication with load-balancer should go over TLS req.zato.lb_use_tls = lb_use_tls req.zato.lb_tls_verify = lb_tls_verify try: resolved_kwargs = resolve(req.path).kwargs req.zato.id = resolved_kwargs.get('id') req.zato.cluster_id = req.GET.get('cluster') or req.POST.get('cluster_id') or \ resolved_kwargs.get('cluster_id') or resolved_kwargs.get('cluster') if req.zato.cluster_id: req.zato.cluster = req.zato.odb.query(Cluster).filter_by( id=req.zato.cluster_id).one() url = 'http{}://{}:{}'.format( 's' if req.zato.lb_use_tls else '', req.zato.cluster.lb_host, req.zato.cluster.lb_port) auth = (ADMIN_INVOKE_NAME, ADMIN_INVOKE_PASSWORD) req.zato.client = Client(req, url, ADMIN_INVOKE_PATH, auth, to_bunch=True) req.zato.clusters = req.zato.odb.query(Cluster).order_by( 'name').all() req.zato.search_form = SearchForm(req.zato.clusters, req.GET) if not req.user.is_anonymous(): try: user_profile = UserProfile.objects.get(user=req.user) except UserProfile.DoesNotExist: user_profile = UserProfile(user=req.user) user_profile.save() req.zato.user_profile = user_profile else: req.zato.user_profile = None except Exception: req.zato.odb.rollback() raise
def process_request(self, req): for dont_require_login in self.dont_require_login: if req.path.startswith(dont_require_login): return None if req.path != self.require_login_path and req.user.is_anonymous(): if req.POST: return login(req) else: return HttpResponseRedirect('{}?next={}'.format( self.require_login_path, req.path)) # Makes each Django view have an access to a 'zato.odb' attribute of the # request object. The attribute is an SQLAlchemy session to the database # defined in app's settings.py req.zato = Bunch() req.zato.odb = SASession() req.zato.args = Bunch() # Arguments read from URL resolved_kwargs = resolve(req.path).kwargs req.zato.id = resolved_kwargs.get('id') req.zato.cluster_id = req.GET.get('cluster') or req.POST.get('cluster_id') or \ resolved_kwargs.get('cluster_id') or resolved_kwargs.get('cluster') if req.zato.cluster_id: req.zato.cluster = req.zato.odb.query(Cluster).filter_by( id=req.zato.cluster_id).one() url = 'http://{}:{}'.format(req.zato.cluster.lb_host, req.zato.cluster.lb_port) auth = (ADMIN_INVOKE_NAME, ADMIN_INVOKE_PASSWORD) req.zato.client = AnyServiceInvoker(url, ADMIN_INVOKE_PATH, auth, to_bunch=True) req.zato.clusters = req.zato.odb.query(Cluster).order_by('name').all() req.zato.choose_cluster_form = ChooseClusterForm( req.zato.clusters, req.GET) if not req.user.is_anonymous(): try: user_profile = UserProfile.objects.get(user=req.user) except UserProfile.DoesNotExist: user_profile = UserProfile(user=req.user) user_profile.save() req.zato.user_profile = user_profile else: req.zato.user_profile = None
def process_request(self, req): # Makes each Django view have an access to a 'zato.odb' attribute of the # request object. The attribute is an SQLAlchemy session to the database # defined in app's settings.py req.zato = Bunch() req.zato.odb = SASession() req.zato.args = Bunch() # Arguments read from URL try: resolved_kwargs = resolve(req.path).kwargs req.zato.id = resolved_kwargs.get('id') req.zato.cluster_id = req.GET.get('cluster') or req.POST.get('cluster_id') or \ resolved_kwargs.get('cluster_id') or resolved_kwargs.get('cluster') if req.zato.cluster_id: req.zato.cluster = req.zato.odb.query(Cluster).filter_by( id=req.zato.cluster_id).one() url = 'http://{}:{}'.format(req.zato.cluster.lb_host, req.zato.cluster.lb_port) auth = (ADMIN_INVOKE_NAME, ADMIN_INVOKE_PASSWORD) req.zato.client = Client(req, url, ADMIN_INVOKE_PATH, auth, to_bunch=True) req.zato.clusters = req.zato.odb.query(Cluster).order_by( 'name').all() req.zato.choose_cluster_form = ChooseClusterForm( req.zato.clusters, req.GET) if not req.user.is_anonymous(): try: user_profile = UserProfile.objects.get(user=req.user) except UserProfile.DoesNotExist: user_profile = UserProfile(user=req.user) user_profile.save() req.zato.user_profile = user_profile else: req.zato.user_profile = None except Exception: req.zato.odb.rollback() raise