Exemplo n.º 1
0
    def test_user_settings(self):
        """Test Function to check User settings"""
        response = self.client.post('/user_detail_change/?action=tabs-1',
                                    {'form-type': 'change-detail',
                                     'first_name': 'admin',
                                     'phone_no': '9324552563'})
        self.assertTrue(response.context['user_detail_form'],
                        UserChangeDetailForm(self.user))
        self.assertTrue(response.context['user_detail_extened_form'],
                        UserChangeDetailExtendForm(self.user))

        response = self.client.post('/user_detail_change/?action=tabs-2',
                                    {'form-type': ''})
        self.assertTrue(response.context['user_password_form'],
                        PasswordChangeForm(self.user))

        response = self.client.get(
            '/user_detail_change/?action=tabs-3&notification=mark_read_all', {})
        self.assertEqual(response.status_code, 200)

        response = self.client.post('/user_detail_change/?action=tabs-5',
                                    {'form-type': 'check-number',
                                     'phone_no': '9324552563'})
        self.assertTrue(response.context['check_phone_no_form'],
                        CheckPhoneNumberForm())
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
            'frontend/registration/user_detail_change.html')

        request = self.factory.get('/user_detail_change/')
        request.user = self.user
        request.session = {}
        response = customer_detail_change(request)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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))