Пример #1
0
    def test_cdr_world_map(self):
        """Test Function to check world map"""
        response = self.client.get('/world_map/')
        self.assertTemplateUsed(response, 'frontend/world_map.html')
        self.assertTrue(response.context['form'], WorldForm())
        self.assertEqual(response.status_code, 200)

        request = self.factory.get('/world_map/')
        request.user = self.user
        request.session = {}
        response = world_map_view(request)
        self.assertEqual(response.status_code, 200)

        data = {
            'switch_id': 1,
            'from_date': datetime.now().strftime("%Y-%m-%d"),
            'to_date': datetime.now().strftime("%Y-%m-%d")
        }
        response = self.client.post('/world_map/', data)
        self.assertTrue(response.context['form'], WorldForm(data))
        self.assertEqual(response.status_code, 200)

        data = {'switch_id': -1, 'from_date': '', 'to_date': ''}
        request = self.factory.post('/world_map/', data)
        request.user = self.user
        request.session = {}
        response = world_map_view(request)
        self.assertEqual(response.status_code, 200)
        chk_account_code(request)
Пример #2
0
    def test_cdr_world_map(self):
        """Test Function to check world map"""
        response = self.client.get('/world_map/')
        self.assertTemplateUsed(response, 'frontend/world_map.html')
        self.assertTrue(response.context['form'], WorldForm())
        self.assertEqual(response.status_code, 200)

        request = self.factory.get('/world_map/')
        request.user = self.user
        request.session = {}
        response = world_map_view(request)
        self.assertEqual(response.status_code, 200)

        data = {'switch_id': 1,
                'from_date': datetime.now().strftime("%Y-%m-%d"),
                'to_date': datetime.now().strftime("%Y-%m-%d")}
        response = self.client.post('/world_map/', data)
        self.assertTrue(response.context['form'], WorldForm(data))
        self.assertEqual(response.status_code, 200)

        data = {'switch_id': -1,
                'from_date': '',
                'to_date': ''}
        request = self.factory.post('/world_map/', data)
        request.user = self.user
        request.session = {}
        response = world_map_view(request)
        self.assertEqual(response.status_code, 200)

        common_send_notification(request, 1, request.user)
        chk_account_code(request)
Пример #3
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm
        * ``template`` - 'cdr/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    if not request.user.is_superuser: # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect('/?acc_code_error=true')

    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)
    except:
        dialer_set = ''

    # Define no of records per page
    PAGE_SIZE = settings.PAGE_SIZE
    try:
        PAGE_NUMBER = int(request.GET['page'])
    except:
        PAGE_NUMBER = 1

    col_name_with_order = {}
    # default
    col_name_with_order['message'] = '-message'
    col_name_with_order['notice_type'] = '-notice_type'
    col_name_with_order['sender'] = '-sender'
    col_name_with_order['added'] = '-added'

    sort_field = variable_value(request, 'sort_by')
    if not sort_field:
        sort_field = 'message' # default sort field
        sort_order = '-' + sort_field # desc
    else:
        if "-" in sort_field:
            sort_order = sort_field
            col_name_with_order[sort_field] = sort_field[1:]
        else:
            sort_order = sort_field
            col_name_with_order[sort_field] = '-' + sort_field
    
    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)

    user_notification = user_notification.order_by(sort_order)

    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.')
        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 = 'cdr/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,
        'user_notification': user_notification,
        'PAGE_SIZE': PAGE_SIZE,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'msg_note': msg_note,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'notice_count': notice_count(request),
        'action': action,
        'col_name_with_order': col_name_with_order,
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Пример #4
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm
        * ``template`` - 'frontend/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change their details.
    """
    if not request.user.is_superuser:  # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect("/?acc_code_error=true")

    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)
        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)

    msg_detail = ""
    msg_pass = ""
    error_detail = ""
    error_pass = ""
    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():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _("Detail has been changed.")
            else:
                error_detail = _("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,
        "msg_detail": msg_detail,
        "msg_pass": msg_pass,
        "error_detail": error_detail,
        "error_pass": error_pass,
        "notice_count": notice_count(request),
        "action": action,
    }
    return render_to_response(template, data, context_instance=RequestContext(request))
Пример #5
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm
        * ``template`` - 'cdr/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    if not request.user.is_superuser:  # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect('/?acc_code_error=true')

    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)
    except:
        dialer_set = ''

    # Define no of records per page
    PAGE_SIZE = settings.PAGE_SIZE
    try:
        PAGE_NUMBER = int(request.GET['page'])
    except:
        PAGE_NUMBER = 1

    col_name_with_order = {}
    # default
    col_name_with_order['message'] = '-message'
    col_name_with_order['notice_type'] = '-notice_type'
    col_name_with_order['sender'] = '-sender'
    col_name_with_order['added'] = '-added'

    sort_field = variable_value(request, 'sort_by')
    if not sort_field:
        sort_field = 'message'  # default sort field
        sort_order = '-' + sort_field  # desc
    else:
        if "-" in sort_field:
            sort_order = sort_field
            col_name_with_order[sort_field] = sort_field[1:]
        else:
            sort_order = sort_field
            col_name_with_order[sort_field] = '-' + sort_field

    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)

    user_notification = user_notification.order_by(sort_order)

    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.')
        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 = 'cdr/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,
        'user_notification': user_notification,
        'PAGE_SIZE': PAGE_SIZE,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'msg_note': msg_note,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'notice_count': notice_count(request),
        'action': action,
        'col_name_with_order': col_name_with_order,
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Пример #6
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm
        * ``template`` - 'frontend/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change their details.
    """
    if not request.user.is_superuser:  # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect('/?acc_code_error=true')

    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)
        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)

    msg_detail = ''
    msg_pass = ''
    error_detail = ''
    error_pass = ''
    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():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _('Detail has been changed.')
            else:
                error_detail = _('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,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'notice_count': notice_count(request),
        'action': action,
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))