示例#1
0
 def test_get_env_data(self):
     """Test getting the environment information"""
     env_data = utils.get_environment_data(self.request)
     self.assertEqual(
         settings.ENVIRONMENTS.get(self.DEFAULT_ENV),
         env_data
     )
示例#2
0
def order_delete(request, order):
    order.delete()
    messages.success(request, "Successfully deleted order in {env}".format(
        env=utils.get_environment_data(request).get('label')
    ))
    return http.HttpResponseRedirect(reverse('order_home'))
    
    
示例#3
0
def request_to_response(request, template, context={}):
    # ensure we have the environment var set
    context.update(environment=utils.get_environment_data(request))
    context.update(environments=settings.ENVIRONMENTS)
    return render_to_response(
        template,
        context,
        context_instance=RequestContext(request)
    )
示例#4
0
def order_edit(request, order):
    form = OrderForm(instance=order)
    if request.method == 'POST':
        form = OrderForm(instance=order, data=request.POST)
        if form.is_valid():
            form.save(request=request)
            messages.success(request, "Successfully updated order in {env}".format(
                env=utils.get_environment_data(request).get('label')
            ))
            return http.HttpResponseRedirect(reverse('order_home'))
    context = dict(
        form=form,
    )
    return request_to_response(request, 'order/edit.html', context)
示例#5
0
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)