def is_authorized_contact(self, str_contact): """Check if a contact is authorized""" try: dialersetting = UserProfile.objects.get(user=self.user).dialersetting return common_contact_authorization(dialersetting, str_contact) except UserProfile.DoesNotExist: return False
def is_authorized_contact(self, str_contact): """Check if a contact is authorized""" try: dialersetting = UserProfile.objects.get( user=self.user).dialersetting return common_contact_authorization(dialersetting, str_contact) except UserProfile.DoesNotExist: return False
def is_authorized_contact(self, str_contact): """Check if a contact is authorized""" from user_profile.models import UserProfile try: dialersetting = UserProfile.objects.get(user=self.user).dialersetting from dialer_campaign.models import common_contact_authorization return common_contact_authorization(dialersetting, str_contact) except UserProfile.DoesNotExist: return False
def customer_detail_change(request): """User Detail change on Customer UI **Attributes**: * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm * ``template`` - 'frontend/registration/user_detail_change.html' **Logic Description**: * User is able to change his/her detail. """ user_detail = get_object_or_404(User, username=request.user) try: user_detail_extened = UserProfile.objects.get(user=user_detail) except UserProfile.DoesNotExist: #create UserProfile user_detail_extened = UserProfile(user=user_detail) #DEMO / Disable if not settings.DEMO_MODE: user_detail_extened.save() user_detail_form = UserChangeDetailForm(request.user, instance=user_detail) user_detail_extened_form = \ UserChangeDetailExtendForm(request.user, instance=user_detail_extened) user_password_form = PasswordChangeForm(user=request.user) check_phone_no_form = CheckPhoneNumberForm() try: dialer_set = DialerSetting.objects.get(id=request.user.get_profile().dialersetting_id) except: dialer_set = '' msg_detail = '' msg_pass = '' msg_number = '' error_detail = '' error_pass = '' error_number = '' action = '' if 'action' in request.GET: action = request.GET['action'] if request.method == 'POST': if request.POST['form-type'] == "change-detail": user_detail_form = UserChangeDetailForm( request.user, request.POST, instance=user_detail) user_detail_extened_form = \ UserChangeDetailExtendForm( request.user, request.POST, instance=user_detail_extened) action = 'tabs-1' if (user_detail_form.is_valid() and user_detail_extened_form.is_valid()): #DEMO / Disable if not settings.DEMO_MODE: user_detail_form.save() user_detail_extened_form.save() msg_detail = _('detail has been changed.') else: error_detail = _('please correct the errors below.') elif request.POST['form-type'] == "check-number": # check phone no action = 'tabs-4' check_phone_no_form = CheckPhoneNumberForm(data=request.POST) if check_phone_no_form.is_valid(): if not common_contact_authorization(request.user, request.POST['phone_number']): error_number = _('this phone number is not authorized.') else: msg_number = _('this phone number is authorized.') else: error_number = _('please correct the errors below.') else: # "change-password" user_password_form = PasswordChangeForm(user=request.user, data=request.POST) action = 'tabs-2' if user_password_form.is_valid(): #DEMO / Disable if not settings.DEMO_MODE: user_password_form.save() msg_pass = _('your password has been changed.') else: error_pass = _('please correct the errors below.') template = 'frontend/registration/user_detail_change.html' data = { 'module': current_view(request), 'user_detail_form': user_detail_form, 'user_detail_extened_form': user_detail_extened_form, 'user_password_form': user_password_form, 'check_phone_no_form': check_phone_no_form, 'msg_detail': msg_detail, 'msg_pass': msg_pass, 'msg_number': msg_number, 'error_detail': error_detail, 'error_pass': error_pass, 'error_number': error_number, 'dialer_set': dialer_set, 'dialer_setting_msg': user_dialer_setting_msg(request.user), 'action': action, } return render_to_response(template, data, context_instance=RequestContext(request))
def customer_detail_change(request): """User Detail change on Customer UI **Attributes**: * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm * ``template`` - 'frontend/registration/user_detail_change.html' **Logic Description**: * User is able to change his/her detail. """ user_detail = User.objects.get(username=request.user) try: user_detail_extened = UserProfile.objects.get(user=user_detail) except UserProfile.DoesNotExist: #create UserProfile user_detail_extened = UserProfile(user=user_detail) #DEMO / Disable user_detail_extened.save() user_detail_form = UserChangeDetailForm(request.user, instance=user_detail) user_detail_extened_form = \ UserChangeDetailExtendForm(request.user, instance=user_detail_extened) user_password_form = PasswordChangeForm(user=request.user) check_phone_no_form = CheckPhoneNumberForm() try: user_ds = UserProfile.objects.get(user=request.user) dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id) except: dialer_set = '' user_notification = \ notification.Notice.objects.filter(recipient=request.user) # Search on sender name q = (Q(sender=request.user)) if q: user_notification = user_notification.filter(q) msg_detail = '' msg_pass = '' msg_number = '' msg_note = '' error_detail = '' error_pass = '' error_number = '' action = '' if 'action' in request.GET: action = request.GET['action'] if request.GET.get('msg_note') == 'true': msg_note = request.session['msg_note'] # Mark all notification as read if request.GET.get('notification') == 'mark_read_all': notification_list = \ notification.Notice.objects.filter(unseen=1, recipient=request.user) notification_list.update(unseen=0) msg_note = _('All notifications are marked as read.') if request.method == 'POST': if request.POST['form-type'] == "change-detail": user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail) user_detail_extened_form = \ UserChangeDetailExtendForm(request.user, request.POST, instance=user_detail_extened) action = 'tabs-1' if user_detail_form.is_valid() \ and user_detail_extened_form.is_valid(): #DEMO / Disable user_detail_form.save() user_detail_extened_form.save() msg_detail = _('Detail has been changed.') else: error_detail = _('Please correct the errors below.') elif request.POST['form-type'] == "check-number": # check phone no action = 'tabs-5' check_phone_no_form = CheckPhoneNumberForm(data=request.POST) if check_phone_no_form.is_valid(): if not common_contact_authorization( request.user, request.POST['phone_number']): error_number = _('This phone number is not authorized.') else: msg_number = _('This phone number is authorized.') else: error_number = _('Please correct the errors below.') else: # "change-password" user_password_form = PasswordChangeForm(user=request.user, data=request.POST) action = 'tabs-2' if user_password_form.is_valid(): #DEMO / Disable user_password_form.save() msg_pass = _('Your password has been changed.') else: error_pass = _('Please correct the errors below.') template = 'frontend/registration/user_detail_change.html' data = { 'module': current_view(request), 'user_detail_form': user_detail_form, 'user_detail_extened_form': user_detail_extened_form, 'user_password_form': user_password_form, 'check_phone_no_form': check_phone_no_form, 'user_notification': user_notification, 'msg_detail': msg_detail, 'msg_pass': msg_pass, 'msg_number': msg_number, 'msg_note': msg_note, 'error_detail': error_detail, 'error_pass': error_pass, 'error_number': error_number, 'notice_count': notice_count(request), 'dialer_set': dialer_set, 'dialer_setting_msg': user_dialer_setting_msg(request.user), 'action': action, } return render_to_response(template, data, context_instance=RequestContext(request))
def customer_detail_change(request): """User Detail change on Customer UI **Attributes**: * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm * ``template`` - 'frontend/registration/user_detail_change.html' **Logic Description**: * User is able to change his/her detail. """ user_detail = User.objects.get(username=request.user) try: user_detail_extened = UserProfile.objects.get(user=user_detail) except UserProfile.DoesNotExist: #create UserProfile user_detail_extened = UserProfile(user=user_detail) user_detail_extened.save() user_detail_form = UserChangeDetailForm(request.user, instance=user_detail) user_detail_extened_form = UserChangeDetailExtendForm(request.user, instance=user_detail_extened) user_password_form = PasswordChangeForm(user=request.user) check_phone_no_form = CheckPhoneNumberForm() try: user_ds = UserProfile.objects.get(user=request.user) dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id) except: dialer_set = '' user_notification = \ notification.Notice.objects.filter(recipient=request.user) # Search on sender name q = (Q(sender=request.user)) if q: user_notification = user_notification.filter(q) msg_detail = '' msg_pass = '' msg_number = '' msg_note = '' error_detail = '' error_pass = '' error_number = '' action = '' if 'action' in request.GET: action = request.GET['action'] if request.GET.get('msg_note') == 'true': msg_note = request.session['msg_note'] # Mark all notification as read if request.GET.get('notification') == 'mark_read_all': notification_list = notification.Notice.objects.filter(unseen=1, recipient=request.user) notification_list.update(unseen=0) msg_note = _('All notifications are marked as read.') if request.method == 'POST': if request.POST['form-type'] == "change-detail": user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail) user_detail_extened_form = UserChangeDetailExtendForm(request.user, request.POST, instance=user_detail_extened) action = 'tabs-1' if user_detail_form.is_valid() and user_detail_extened_form.is_valid(): user_detail_form.save() user_detail_extened_form.save() msg_detail = _('Detail has been changed.') else: error_detail = _('Please correct the errors below.') elif request.POST['form-type'] == "check-number": # check phone no action = 'tabs-5' check_phone_no_form = CheckPhoneNumberForm(data=request.POST) if check_phone_no_form.is_valid(): if not common_contact_authorization(request.user, request.POST['phone_number']): error_number = _('This phone number is not authorized.') else: msg_number = _('This phone number is authorized.') else: error_number = _('Please correct the errors below.') else: # "change-password" user_password_form = PasswordChangeForm(user=request.user, data=request.POST) action = 'tabs-2' if user_password_form.is_valid(): user_password_form.save() msg_pass = _('Your password has been changed.') else: error_pass = _('Please correct the errors below.') template = 'frontend/registration/user_detail_change.html' data = { 'module': current_view(request), 'user_detail_form': user_detail_form, 'user_detail_extened_form': user_detail_extened_form, 'user_password_form': user_password_form, 'check_phone_no_form': check_phone_no_form, 'user_notification': user_notification, 'msg_detail': msg_detail, 'msg_pass': msg_pass, 'msg_number': msg_number, 'msg_note': msg_note, 'error_detail': error_detail, 'error_pass': error_pass, 'error_number': error_number, 'notice_count': notice_count(request), 'dialer_set': dialer_set, 'dialer_setting_msg': user_dialer_setting_msg(request.user), 'action': action, } return render_to_response(template, data, context_instance=RequestContext(request))
def customer_detail_change(request): """User Detail change on Customer UI **Attributes**: * ``form`` - UserChangeDetailForm, PasswordChangeForm, CheckPhoneNumberForm * ``template`` - 'frontend/registration/user_detail_change.html' **Logic Description**: * User is able to change his/her detail. """ user_detail = User.objects.get(username=request.user) user_detail_form = UserChangeDetailForm(user=request.user, instance=user_detail) user_password_form = PasswordChangeForm(user=request.user) check_phone_no_form = CheckPhoneNumberForm() try: user_ds = UserProfile.objects.get(user=request.user) dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id) except: dialer_set = '' user_notification = \ notification.Notice.objects.filter(recipient=request.user) # Search on sender name q = (Q(sender=request.user)) if q: user_notification = user_notification.filter(q) msg_detail = '' msg_pass = '' msg_number = '' msg_note = '' error_detail = '' error_pass = '' error_number = '' selected = 0 if 'selected' in request.GET: selected = request.GET['selected'] if request.GET.get('msg_note') == 'true': msg_note = request.session['msg_note'] if request.method == 'POST': if request.POST['form-type'] == "change-detail": user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail) selected = 0 if user_detail_form.is_valid(): user_detail_form.save() msg_detail = _('Your detail has been changed successfully.') else: error_detail = _('Please correct the errors below.') elif request.POST['form-type'] == "check-number": # check phone no selected = 4 check_phone_no_form = CheckPhoneNumberForm(data=request.POST) if not common_contact_authorization(request.user, request.POST['phone_number']): error_number = _('This phone number is not authorized.') else: msg_number = _('This phone number is authorized.') else: # "change-password" user_password_form = PasswordChangeForm(user=request.user, data=request.POST) selected = 1 if user_password_form.is_valid(): user_password_form.save() msg_pass = _('Your password has been changed successfully.') else: error_pass = _('Please correct the errors below.') template = 'frontend/registration/user_detail_change.html' data = { 'module': current_view(request), 'user_detail_form': user_detail_form, 'user_password_form': user_password_form, 'check_phone_no_form': check_phone_no_form, 'user_notification': user_notification, 'msg_detail': msg_detail, 'msg_pass': msg_pass, 'msg_number': msg_number, 'msg_note': msg_note, 'selected': selected, 'error_detail': error_detail, 'error_pass': error_pass, 'error_number': error_number, 'notice_count': notice_count(request), 'dialer_set': dialer_set, 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def test_campaign_form(self): self.assertEqual(self.campaign.name, "sample_campaign") Campaign.objects.get_running_campaign() Campaign.objects.get_expired_campaign() dialersetting = DialerSetting.objects.get(pk=1) #self.user.get_profile().dialersetting common_contact_authorization(dialersetting, '1234567890') # status = 1 self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 2 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 3 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 4 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.is_authorized_contact(dialersetting, '123456789') self.campaign.get_active_max_frequency() self.campaign.get_active_callmaxduration() self.campaign.get_active_contact() self.campaign.progress_bar() self.campaign.subscriber_detail() self.campaign.get_pending_subscriber_update(10, SUBSCRIBER_STATUS.IN_PROCESS) self.assertEqual(self.subscriber.campaign, self.campaign) form = CampaignForm(self.user) obj = form.save(commit=False) obj.name = "new_campaign" obj.user = self.user obj.phonebook_id = 1 obj.aleg_gateway_id = 1 obj.content_type_id = self.content_type_id obj.object_id = 1 obj.save() form = CampaignForm(self.user, instance=self.campaign) self.assertTrue(isinstance(form.instance, Campaign)) form = CampaignForm(self.user, data={ "name": "mylittle_campaign", "description": "xyz", "startingdate": "1301392136.0", "expirationdate": "1301332136.0", "frequency": "120", "callmaxduration": "50", "maxretry": "3", "intervalretry": "2000", "calltimeout": "60", "aleg_gateway": "1", "sms_gateway": "", "content_object": "type:32-id:1", "extra_data": "2000"}) self.assertEquals(form.is_valid(), False)
def customer_detail_change(request): """User Detail change on Customer UI **Attributes**: * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm * ``template`` - 'frontend/registration/user_detail_change.html' **Logic Description**: * User is able to change his/her detail. """ user_detail = User.objects.get(username=request.user) try: user_detail_extened = UserProfile.objects.get(user=user_detail) except UserProfile.DoesNotExist: # create UserProfile user_detail_extened = UserProfile(user=user_detail) user_detail_extened.save() user_detail_form = UserChangeDetailForm(request.user, instance=user_detail) user_detail_extened_form = UserChangeDetailExtendForm(request.user, instance=user_detail_extened) user_password_form = PasswordChangeForm(user=request.user) check_phone_no_form = CheckPhoneNumberForm() try: user_ds = UserProfile.objects.get(user=request.user) dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id) except: dialer_set = "" user_notification = notification.Notice.objects.filter(recipient=request.user) # Search on sender name q = Q(sender=request.user) if q: user_notification = user_notification.filter(q) msg_detail = "" msg_pass = "" msg_number = "" msg_note = "" error_detail = "" error_pass = "" error_number = "" action = "" if "action" in request.GET: action = request.GET["action"] if request.GET.get("msg_note") == "true": msg_note = request.session["msg_note"] # Mark all notification as read if request.GET.get("notification") == "mark_read_all": notification_list = notification.Notice.objects.filter(unseen=1, recipient=request.user) notification_list.update(unseen=0) msg_note = _("All notifications are marked as read.") if request.method == "POST": if request.POST["form-type"] == "change-detail": user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail) user_detail_extened_form = UserChangeDetailExtendForm( request.user, request.POST, instance=user_detail_extened ) action = "tabs-1" if user_detail_form.is_valid() and user_detail_extened_form.is_valid(): user_detail_form.save() user_detail_extened_form.save() msg_detail = _("Detail has been changed.") else: error_detail = _("Please correct the errors below.") elif request.POST["form-type"] == "check-number": # check phone no action = "tabs-5" check_phone_no_form = CheckPhoneNumberForm(data=request.POST) if check_phone_no_form.is_valid(): if not common_contact_authorization(request.user, request.POST["phone_number"]): error_number = _("This phone number is not authorized.") else: msg_number = _("This phone number is authorized.") else: error_number = _("Please correct the errors below.") else: # "change-password" user_password_form = PasswordChangeForm(user=request.user, data=request.POST) action = "tabs-2" if user_password_form.is_valid(): user_password_form.save() msg_pass = _("Your password has been changed.") else: error_pass = _("Please correct the errors below.") template = "frontend/registration/user_detail_change.html" data = { "module": current_view(request), "user_detail_form": user_detail_form, "user_detail_extened_form": user_detail_extened_form, "user_password_form": user_password_form, "check_phone_no_form": check_phone_no_form, "user_notification": user_notification, "msg_detail": msg_detail, "msg_pass": msg_pass, "msg_number": msg_number, "msg_note": msg_note, "error_detail": error_detail, "error_pass": error_pass, "error_number": error_number, "notice_count": notice_count(request), "dialer_set": dialer_set, "dialer_setting_msg": user_dialer_setting_msg(request.user), "action": action, } return render_to_response(template, data, context_instance=RequestContext(request))
def test_campaign_form(self): self.assertEqual(self.campaign.name, "sample_campaign") Campaign.objects.get_running_campaign() Campaign.objects.get_expired_campaign() dialersetting = DialerSetting.objects.get(pk=1) #self.user.get_profile().dialersetting common_contact_authorization(dialersetting, '1234567890') # status = 1 self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 2 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 3 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 4 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.is_authorized_contact(dialersetting, '123456789') self.campaign.get_active_max_frequency() self.campaign.get_active_callmaxduration() self.campaign.get_active_contact() self.campaign.progress_bar() self.campaign.subscriber_detail() self.campaign.get_pending_subscriber_update( 10, SUBSCRIBER_STATUS.IN_PROCESS) self.assertEqual(self.subscriber.campaign, self.campaign) form = CampaignForm(self.user) obj = form.save(commit=False) obj.name = "new_campaign" obj.user = self.user obj.phonebook_id = 1 obj.aleg_gateway_id = 1 obj.content_type_id = self.content_type_id obj.object_id = 1 obj.save() form = CampaignForm(self.user, instance=self.campaign) self.assertTrue(isinstance(form.instance, Campaign)) form = CampaignForm(self.user, data={ "name": "mylittle_campaign", "description": "xyz", "startingdate": "1301392136.0", "expirationdate": "1301332136.0", "frequency": "120", "callmaxduration": "50", "maxretry": "3", "intervalretry": "2000", "calltimeout": "60", "aleg_gateway": "1", "content_object": "type:32-id:1", "extra_data": "2000", "ds_user": self.user }) self.assertEquals(form.is_valid(), False)