def deposit(request): sid = request.POST.get('student_id') password = request.POST.get('password') oppassword = request.POST.get('operatorpassword') student = getstudentp(sid,password) operator = getoperatorp(request.session['data_ioests'].get('name'),oppassword) details = request.POST.get('details','amount deposited') if not (student and operator): return "Student or Operator doesn't exist" amount = request.POST.get('amount') if amount == None: return "Amount field can't be empty" try: amount = float(amount) except: return "Invalid Balance. Must be a float number" if amount >1000: return "Can't deposit more than Rs 1000 at a time" student.balance += amount student.save() activ = Activity(student=student,atype='deposit',operator=operator,details=details,amount=amount) activ.save() student.save() #TODO: create activity return True
def index(request): #list_by_credit = Student.objects.all().order_by('credit') #return render_to_response('ioestu/index.html', {'list_by_credit': list_by_credit}) state = "Please log in below..." username = password = '' if request.method == 'POST': state = "invalid user id or password" username = request.POST.get('username') password = request.POST.get('password') if getoperatorp(username,password): request.session['data_ioests']={'type':'operator','name':username,'balance_before':'null','action':'payment'} return HttpResponseRedirect('/logged/') elif getstudentp(username, password): request.session['data_ioests']={'type':'student','name':username,'balance_before':'null','action':'payment'} return HttpResponseRedirect('/logged/') else: student = None operator = None return render(request,'ioestu/index.html',{'state':state, 'username': username})