def whitelist_edit(request): variables = {} whitelist_id = int(request.POST.get("data[id]", "0")) phoneuser_id = int(request.POST.get("data[phoneuser_id]", "0")) if whitelist_id: try: whitelist = Whitelist.objects.get(pk=whitelist_id) whitelist.duration = int(whitelist.duration / 60) whitelist.frequency = int(whitelist.frequency) except: raise Http404 else: whitelist = Whitelist() whitelist.duration = int(Pref.get("threshold")) / 60 if phoneuser_id: try: whitelist.phoneuser = PhoneUser.objects.get(pk=phoneuser_id) except: raise Http404 variables['whitelist'] = whitelist variables['enable_first_in'] = Pref.get("enable_first_in") variables['change_threshold'] = Pref.get("change_threshold") return render_to_response('phoneusers/whitelists/whitelist.html', variables)
def whitelist_save(request): """Save or update whitelist""" whitelist_id = int(request.POST.get("data[whitelist_id]", "0")) phoneuser_id = int(request.POST.get("data[phoneuser_id]", "0")) label = request.POST.get("data[label]", "") phonenumber = request.POST.get("data[phonenumber]", "") duration = int(request.POST.get("data[duration]", "0")) frequency = int(request.POST.get("data[frequency]", "0")) real_mobile = int(request.POST.get("data[real_mobile]", "0")) # la maschera consente di inserire i minuti duration = duration * 60 action = "Creazione" try: if whitelist_id: whitelist = Whitelist.objects.get(pk=whitelist_id) action = "Modifica" else: whitelist = Whitelist() if frequency == 0: whitelist.enabled = True whitelist.phoneuser_id = phoneuser_id whitelist.label = label whitelist.phonenumber = phonenumber whitelist.duration = duration whitelist.frequency = frequency whitelist.real_mobile = real_mobile whitelist.save() # log azione audit = Audit() audit.log(user=request.user, what="%s autorizzazione: %s" % (action, whitelist.phoneuser)) return whitelist_items(request, phoneuser_id) except Exception as e: return HttpResponse(status=400, content=json.dumps({'err_msg': format(e)}), content_type='application/json')