Esempio n. 1
0
def money_manage(request):
  if request.method == 'POST':
    form = MoneyForm(request.POST)
    if form.is_valid():
      form_data = form.cleaned_data
      people = []
      for p in form_data['people']:
        people.append(get_object_or_404(Person, id=p))
      
      action = form_data['action']
      money = form_data['money']
      if action == 'add':
        change_money(people, money, "充值")
      elif action == 'sub':
        change_money(people, money * -1, "扣除")
      elif action == 'addall':
        change_money(people, money / len(people), "返奖")
      elif action == 'suball':
        change_money(people, money / len(people) * -1, "购买")
      else:
        raise Http404
      return HttpResponseRedirect('../success/')
  else:
    form = MoneyForm()
  return render(request, 'weblog/money_manage.html', 
                {'form': form,
                })
Esempio n. 2
0
def money_add(request):
        if request.method == 'POST':
                form = MoneyForm(request.POST)
                if form.is_valid():
                        form.save()
                        year = localtime(timezone.now()).year
                        month =  localtime(timezone.now()).month
                        try:
                                themonth = Month.objects.get(date=year*100+month)
                        except ObjectDoesNotExist:
                                themonth = Month(date=year*100+month)
                                themonth.save()
                        return redirect("/money/"+str(themonth.date))
        else:
                form = MoneyForm()
        return render_to_response('form.html',{'form': form}, context_instance=RequestContext(request))
Esempio n. 3
0
def get(request, money_id = None):
    if money_id:
        money = get_object_or_404(Money, id=money_id)
        html = 'edit.html'
    else:
        money = None
        html = 'add.html'
        
    if request.POST:
        form = MoneyForm(request.POST, instance=money)
        if form.is_valid():
            form.save()
            if money_id:
                values = {'title': 'Success: Delete', 'text': 'Opening number '+ money_id + ' deleted', 'image': '/media/img/backend/Symbol-delete.png'}
                return JsonResponse(values)
            else:
                return HttpResponseRedirect('/backend/coins/')
    else:
        form = MoneyForm(instance=money)
        if money_id:
            return Headers(render_to_response(templates+html, {'form': form, 'id': money_id}))
        else:
            return Headers(render_to_response(templates+html, {'form': form}))