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 addaccount(request): #check if another operator and student has this name uname = request.POST.get('student_id') if getoperator(uname) or getstudent(uname): return 'The id already exists' password = validation.hash(uname) email = request.POST.get('email') firstname = request.POST.get('fname') lastname = request.POST.get('lname') operator = getoperator(request.session['data_ioests'].get('name')) if not operator: return "Operator doesn't exist. Please Log in first " details = request.POST.get('details','new account created') #validate these credentials error = validation.usernamevalid(uname) if error != 'True': return error error = validation.emailvalid(email) if error != 'True': return error error = validation.namevalid(firstname) if error != 'True': return error error = validation.namevalid(lastname) if error != 'True': return error s = Student(student_id=uname,firstname=firstname,lastname=lastname,password=password,balance=100.,emailid=email,lastlogin=datetime.now()) s.save() activ = Activity(student=s,atype='newaccount',operator=operator,details=details,amount=100.) activ.save() return True
def payment(request): sid = request.POST.get('student_id') password = request.POST.get('password') opname = request.session['data_ioests'].get('name') student = getstudentp(sid,password) operator = getoperator(opname) details = request.POST.get('details') if not(student and operator): return "Student or Operator doesn't exist" amount = request.POST.get('amount') if not amount: 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 pay more than Rs 1000 at a time" if amount > student.balance: return "Insufficient funds" data_ioests = request.session['data_ioests'] data_ioests['balance_before']=student.balance request.session['data_ioests']=data_ioests student.balance -= amount activ = Activity(student=student,atype='payment',operator=operator,details=details,amount=amount) activ.save() student.save() #TODO: create activity return True