Пример #1
0
def contact_change(request, object_id):
    """Update/Delete contact for the logged in user

    **Attributes**:

        * ``object_id`` - Selected contact object
        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Update/delete selected contact from the contact list
          via ContactForm & get redirected to the contact list
    """
    contact = get_object_or_404(Contact, pk=object_id, phonebook__user=request.user)

    form = ContactForm(request.user, instance=contact)
    if request.method == "POST":
        # Delete contact
        if request.POST.get("delete"):
            return HttpResponseRedirect("/contact/del/%s/" % object_id)
        else:
            # Update contact
            form = ContactForm(request.user, request.POST, instance=contact)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%s" is updated.') % request.POST["contact"]
                return HttpResponseRedirect("/contact/")

    template = "frontend/contact/change.html"
    data = {"form": form, "action": "update", "dialer_setting_msg": user_dialer_setting_msg(request.user)}
    return render_to_response(template, data, context_instance=RequestContext(request))
Пример #2
0
def contact_change(request, object_id):
    """Update/Delete contact for the logged in user

    **Attributes**:

        * ``object_id`` - Selected contact object
        * ``form`` - ContactForm
        * ``template`` - dialer_contact/contact/change.html

    **Logic Description**:

        * Update/delete selected contact from the contact list
          via ContactForm & get redirected to the contact list
    """
    contact = get_object_or_404(Contact, pk=object_id, phonebook__user=request.user)

    form = ContactForm(request.user, request.POST or None, instance=contact)
    if form.is_valid():
        # Delete contact
        if request.POST.get('delete'):
            return HttpResponseRedirect('%sdel/%s/' % (redirect_url_to_contact_list, object_id))
        else:
            # Update contact
            form.save()
            request.session["msg"] = _('"%s" is updated.') % request.POST['contact']
            return HttpResponseRedirect(redirect_url_to_contact_list)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('dialer_contact/contact/change.html', data, context_instance=RequestContext(request))
Пример #3
0
def contact_add(request):
    """Add a new contact into the selected phonebook for the logged in user

    **Attributes**:

        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Before adding a contact, check dialer setting limit if applicable
          to the user.
        * Add new contact belonging to the logged in user
          via ContactForm & get redirected to the contact list
    """
    # Check dialer setting limit
    if request.user and request.method == 'POST':
        # check  Max Number of subscriber per campaign
        if check_dialer_setting(request, check_for="contact"):
            request.session['msg'] = \
                _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s") % \
                {'limit': dialer_setting_limit(request, limit_for="contact")}

            # contact limit reached
            frontend_send_notification(request,
                                       NOTIFICATION_NAME.contact_limit_reached)
            return HttpResponseRedirect("/contact/")

    form = ContactForm(request.user)
    error_msg = False
    # Add contact
    if request.method == 'POST':
        form = ContactForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            request.session["msg"] = _(
                '"%s" is added.') % request.POST['contact']
            return HttpResponseRedirect('/contact/')
        else:
            if len(request.POST['contact']) > 0:
                error_msg = _(
                    '"%s" cannot be added.') % request.POST['contact']

    phonebook_count = Phonebook.objects.filter(user=request.user).count()
    template = 'frontend/contact/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'add',
        'error_msg': error_msg,
        'phonebook_count': phonebook_count,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Пример #4
0
def contact_add(request):
    """Add a new contact into the selected phonebook for the logged in user

    **Attributes**:

        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Before adding a contact, check dialer setting limit if applicable
          to the user.
        * Add new contact belonging to the logged in user
          via ContactForm & get redirected to the contact list
    """
    # Check dialer setting limit
    if request.user and request.method == 'POST':
        # check  Max Number of subscriber per campaign
        if check_dialer_setting(request, check_for="contact"):
            request.session['msg'] = \
                _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s") % \
                {'limit': dialer_setting_limit(request, limit_for="contact")}

            # contact limit reached
            frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached)
            return HttpResponseRedirect("/contact/")

    form = ContactForm(request.user)
    error_msg = False
    # Add contact
    if request.method == 'POST':
        form = ContactForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            request.session["msg"] = _('"%(name)s" added.') %\
                {'name': request.POST['contact']}
            return HttpResponseRedirect('/contact/')
        else:
            if len(request.POST['contact']) > 0:
                error_msg = _('"%(name)s" cannot be added.') %\
                    {'name': request.POST['contact']}

    phonebook_count = Phonebook.objects.filter(user=request.user).count()
    template = 'frontend/contact/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'add',
        'error_msg': error_msg,
        'phonebook_count': phonebook_count,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Пример #5
0
def contact_add(request):
    """Add a new contact into the selected phonebook for the logged in user

    **Attributes**:

        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Before adding a contact, check dialer setting limit if applicable
          to the user.
        * Add new contact belonging to the logged in user
          via ContactForm & get redirected to the contact list
    """
    # Check dialer setting limit
    if request.user and request.method == "POST":
        if check_dialer_setting(request, check_for="contact"):
            request.session["msg"] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % {
                "limit": dialer_setting_limit(request, limit_for="contact")
            }

            # contact limit reached
            frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached)
            return HttpResponseRedirect("/contact/")

    form = ContactForm(request.user)
    error_msg = False
    # Add contact
    if request.method == "POST":
        form = ContactForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            request.session["msg"] = _('"%s" is added.') % request.POST["contact"]
            return HttpResponseRedirect("/contact/")
        else:
            if len(request.POST["contact"]) > 0:
                error_msg = _('"%s" cannot be added.') % request.POST["contact"]

    phonebook_count = Phonebook.objects.filter(user=request.user).count()
    template = "frontend/contact/change.html"
    data = {
        "form": form,
        "action": "add",
        "error_msg": error_msg,
        "phonebook_count": phonebook_count,
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data, context_instance=RequestContext(request))
Пример #6
0
    def test_contact_form(self):
        self.assertEqual(self.contact.phonebook, self.phonebook)
        form = ContactForm(self.user)
        form.contact = '123456'
        obj = form.save(commit=False)
        obj.phonebook = self.phonebook
        obj.save()

        form = ContactForm(self.user, instance=self.contact)
        self.assertTrue(isinstance(form.instance, Contact))
Пример #7
0
    def test_contact_form(self):
        self.assertEqual(self.contact.phonebook, self.phonebook)
        form = ContactForm(self.user)
        form.contact = '123456'
        obj = form.save(commit=False)
        obj.phonebook = self.phonebook
        obj.save()

        form = ContactForm(self.user, instance=self.contact)
        self.assertTrue(isinstance(form.instance, Contact))
Пример #8
0
def contact_change(request, object_id):
    """Update/Delete contact for the logged in user

    **Attributes**:

        * ``object_id`` - Selected contact object
        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Update/delete selected contact from the contact list
          via ContactForm & get redirected to the contact list
    """
    contact = get_object_or_404(Contact,
                                pk=object_id,
                                phonebook__user=request.user)

    form = ContactForm(request.user, instance=contact)
    if request.method == 'POST':
        # Delete contact
        if request.POST.get('delete'):
            return HttpResponseRedirect('/contact/del/%s/' % object_id)
        else:
            # Update contact
            form = ContactForm(request.user, request.POST, instance=contact)
            if form.is_valid():
                form.save()
                request.session["msg"] = _(
                    '"%s" is updated.') % request.POST['contact']
                return HttpResponseRedirect('/contact/')

    template = 'frontend/contact/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'update',
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Пример #9
0
def contact_change(request, object_id):
    """Update/Delete contact for the logged in user

    **Attributes**:

        * ``object_id`` - Selected contact object
        * ``form`` - ContactForm
        * ``template`` - frontend/contact/change.html

    **Logic Description**:

        * Update/delete selected contact from the contact list
          via ContactForm & get redirected to the contact list
    """
    contact = get_object_or_404(
        Contact, pk=object_id, phonebook__user=request.user)

    form = ContactForm(request.user, instance=contact)
    if request.method == 'POST':
        # Delete contact
        if request.POST.get('delete'):
            contact_del(request, object_id)
            return HttpResponseRedirect('/contact/')
        else:
            # Update contact
            form = ContactForm(request.user, request.POST, instance=contact)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated.') \
                    % {'name': request.POST['contact']}
                return HttpResponseRedirect('/contact/')

    template = 'frontend/contact/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'update',
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Пример #10
0
def contact_add(request):
    """Add a new contact into the selected phonebook for the logged in user

    **Attributes**:

        * ``form`` - ContactForm
        * ``template`` - dialer_contact/contact/change.html

    **Logic Description**:

        * Before adding a contact, check dialer setting limit if applicable
          to the user.
        * Add new contact belonging to the logged in user
          via ContactForm & get redirected to the contact list
    """
    # Check dialer setting limit
    if request.user and request.method == 'POST':
        if check_dialer_setting(request, check_for="contact"):
            request.session['msg'] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % \
                {'limit': dialer_setting_limit(request, limit_for="contact")}

            # contact limit reached
            frontend_send_notification(request,
                                       NOTIFICATION_NAME.contact_limit_reached)
            return HttpResponseRedirect(redirect_url_to_contact_list)

    form = ContactForm(request.user, request.POST or None)
    # Add contact
    if form.is_valid():
        form.save()
        request.session["msg"] = _('"%s" is added.') % request.POST['contact']
        return HttpResponseRedirect(redirect_url_to_contact_list)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('dialer_contact/contact/change.html',
                              data,
                              context_instance=RequestContext(request))
Пример #11
0
def contact_add(request):
    """Add a new contact into the selected phonebook for the logged in user

    **Attributes**:

        * ``form`` - ContactForm
        * ``template`` - dialer_contact/contact/change.html

    **Logic Description**:

        * Before adding a contact, check dialer setting limit if applicable
          to the user.
        * Add new contact belonging to the logged in user
          via ContactForm & get redirected to the contact list
    """
    # Check dialer setting limit
    if request.user and request.method == 'POST':
        if check_dialer_setting(request, check_for="contact"):
            request.session['msg'] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % \
                {'limit': dialer_setting_limit(request, limit_for="contact")}

            # contact limit reached
            frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached)
            return HttpResponseRedirect(redirect_url_to_contact_list)

    form = ContactForm(request.user, request.POST or None)
    # Add contact
    if form.is_valid():
        form.save()
        request.session["msg"] = _('"%s" is added.') % request.POST['contact']
        return HttpResponseRedirect(redirect_url_to_contact_list)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('dialer_contact/contact/change.html', data, context_instance=RequestContext(request))
Пример #12
0
def contact_change(request, object_id):
    """Update/Delete contact for the logged in user

    **Attributes**:

        * ``object_id`` - Selected contact object
        * ``form`` - ContactForm
        * ``template`` - dialer_contact/contact/change.html

    **Logic Description**:

        * Update/delete selected contact from the contact list
          via ContactForm & get redirected to the contact list
    """
    contact = get_object_or_404(Contact,
                                pk=object_id,
                                phonebook__user=request.user)

    form = ContactForm(request.user, request.POST or None, instance=contact)
    if form.is_valid():
        # Delete contact
        if request.POST.get('delete'):
            return HttpResponseRedirect(
                '%sdel/%s/' % (redirect_url_to_contact_list, object_id))
        else:
            # Update contact
            form.save()
            request.session["msg"] = _(
                '"%s" is updated.') % request.POST['contact']
            return HttpResponseRedirect(redirect_url_to_contact_list)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('dialer_contact/contact/change.html',
                              data,
                              context_instance=RequestContext(request))