def add_plan(request, access_token): result = login_auth(access_token) if result['err']['code'] != 0: return HttpResponse(json.dumps(result)) userid = result['data']['id'] try: new_plan = Plan() user = FBUser.objects.get(fbid=userid) new_plan.holder = user new_plan.title = request.POST.get('title', "testtitle") new_plan.destination = request.POST.get('destination', "testdestination") new_plan.description = request.POST.get('description', "testdescription") new_plan.depart_time = request.POST.get('depart_time', datetime.today()) new_plan.length = request.POST.get('length', 2) new_plan.limit = request.POST.get('limit', 2) visible_type = request.POST.get('visible_type', 1) new_plan.visible_type = int(visible_type) friend_list = request.POST.getlist('friendlist',[]) new_plan.full_clean() new_plan.save() if new_plan.visible_type == 3: for friendid in friend_list: friend = FBUser.objects.get(fbid=friendid) private = PrivatePlan() private.accessible_user = friend private.accessible_plan = new_plan private.full_clean() private.save() result = format(0, 'create success') return HttpResponse(json.dumps(result)) except Exception as e: result = format(400, str(e)) return HttpResponse(json.dumps(result))
def test_api_get_plan_name(self): register_user_from_homepage() profile = ClientProfile.objects.all()[0] profile.account_key = "123" profile.save() plan = Plan(user=profile.user, type="1", status="active") plan.save() resp = c.post(reverse('api_get_plan_name'), {'account_key': "1234"}) self.assertContains(resp, "error") self.assertEqual(resp.status_code, 200)
def _create_plan(self, **kwargs): opts = { 'name': 'test-plan', 'available': True, 'visible': True, 'created': datetime.now() } opts.update(kwargs) p = Plan(**opts) p.full_clean() p.save() return p
def test_website_adding_get(self): # create and log in a user register_user_from_homepage() logged_in = c.login(username='******', password='******') profile = ClientProfile.objects.all()[0] plan = Plan(user=profile.user, type=PlanVariant.PRO, status='active') plan.save() # assert that he logged in self.assertTrue(logged_in) resp = c.get(reverse('websites')) self.assertEqual(resp.status_code, 200)
def test_website_adding_post(self): # create a push package package = create_push_package( os.path.join(settings.MEDIA_ROOT, 'test2')) # create and log in a user register_user_from_homepage() logged_in = c.login(username='******', password='******') profile = ClientProfile.objects.all()[0] # add an account_key because the test will not actually associate a push # package to this profile profile.account_key = "123" profile.save() plan = Plan(user=profile.user, type=PlanVariant.PRO, status='active') plan.save() # assert that he logged in self.assertTrue(logged_in) self.assertEqual(WebsiteIcon.objects.count(), 0) # get the URL first, to create the website cluster resp = c.get(reverse('websites')) self.assertEqual(resp.status_code, 200) # fill in the form icon_file = open( os.path.join(settings.MEDIA_ROOT, 'test2', 'image.png')) resp = c.post( reverse('websites'), { 'website_url': 'http://test2.com', 'icon': icon_file, 'website_name': "Ze Test", }) # assert that websites have been created self.assertRedirects(resp, reverse('websites')) self.assertEqual(WebsiteIcon.objects.count(), 1) self.assertEqual(WebsiteCluster.objects.count(), 1) cluster = WebsiteCluster.objects.all()[0] self.assertEqual(cluster.website_set.count(), 2) for website in cluster.website_set.all(): self.assertTrue(website.account_key != None) self.assertEqual( cluster.website_set.filter(account_key=package.identifier).count(), 1)
def prepare_adding_website_to_cluster(self): # create a push package package = create_push_package(os.path.join(settings.MEDIA_ROOT, 'test2')) # create and log in a user register_user_from_homepage() logged_in = c.login(username='******', password='******') profile = ClientProfile.objects.all()[0] # add an account_key because the test will not actually associate a push # package to this profile profile.account_key = "123" profile.save() plan = Plan(user=profile.user, type=PlanVariant.PRO, status='active') plan.save() # assert that he logged in self.assertTrue(logged_in) self.assertEqual(WebsiteIcon.objects.count(), 0) # get the URL first, to create the website cluster resp = c.get(reverse('websites')) self.assertEqual(resp.status_code, 200) return package
def redeem(request): redeemed = False plan = None if request.method == "POST": form = RedeemForm(data=request.POST) if form.is_valid(): #mark coupon as redeemed code = form.cleaned_data['code'] coupon = Coupon.objects.get(string=code) coupon.redeemed = True coupon.user = request.user coupon.save() redeemed = True #create a new plan for this coupon end_at = datetime.now() + timedelta(days=365 * coupon.time_unit_count) if coupon.time_unit == 'monthly': end_at = datetime.now() + timedelta(days=30 * coupon.time_unit_count) plan = Plan(user=request.user, type=coupon.plan, end_at=end_at, status='active', payed=False, txn_id='Coupon') plan.save() redeemed = True else: form = RedeemForm() return render_to_response('coupons/redeem.html', { 'form': form, 'redeemed': redeemed, 'plan': plan, 'plans': PlanVariant, }, RequestContext(request))
def add_plan(request, access_token): result = login_auth(access_token) if result['err']['code'] != 0: return HttpResponse(json.dumps(result)) userid = result['data']['id'] try: new_plan = Plan() user = FBUser.objects.get(fbid=userid) new_plan.holder = user new_plan.title = request.POST.get('title', "testtitle") new_plan.destination = request.POST.get('destination', "testdestination") new_plan.description = request.POST.get('description', "testdescription") new_plan.depart_time = request.POST.get('depart_time', datetime.today()) new_plan.length = request.POST.get('length', 2) new_plan.limit = request.POST.get('limit', 2) visible_type = request.POST.get('visible_type', 1) new_plan.visible_type = int(visible_type) friend_list = request.POST.getlist('friendlist', []) new_plan.full_clean() new_plan.save() if new_plan.visible_type == 3: for friendid in friend_list: friend = FBUser.objects.get(fbid=friendid) private = PrivatePlan() private.accessible_user = friend private.accessible_plan = new_plan private.full_clean() private.save() result = format(0, 'create success') return HttpResponse(json.dumps(result)) except Exception as e: result = format(400, str(e)) return HttpResponse(json.dumps(result))
def register_thank_you(request, profile_id=None): try: profile = ClientProfile.objects.get(id=profile_id) if profile.registration_step != 3: raise Http404("Wrong user.") profile.registration_step = 4 profile.save() except: raise Http404( "Reached register_thank_you with no ClientProfile. profile_id=" + str(profile_id)) if profile.has_push_package(): return redirect('dashboard') if profile.status == 'active': return redirect('dashboard') #push package package_manager = PushPackageManager() package = package_manager.get_push_package(profile) if package: profile_image = ProfileImage.objects.get(profile=profile) package.generate_zip( profile.website_name, profile.website, profile_image.image128_2x.path, profile_image.image128.path, profile_image.image32_2x.path, profile_image.image32.path, profile_image.image16_2x.path, profile_image.image16.path, ) profile.status = 'active' profile.account_key = package.identifier profile.website_push_id = package.website_push_id profile.save() package.used = True package.save() else: profile.status = 'pending' profile.save() #plan if profile.from_envato: plan = Plan.objects.create_fixed_plan(profile.user) else: plan = Plan(user=profile.user, type=plans.TRIAL, end_at=datetime.now() + timedelta(days=30), status='active', payed=False) plan.save() #send email to ADMINS email_manager = PlansEmailManager() email_manager.send_admin_new_plan(profile.user.email, profile.user.first_name, plan) url = profile.return_url if len(url): #redirect back to WP if package: if url.find('?') > 0: url += "&push_monkey_account_key=" + profile.account_key + "&push_monkey_registered=1" else: url += "?push_monkey_account_key=" + profile.account_key + "&push_monkey_registered=1" else: url += "&push_monkey_package_pending=1&push_monkey_registered=1" return HttpResponseRedirect(url) return render_to_response('clients/register-thank-you.html', {}, RequestContext(request))
active=plan['active'], md=plan['md'], inc=plan['inc'], azi=plan['azi'], tvd=plan['tvd'], north=plan['north'], east=plan['east'], vertical_section=plan['vertical_section'], dogleg=plan['dogleg'], build_rate=plan['build_rate'], turn_rate=plan['turn_rate'], calculated_tf=plan['calculated_tf'], zero_vs=plan['zero_vs'], step_out=plan['step_out'], tie_in_depth=plan['tie_in_depth']) plan.save() except: print("bad plan") with open('motors.json', encoding="utf8") as f: assets_json = json.load(f) for asset in assets_json: asset = Asset(asset_group=asset["asset_group"], asset_type=asset["asset_type"], serial_num=asset["serial_num"], part_num=asset["part_num"], rig_item=asset["rig_item"], rented=asset["rented"], condition_status=asset["condition_status"], size=asset["size"],