def change_plan(request, device_id): get_object_or_404(Device, id=device_id, user=request.user) tup = f5.device_details(request, device_id) if not tup or tup == ('', ''): raise Http404 if tup[0][u'paid']: raise Http404 ERROR = False if request.method == "POST" and "active-plan" in request.POST: try: plan = request.POST["active-plan"] url = settings.FPAN['host'] + settings.FPAN['urls']['change_plan'] payload = {'plan': plan, 'device_id': device_id} r = requests.post(url, data=payload, headers=f5.get_api_header(), verify=False) print r.content if r.status_code == 200: from apps.devices.views import start_invoice_pay return HttpResponseRedirect( reverse(start_invoice_pay, kwargs={'invoice_id': r.json()['invoice_id']})) else: ERROR = True except: ERROR = True plans = parse_plans(request) variables = dict(plans=plans, ERROR=ERROR) return render_to_response('change_plan.html', RequestContext(request, variables))
def get_user_id_from_udid(request): udid = request.GET["udid"].lower() try: device = Device.objects.filter(device_id=udid).order_by("-id")[0] except IndexError: import string rot13 = string.maketrans( "ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz", "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm") udid = string.translate(str(udid), rot13) device = Device.objects.filter(device_id=udid).order_by("-id")[0] import apps.panel.f5adapter as f5 tup = f5.device_details(request, device.id, activate=True) invoice = tup[0] record = tup[2] avatar = get_avatar(device.user) data = { 'userID': str(device.user.id.user_id), 'name': unicode(device.user.first_name), 'email': device.user.email, 'avatar': avatar, 'expire_date': record['due_date'], 'plan': invoice['plan'], 'status': user_status_calculater(tup), } return HttpResponse(json.dumps(data), content_type="application/json")
def send_user_latestplan_analytics(user, request): latestPlan = {} for device in user.device_set.all(): if device.device_id: import apps.panel.f5adapter as f5 tup = f5.device_details(request, device.id) try: latestPlan[device.device_id] = get_plan_label( tup[2]['plan_label']) except: pass analytics.identify(user.id.user_id, {'latestPlan': latestPlan})
def get_device_status(request, device_id): import apps.panel.f5adapter as f5 tup = f5.device_details(request, device_id) print tup try: data = { 'status': 'ok', 'user_status': (1 if tup[2]['is_active'] else 2), } return data except: return {}
def f(dev): if device_id and str(dev.id) != str(device_id): return None tup = f5.device_details(request, dev.id) if tup == ('', '') or not tup: return None if str(tup[2]['status']) in ['2', '7']: return None return InvoiceInfo( 'paid', tup[0][u'plan_label'], tup[0][u'plan_amount'], tup[0][u'amount'], reverse(invoice_details, kwargs={'invoice_id': tup[0]['id']}), tup[0][u'invoice_payment_url'][u'mellat'], dev.device_product)
def get_f5_data(request): """Get a udid (device_id) in a post request and return its related data our from F5 service. """ udid = request.POST.get("udid") if not udid: raise Http404 uuid = Device.objects.filter(device_id=udid).reverse()[0].id f5_data = f5.device_details(request, uuid) return json.dumps({ 'invoice': f5_data[0], 'plan': f5_data[1], 'record': f5_data[2] })
def get_user_status(request): udid = request.GET["id"] print udid try: device = Device.objects.filter(device_id=udid).order_by("-id")[0] except IndexError: import string rot13 = string.maketrans( "ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz", "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm") udid = string.translate(str(udid), rot13) try: device = Device.objects.filter(device_id=udid).order_by("-id")[0] except: return HttpResponse( json.dumps({ "status": "errro", "message": "Access denied!" })) import apps.panel.f5adapter as f5 tup = f5.device_details(request, device.id, activate=True) print tup try: data = { 'status': 'ok', 'user_status': user_status_calculater(tup), } if data['user_status'] == 2: data['link'] = tup[0][u'invoice_payment_url'][u'mellat'] return HttpResponse(json.dumps(data), content_type="application/json") except: return HttpResponse( json.dumps({ "status": "errro", "message": "Access denied!" }))
def f(dev): tup = f5.device_details(request, dev.id) if tup == ('', '') or not tup: user_info = appdb.users.find_one({ 'user_id': str(dev.user.id.user_id), "device": str(dev.pk) }) if is_free_device(dev) and user_info: campaigns = user_info.get('campaigns', None) return DeviceInfo().free_device(dev.id, campaigns) else: return None try: j = dateutil.parser.parse(tup[2][u'due_date']) date = jdatetime.date.fromgregorian( day=j.day, month=j.month, year=j.year).strftime("%Y/%m/%d") print tup[0] if dev.device_id is None: return DeviceInfo().unregistered_device( dev.id, tup[1][u'label'], date, reverse(invoice_of_device, kwargs={'device_id': dev.id}), tup[0][u'paid'], tup[0][u'plan_label'], tup[2]['status'], j) else: return DeviceInfo().registered_device( dev.id, dev.device_product, tup[1][u'label'], date, reverse(invoice_of_device, kwargs={'device_id': dev.id}), dev.device_id, tup[0][u'paid'], tup[0][u'plan_label'], tup[2]['status'], j) except: import traceback traceback.print_exc() return None