def block_iptv_subscription(request): client = IPTVClient() customer_number = request.POST['customerNumber'] result = client.create_iptv_session() transaction_id = request.POST['transactionId'] if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), mimetype="application/json") session_id = result['session_id'] result = client.fetch_tv_subscriptions(session_id, customer_number) if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) if not result['subscription'][0] or not result['subscription'][ 0].tvSubscriptionId: response = { 'success': False, 'msg': "Subscriber (%s) has no IPTV subscriptions." % customer_number, } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) subscription_id = result['subscription'][0].tvSubscriptionId result = client.block_tv_subscription(session_id, subscription_id) if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) response = {'success': True, 'msg': ""} return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id)
def _release_session_and_return(session_id, request, fn_name, return_response, transaction_id): client = IPTVClient() result = client.release_iptv_session(session_id) if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } log_action(fn_name, request, response, transaction_id=transaction_id) log_action(fn_name, request, return_response, transaction_id=transaction_id) return HttpResponse(json.dumps(return_response), mimetype="application/json")
def remove_iptv_stb(request): client = IPTVClient() customer_number = request.POST['customerNumber'] mac_address = request.POST['macAddress'] transaction_id = request.POST['transactionId'] result = client.create_iptv_session() if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), mimetype="application/json") session_id = result['session_id'] result = client.fetch_tv_subscriptions(session_id, customer_number) if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) if not result['subscription'][0].tvSubscriptionId: response = { 'success': False, 'msg': "Subscriber (%s) has no IPTV subscriptions." % customer_number, } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) subscription_id = result['subscription'][0].tvSubscriptionId result = client.remove_stb(session_id, subscription_id, customer_number, mac_address) if not result['action_result']: if "STB" in result['action_error_message'] and "does not exist on subscription" \ in result['action_error_message']: response = { 'success': False, 'msg': "STB (%s) is not assigned to subscriber (%s)" % (mac_address, customer_number), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) response = {'success': True, 'msg': ''} return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id)
def query_user_info(request): client = IPTVClient() customer_number = request.GET['customerNumber'] transaction_id = request.GET['transactionId'] result = client.create_iptv_session() if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), mimetype="application/json") session_id = result['session_id'] result = client.fetch_tv_subscriptions(session_id, customer_number) if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) if not result['subscription'][0] or not result['subscription'][ 0].tvSubscriptionId: response = { 'success': False, 'msg': "Subscriber (%s) has no IPTV subscriptions." % customer_number, } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) subscription = result['subscription'][0] status = subscription.status package = subscription.packages[0].name if len( subscription.packages) else None stb = subscription.stbs[0].macAddress if hasattr(subscription, 'stbs') else None response = { 'success': True, 'msg': '', 'status': status, 'package': package, 'stb': stb } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id)
def create_customer(request): client = IPTVClient() customer_number = request.POST['customerNumber'] package_name = request.POST['packageName'] mac_address = request.POST['macAddress'] transaction_id = request.POST['transactionId'] result = client.create_iptv_session() if not result['action_result']: response = { 'success': False, 'msg': result.get('action_error_message'), } log_action(inspect.stack()[0][3], request, response, transaction_id=transaction_id) return HttpResponse(json.dumps(response), mimetype="application/json") session_id = result['session_id'] subscription_result = client.fetch_tv_subscriptions( session_id, customer_number) if subscription_result['action_result']: response = {'success': False, 'msg': 'Subscriber exists.'} return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) result = client.create_customer(session_id=session_id, customer_number=customer_number) if not result['action_result'] and not result[ 'action_error_message'].endswith('already exists. '): response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) result = client.order_tv_subscription(session_id, customer_number, package_name, mac_address) if not result['action_result']: client.remove_iptv_customer(session_id, customer_number) if "STB" in result[ 'action_error_message'] and "is already on subscription" in result[ 'action_error_message']: order_id = re.findall("[\d]{5}", result['action_error_message'])[0] single_subscription_result = client.fetch_tv_subscription( session_id, order_id) if single_subscription_result['action_result']: error_msg = "STB already assigned to subscriber (%s)" % \ single_subscription_result['subscription'].customerNumber else: error_msg = "STB already assigned to another subscriber" response = { 'success': False, 'msg': error_msg, } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) response = { 'success': False, 'msg': result.get('action_error_message'), } return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id) response = {'success': True, 'msg': ""} return _release_session_and_return(session_id, request, fn_name=inspect.stack()[0][3], return_response=response, transaction_id=transaction_id)