Beispiel #1
0
def transfer(request, netid):
    vend_user = get_object_or_404(Member, username=netid)
    vending = vend_user.get_vending()
    user_form = None

    # Prevent transferring to yourself, since that causes nasty concurrence errors
    if netid == request.user.username:
        messages.add_message(request, messages.ERROR,
                             'You can\'t transfer money to yourself.')
        return redirect(reverse('cm_user_view'))

    if request.method == 'POST':
        user_form = VendingForm(request.POST, instance=vending)

        if user_form.is_valid():
            debtor = request.user.get_vending()
            amount = Decimal(user_form['balance'].value())

            if Decimal(amount) <= 0:
                user_form.errors['balance'] = [
                    'Transfer amount must be a number greater than $0.00.'
                ]
            elif debtor.balance < amount:
                user_form.errors['balance'] = [
                    'Transfer amount must not be more than your current balance.'
                ]
            else:
                debtor.balance -= amount

                vending = vend_user.get_vending()  # Get a clean copy
                vending.balance += amount

                debtor.save()
                vending.save()

                return redirect(
                    reverse('cm_user_view', args=[vend_user.username]))
    else:
        user_form = VendingForm(instance=vending)

    user_form.fields['balance'].label = 'Transfer amount'
    return render_to_response('intranet/caffeine_manager/user/edit_user.html',
                              {
                                  'section': 'intranet',
                                  'page': 'caffeine',
                                  'form': user_form,
                                  'is_transfer': True
                              },
                              context_instance=RequestContext(request))
Beispiel #2
0
def transfer(request, netid):
    vend_user=get_object_or_404(Member, username=netid)
    vending=vend_user.get_vending()
    user_form=None;

    # Prevent transferring to yourself, since that causes nasty concurrence errors
    if netid == request.user.username:
        messages.add_message(request, messages.ERROR, 'You can\'t transfer money to yourself.')
        return redirect(reverse('cm_user_view'))

    if request.method == 'POST':
        user_form=VendingForm(request.POST, instance=vending)

        if user_form.is_valid():
            debtor=request.user.get_vending()
            amount=Decimal(user_form['balance'].value())

            if Decimal(amount) <= 0:
                user_form.errors['balance']=['Transfer amount must be a number greater than $0.00.']
            elif debtor.balance < amount:
                user_form.errors['balance']=['Transfer amount must not be more than your current balance.']
            else:
                debtor.balance -= amount

                vending=vend_user.get_vending() # Get a clean copy
                vending.balance += amount

                debtor.save()
                vending.save()

                return redirect(reverse('cm_user_view', args=[vend_user.username]))
    else:
        user_form=VendingForm(instance=vending)

    user_form.fields['balance'].label='Transfer amount'
    return render_to_response(
      'intranet/caffeine_manager/user/edit_user.html',
      {
        'section':'intranet',
        'page':'caffeine',
        'form':user_form,
        'is_transfer':True
      }, context_instance=RequestContext(request))
Beispiel #3
0
def edit(request, netid):
    vend_user=get_object_or_404(Member, username=netid)
    vending=vend_user.get_vending()
    user_form=None;

    if request.method == 'POST':
        user_form=VendingForm(request.POST, instance=vending)
        if user_form.is_valid():
            user_form.save()
            return redirect(reverse('cm_user_view', args=[vend_user.username]))
    else:
        user_form=VendingForm(instance=vending)

    return render_to_response(
      'intranet/caffeine_manager/user/edit_user.html',
      {
        'section':'intranet',
        'page':'caffeine',
        'form':user_form,
        'is_transfer':False
      }, context_instance=RequestContext(request))
Beispiel #4
0
def edit(request, netid):
    vend_user = get_object_or_404(Member, username=netid)
    vending = vend_user.get_vending()
    user_form = None

    if request.method == 'POST':
        user_form = VendingForm(request.POST, instance=vending)
        if user_form.is_valid():
            user_form.save()
            return redirect(reverse('cm_user_view', args=[vend_user.username]))
    else:
        user_form = VendingForm(instance=vending)

    return render_to_response('intranet/caffeine_manager/user/edit_user.html',
                              {
                                  'section': 'intranet',
                                  'page': 'caffeine',
                                  'form': user_form,
                                  'is_transfer': False
                              },
                              context_instance=RequestContext(request))