def create_one_license(selling_shop,data_transfer_plan,prefix): # read current index bulk_license_manager = BulkLicenseManagement.objects.all()[0] current_index = bulk_license_manager.current_index # set up username and password username = prefix + str(current_index) password = generate_md5_hash(selling_shop.username + str(current_index)) password = password[: ( len(password)/2 ) ] new_user = User(username=username, password=password) current_index2 = BulkLicenseManagement.objects.all()[0].current_index if current_index != current_index2: raise DatabaseError() else: new_user = User.objects.create_user(username=username, password=password) # create a userprofile for the new customer new_user_profile = UserProfile() new_user_profile.user = new_user new_user_profile.is_shop = False new_user_profile.email_subscription = False new_user_profile.save() # create CustomerProfile new_customer_profile = CustomerProfile() new_customer_profile.user_profile = new_user_profile new_customer_profile.save() #create purchase object new_purchase = Purchase() new_purchase.user = new_user new_purchase.data_transfer_plan = data_transfer_plan new_purchase.remaining_allowance_frequency = data_transfer_plan.freq new_purchase.selling_shop = selling_shop # purchase.shop_debited = false is by default. new_purchase.save() new_purchase.follow_up_number = generate_md5_hash(str(new_purchase.id)) new_purchase.save() #increase the current index current_index = current_index + 1 bulk_license_manager.current_index = current_index bulk_license_manager.save() return (username,password)
def coupon_created(sender, instance, created, **kwargs): if created: print (instance.id) hashcode = generate_md5_hash(str(instance.id)) instance.hashcode = hashcode instance.save()
def pay_for_a_plan_success(request,pending_purchase,context,user_existing_coupons,selected_plan): # add the purchase to the database new_purchase = Purchase() new_purchase.user = pending_purchase.user new_purchase.data_transfer_plan = pending_purchase.data_transfer_plan if user_existing_coupons: new_purchase.amount_paid = selected_plan.discounted_price else: new_purchase.amount_paid = selected_plan.original_price new_purchase.remaining_allowance_frequency = pending_purchase.data_transfer_plan.freq new_purchase.save() # save follow_up number using hash follow_up_number = generate_md5_hash(str(new_purchase.id)) new_purchase.follow_up_number = follow_up_number new_purchase.save() context['follow_up_number'] = follow_up_number # if necessary, remove user's best coupon if user_existing_coupons: best_coupon = utility_functions.get_best_coupon(user_existing_coupons) best_coupon.delete() # send an email plaintext = loader.get_template('payment/pay_for_a_plan_complete_email.txt') htmly = loader.get_template('payment/pay_for_a_plan_complete_email.html') subject = loader.get_template('payment/pay_for_a_plan_complete_email_subject.html') subject_content = subject.render(context).replace('\n',' ') text_content = plaintext.render(context) html_content = htmly.render(context) from_email = '*****@*****.**' recipient_list = [new_purchase.user.email] msg = EmailMultiAlternatives(subject_content, text_content, from_email, recipient_list) msg.attach_alternative(html_content, "text/html") msg.send() # return response to the user. return render(request,'payment/successful_payment.html',context)
def pending_purchase_created(sender, instance, created, **kwargs): if created: hashcode = generate_md5_hash(str(instance.id)) instance.hashcode = hashcode instance.save()