def simulator(request): """Client Simulator To view rate according to VoIP Plan & Destination No. **Attributes**: * ``template`` - voip_billing/simulator.html * ``form`` - SimulatorForm **Logic Description**: get min call rates for destination from rate_engine and display them in template """ data = [] form = SimulatorForm(request.user, request.POST or None) # Get Voip Plan ID according to USER if form.is_valid(): # IS recipient_phone_no/destination no is valid prefix # (Not banned Prefix) ? destination_no = request.POST.get("destination_no") if hasattr(request.user, 'userprofile'): voipplan_id = request.user.userprofile.voipplan_id allowed = prefix_allowed_to_call(destination_no, voipplan_id) if allowed: rates = rate_engine(voipplan_id=voipplan_id, dest_number=destination_no) for rate in rates: r_r_plan = VoIPRetailRate.objects.get(id=rate.rrid) data.append( (voipplan_id, r_r_plan.voip_retail_plan_id.name, rate.retail_rate)) data = { 'form': form, 'data': data, } return render_to_response('voip_billing/simulator.html', data, context_instance=RequestContext(request))
def simulator(request): """Client Simulator To view rate according to VoIP Plan & Destination No. **Attributes**: * ``template`` - voip_billing/simulator.html * ``form`` - SimulatorForm **Logic Description**: get min call rates for destination from rate_engine and display them in template """ data = [] form = SimulatorForm(request.user, request.POST or None) # Get Voip Plan ID according to USER if form.is_valid(): # IS recipient_phone_no/destination no is valid prefix # (Not banned Prefix) ? destination_no = request.POST.get("destination_no") if hasattr(request.user, 'userprofile'): voipplan_id = request.user.userprofile.voipplan_id allowed = prefix_allowed_to_call(destination_no, voipplan_id) if allowed: rates = rate_engine(voipplan_id=voipplan_id, dest_number=destination_no) for rate in rates: r_r_plan = VoIPRetailRate.objects.get(id=rate.rrid) data.append((voipplan_id, r_r_plan.voip_retail_plan_id.name, rate.retail_rate)) data = { 'form': form, 'data': data, } return render_to_response('voip_billing/simulator.html', data, context_instance=RequestContext(request))
def simulator(self, request): """ Admin Simulator To view rate according to VoIP Plan & Destination No. """ opts = VoIPPlan._meta # Assign form field value to local variable destination_no = variable_value(request, "destination_no") voipplan_id = variable_value(request, "plan_id") data = [] form = SimulatorForm(request.user, request.POST or None) if form.is_valid(): destination_no = request.POST.get("destination_no") voipplan_id = request.POST.get("plan_id") rates = rate_engine(voipplan_id=voipplan_id, dest_number=destination_no) for rate in rates: c_r_plan = VoIPCarrierRate.objects.get(id=rate.crid) r_r_plan = VoIPRetailRate.objects.get(id=rate.rrid) data.append((voipplan_id, c_r_plan.voip_carrier_plan_id.id, c_r_plan.voip_carrier_plan_id.name, r_r_plan.voip_retail_plan_id.id, r_r_plan.voip_retail_plan_id.name, rate.crid, rate.carrier_rate, rate.rrid, rate.retail_rate, rate.rt_prefix)) variables = { 'title': _('VoIP Simulator'), 'form': form, 'opts': opts, 'model_name': opts.object_name.lower(), 'data': data, } ctx = RequestContext(request, variables) return render_to_response('admin/voip_billing/voipplan/simulator.html', context_instance=ctx)