def balance(request): """ View card balans and store this operation in db""" card = request.user date = datetime.utcnow() operation = Operation(card=card, date=date, operation='0') operation.save() content = {'date': date.date, 'balance': card.balance, 'card': split_number(card.card_number)} return render(request, 'balance.html', content)
def do_update(request): if request.method == "POST": ips = request.POST["ips"] op = Operation(o_ips=ips) op.save() op_id = op ip_list = ips.split(";") for ip in ip_list: ip = ip.strip() if ip: per_ip(ip, op_id) resp = "success" else: resp = "GET not allowed" return HttpResponse(resp)
def transfer(userSource, userTarget, title, amount, admin): try: userSource_acc = Account.objects.filter(owner=userSource) if not userSource_acc: raise Exception(u"Nieznany użytkownik") userSource_acc = userSource_acc[0] userTarget_acc = Account.objects.filter(owner=userTarget) if not userTarget_acc: raise Exception(u"Nieznany użytkownik") userTarget_acc = userTarget_acc[0] if userSource == userTarget and admin != 1: raise Exception(u"Nie można przelewać na swoje konto!") if amount < 0 and admin != 1: raise Exception(u"Ujemna kwota przelewu!") if amount == 0: raise Exception("Kwota musi być różna od 0") if userSource_acc.balance < amount and admin != 1: raise Exception(u"Brak środków!") transfer_obj = Operation() transfer_obj.SourceAccount = userSource_acc transfer_obj.TargetAccount = userTarget_acc transfer_obj.title = title transfer_obj.amount = amount transfer_obj.save() userTarget_acc.balance += amount userTarget_acc.save() if admin != 1: userSource_acc = Account.objects.filter(owner=userSource)[0] userSource_acc.balance -= amount userSource_acc.save() return 'Ok' except Exception,e: return e
def withdrawal(request): """ View withdrawal process, """ if request.POST: date = datetime.utcnow() card = request.user amount = int(request.POST.get('amount')) if card.balance < amount: return render(request, 'error_page.html', {}) operation = Operation(card=card, date=date, operation='1', amount=amount) operation.save() card.balance -= amount card.save() content = {'date': date.date, 'balance': card.balance, 'card': split_number(card.card_number), 'amount': amount} return render(request, 'report.html', content) return render(request, 'withdrawal.html', {})
def transfer(userSource, userTarget, title, amount, admin): try: userSource_acc = Account.objects.filter(owner=userSource) if not userSource_acc: raise Exception(u"Nieznany użytkownik") userSource_acc = userSource_acc[0] userTarget_acc = Account.objects.filter(owner=userTarget) if not userTarget_acc: raise Exception(u"Nieznany użytkownik") userTarget_acc = userTarget_acc[0] if userSource == userTarget and admin != 1: raise Exception(u"Nie można przelewać na swoje konto!") if amount < 0 and admin != 1: raise Exception(u"Ujemna kwota przelewu!") if amount == 0: raise Exception("Kwota musi być różna od 0") if userSource_acc.balance < amount and admin != 1: raise Exception(u"Brak środków!") transfer_obj = Operation() transfer_obj.SourceAccount = userSource_acc transfer_obj.TargetAccount = userTarget_acc transfer_obj.title = title transfer_obj.amount = amount transfer_obj.save() userTarget_acc.balance += amount userTarget_acc.save() if admin != 1: userSource_acc = Account.objects.filter(owner=userSource)[0] userSource_acc.balance -= amount userSource_acc.save() return 'Ok' except Exception, e: return e
def init_db(): # --- Inserting a user --- test = User(username='******', email='*****@*****.**', password='******') test.save() # --- Inserting some operation-types --- tokenization = OperationType(nameOp='Tokenization') tokenization.save() stopWords = OperationType(nameOp='Stop words') stopWords.save() lemmatization = OperationType(nameOp='Lemmatization') lemmatization.save() stemming = OperationType(nameOp='Stemming') stemming.save() posTagging = OperationType(nameOp='Pos Tagging') posTagging.save() bagOfWords = OperationType(nameOp='Bag of words') bagOfWords.save() TfIdf = OperationType(nameOp='TF-IDF') TfIdf.save() word2Vec = OperationType(nameOp='Word2Vec') word2Vec.save() # --- Inserting an operation --- stopWordOp1 = Operation( text= "منذ انعقاد المجلس الوطني الأخير لحزب العدالة والتنمية لا حديث بين الأعضاء إلا عن أساليب التهديد والوعيد التي بات يرفعها بعض أعضاء الأمانة العامة في وجه المخالفين للقيادة الحالية.", textType="input", result= "['انعقاد', 'المجلس', 'الوطني', 'الأخير', 'لحزب', 'العدالة', 'والتنمية', 'حديث', 'الأعضاء', 'أساليب', 'التهديد', 'والوعيد', 'بات', 'يرفعها', 'أعضاء', 'الأمانة', 'العامة', 'وجه', 'المخالفين', 'للقيادة', 'الحالية', '.']", dateCr="2012-10-15T21:26:17Z", user=test, operation_type=stopWords) stopWordOp1.save() tokenOp1 = Operation( text="منذ انعقاد المجلس الوطني الأخير لحزب العدالة والتنمية", textType="input", result= "[ 'منذ', 'انعقاد', 'المجلس', 'الوطني', 'الأخير', 'لحزب', 'العدالة', 'والتنمية' ]", dateCr="2012-10-15T21:26:17Z", user=test, operation_type=tokenization) tokenOp1.save() # --- Inserting some datas --- data1 = Data(url="lakom", title="tttttttttt", content="test", language="arabic", datePost="now", score=4, classe=1) data1.save() data2 = Data(url="lakom", title="tttttttttt", content="test", language="arabic", datePost="now", score=4, classe=1) data2.save() # --- Main function --- # if(__name__=='__main__'): # init_db()