All posts All posts by this author Paper color Change page color Announcements

Newfies Dialer Bulk Contact Import Customization

Newfies-Dialer is a voice broadcast and SMS messaging platform that sends telephone calls and text messages at very high speed to help you grow and retain your customer base effectively.

Contact Import

Newfies-Dialer has builtin bulk contact import support. It allows importing contacts from csv file. But applies a strict fromating rule. And here comes the importance of customization.

Newfies-Dialer is a django application. So let's write a decorator function. The wrapper function must accept at least one argument HttpRequest object. Wrapper function checks HTTP request method. If gets HTTP POST request then do some calculation & if necessary returns HttpResponse.

def contact_import_decorator(view_func):

    @wraps(view_func, assigned=available_attrs(view_func))
    def wrapped_view(request, *args, **kwargs):

        if request.user and request.method == 'POST':

            # check for user permission
            if user_limit_over(user):
                # redirecting user to contact list page if dont have 
                # enough permission to add more contacts
                return HttpResponseRedirect(redirect_url_to_contact_list)

            # initializing form with POST data
            form = Contact_fileImport(request.user, request.POST or None,
                                      request.FILES or None)

            # form data validation
            if form.is_valid():

                # freedom to apply own logic
                data = add_contacts_to_db_from_parsed_data(
                    custom_csv_parser(request.FILES['csv_file'].file)
                )

                return render_to_response(
                    'dialer_contact/contact/import_contact.html',
                    data, context_instance=RequestContext(request)
                )

            # if form is not valid then let the main view function to 
            # handle the request. But dont forget to turn the request
            # method to HTTP GET from POST.
            request._post = QueryDict('')
            request._files = MultiValueDict()
            request.method = 'GET'

        # calling the default view function for HTTP GET request
        # or modified GET request.
        return view_func(request, *args, **kwargs)

    return wrapped_view

Import the decorator function in dialer_contact/views.py and decorate contact_import view function.

from custom_module import contact_import_decorator

@login_required
@contact_import_decorator
def contact_import(request):
    ....

Now got the freedom of writing custom_csv_parser and add_contacts_to_db_from_parsed_data function to meet the demand. Newfies-Dialer default contact_import view function also don't have any mechanism to prevent duplicate contact addition during import.

Software Solutions