示例#1
0
文件: views.py 项目: gmuresan/repunch
def add_code(request, id):
    retailer = Retailer.objects.get(pk=id)
    code = Code()
    code.used = False
    code.retailer_id = id

    code.code = hash(str(retailer.name)+str(datetime.now()))
    while int(code.code) < 0:
        code.code = hash(str(retailer.name) + str(datetime.now()))

    code.save()

    return HttpResponseRedirect('/edit/'+id)
示例#2
0
文件: views.py 项目: gmuresan/repunch
def generate_code(request):
    if request.method == 'POST':
        response = dict()
        retailer_id = request.POST['retailer_id']
        retailer_password = request.POST['password']
        employee_id = request.POST['employee_id']

        try:
            retailer_account = RetailerAccount.objects.get(retailerId=retailer_id)
            if retailer_account.user.check_password(retailer_password):
                retailer = retailer_account.retailer
                employee = Employee.objects.get(employeeId=employee_id, retailer=retailer)

                code = Code()
                code.used = False
                code.retailer = retailer

                code.code = hash(str(retailer.name)+str(datetime.datetime.now()))
                while int(code.code) < 0:
                    code.code = hash(str(retailer.name) + str(datetime.datetime.now()))

                code.save()

                log = Log()
                log.employee = employee
                log.code = code
                log.date = datetime.datetime.now()
                log.action = 'generated'

                response['success'] = True
                response['code'] = code.code
                return HttpResponse(simplejson.dumps(response), mimetype='application/json')
            else:
                response['success'] = False
                response['error'] = 'Incorrect Password'

        except Employee.DoesNotExist:
            response['success'] = False
            response['error'] = 'Employee ID is incorrect'
        except RetailerAccount.DoesNotExist:
            response['success'] = False
            response['error'] = 'Retailer ID is incorrect'

        return HttpResponse(simplejson.dumps(response), mimetype='application/json')