def test_get_env_db(self): """Test getting the environment database""" db = utils.get_environment_db(self.request) self.assertEqual(self.DEFAULT_ENV, db) # change environment utils.set_environment(self.request, 'qa') db = utils.get_environment_db(self.request) self.assertEqual('qa', db)
def decorator(request, order_id, *args, **kwargs): try: order = Order.objects.using(utils.get_environment_db(request)).get( pk=order_id ) return func(request, order, *args, **kwargs) except Order.DoesNotExist(): return http.HttpResponseNotFound("Order Not Found")
def order_list(request): orders = Order.objects.using(utils.get_environment_db(request)).all() form = OrderForm() if request.method == 'POST': form = OrderForm(data=request.POST) if form.is_valid(): form.save(request=request) messages.success(request, "Successfully added order to {env}".format( env=utils.get_environment_data(request).get('label') )) return http.HttpResponseRedirect(reverse('order_home')) context = dict( form=form, orders=orders ) return request_to_response(request, 'order/index.html', context)