Пример #1
0
def provision_inkling(first, last, email, title):

    product_id = get_product_id(title)
    data = {
        "email": email,
        "productId": product_id,
        "firstName": first,
        "lastName": last,
        "receiveEmail": True,
        "checkoutAmount": 1000,
        "partnerInfo": {
            "partnerSiteId": "...",
            "partnerPermaItemUrl": "...",
            "partnerTransactionId": "..."
        }
    }

    response_data = inkling_tools.post('/purchases', data)

    #MAKE A LOG ENTRY
    user_details = ''
    logging_details = ''
    success_or_fail = ''
    type = 'user purchase'
    if response_data['status']['statusCode'] == 'HTTPCreated':
        logging_details = 'Successfully Provisioned.'
        success_or_fail = 'success'
    elif response_data['status']['statusCode'] == 'DuplicatePurchase':
        logging_details = 'Duplicate purchase.'
        success_or_fail = 'fail'
    elif response_data['status']['statusCode'] == 'SchemaValidationError':
        logging_details = 'Missing one or more fields'
        success_or_fail = 'fail'
    else:
        logging_details = 'Connection error'
        success_or_fail = 'fail'

    new_log_entry = InklingTransaction(user_id=email,
                                       type=type,
                                       first_name=first,
                                       last_name=last,
                                       title=title,
                                       success_or_fail=success_or_fail,
                                       details=logging_details)
    new_log_entry.save()
Пример #2
0
def provision_inkling(first, last, email, title):

    product_id = get_product_id(title)
    data = {
         "email": email,
         "productId": product_id,
         "firstName": first,
         "lastName": last,
         "receiveEmail": True,
         "checkoutAmount": 1000,
         "partnerInfo": {
              "partnerSiteId": "...",
               "partnerPermaItemUrl": "...",
              "partnerTransactionId": "..."
         }
    }

    response_data = inkling_tools.post('/purchases', data)

    #MAKE A LOG ENTRY
    user_details = ''
    logging_details = ''
    success_or_fail = ''
    type = 'user purchase'
    if response_data['status']['statusCode'] == 'HTTPCreated':
         logging_details = 'Successfully Provisioned.'
         success_or_fail = 'success'
    elif response_data['status']['statusCode'] == 'DuplicatePurchase':
        logging_details = 'Duplicate purchase.'
        success_or_fail = 'fail'
    elif response_data['status']['statusCode'] == 'SchemaValidationError':
        logging_details = 'Missing one or more fields'
        success_or_fail = 'fail'
    else:
        logging_details = 'Connection error'
        success_or_fail = 'fail'

    new_log_entry = InklingTransaction(user_id=email, type=type, first_name=first, last_name=last,
                                        title=title, success_or_fail=success_or_fail, details=logging_details)
    new_log_entry.save()
Пример #3
0
def do_bulk_upload(request):
    context = RequestContext(request)

    product_list = Product.objects.all()
    if request.method == 'POST':
        user_data = []
        data = str(request.POST.get('data'))
        book_choice = request.POST.get('book_choice')

        product_id = get_product_id(book_choice)
        user_string = ','.join(data.split(',')[:])

        users = data.replace("\n", "").strip(" ").split(';')
        for person in users:
            if person != '':
                user = person.strip(" ").replace(" ", "").split(',')
                user_data.append(user)
        result_data = []
        for user in user_data:
            first_name = user[0]
            last_name = user[1]
            email = user[2]
            book_choice = 'PLACEHOLDER'

            data = {
                 "email": email,
                 "productId": product_id,
                 "firstName": first_name,
                 "lastName": last_name,
                 "receiveEmail": True,
                 "checkoutAmount": 1000,
                 "partnerInfo": {
                      "partnerSiteId": "...",
                       "partnerPermaItemUrl": "...",
                      "partnerTransactionId": "..."
                 }
            }

            response_data = inkling_tools.post('/purchases', data)

            user_details = ''
            logging_details = ''
            success_or_fail = ''
            type = 'bulk'
            if response_data['status']['statusCode'] == 'HTTPCreated':
                 logging_details = 'Successfully Provisioned.'
                 success_or_fail = 'success'
            elif response_data['status']['statusCode'] == 'DuplicatePurchase':
                logging_details = 'Duplicate purchase.'
                success_or_fail = 'fail'
            elif response_data['status']['statusCode'] == 'SchemaValidationError':
                logging_details = 'Missing one or more fields'
                success_or_fail = 'fail'
            else:
                logging_details = 'Connection error'
                success_or_fail = 'fail'

            new_log_entry = InklingTransaction(user_id=email, type=type, first_name=first_name, last_name=last_name,
                                                title=book_choice, success_or_fail=success_or_fail, details=logging_details)
            new_log_entry.save()

            result_display = {'user': email, 'first_name': first_name, 'last_name': last_name, 'details': logging_details}

            result_data.append(result_display)

        return HttpResponse(
            json.dumps(result_data),
            content_type="application/json"
        )

    def get_urls(self):
        urls = super(BulkUploadAdmin, self).get_urls()

        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)
        # my_urls = [
        #     url(r'^do_bulk_upload/$', self.do_bulk_upload, name='bulk upload'),
        # ]
        custom_urls = patterns('',
            url(r'^do_bulk_upload/$',
                 wrap(self.do_bulk_upload),
                 name='bulk',)
        )
        return custom_urls + urls
Пример #4
0
def pass_to_inkling(request):
    context = RequestContext(request)

    if request.method == 'POST':
        form = forms.UserInfoForm(request.POST)
        form_errors = form.errors.as_data()

        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        email = request.POST.get('cnm_email')
        book_choice = request.POST.get('book_choice')
        product_id = get_product_id(book_choice)

        data = {
             "email": email,
             "productId": product_id,
             "firstName": first_name,
             "lastName": last_name,
             "receiveEmail": True,
             "checkoutAmount": 1000,
             "partnerInfo": {
                 "partnerSiteId": "...",
                 "partnerPermaItemUrl": "...",
                 "partnerTransactionId": "..."
             }
        }

        titles = inkling_tools.get_list_of_titles()

        response_data = inkling_tools.post('/purchases', data)

        #TODO: ENCAPSULATE THIS
        user_details = ''
        logging_details = ''
        success_or_fail = ''
        type = 'customer'
        if response_data['status']['statusCode'] == 'HTTPCreated':
            user_details = 'Thank you for your purchase, {}. Your copy of {} has been provisioned. An email has been ' \
                           'sent to {} with instructions for accessing your book'.format(first_name, book_choice, email)
            logging_details = 'Successfully Provisioned.'
            success_or_fail = 'success'
        elif response_data['status']['statusCode'] == 'DuplicatePurchase':
            user_details = 'According to our records, you have already purchased this book. Contact blah blah blah ' \
                           'if you think this to be an error.'
            logging_details = 'Duplicate purchase.'
            success_or_fail = 'fail'
        elif response_data['status']['statusCode'] == 'SchemaValidationError':
            user_details = 'Please fill in all form fields'
            logging_details = 'Missing one or more fields'
            success_or_fail = 'fail'
        else:
            user_details = 'Connection error'
            logging_details = 'Connection error'
            success_or_fail = 'fail'

        if first_name != '' and last_name != '' and email != '':
            new_log_entry = InklingTransaction(user_id=email, type=type, first_name=first_name, last_name=last_name,
                                               title=book_choice, success_or_fail=success_or_fail, details=logging_details)
            new_log_entry.save()

        display_dict = {'user_details': user_details}
        response_data['display_dict'] = display_dict

        return HttpResponse(
            json.dumps(response_data),
            content_type="application/json"
        )
Пример #5
0
def pass_to_inkling(request):
    context = RequestContext(request)

    if request.method == 'POST':
        form = forms.UserInfoForm(request.POST)
        form_errors = form.errors.as_data()

        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        email = request.POST.get('cnm_email')
        book_choice = request.POST.get('book_choice')
        product_id = get_product_id(book_choice)

        data = {
            "email": email,
            "productId": product_id,
            "firstName": first_name,
            "lastName": last_name,
            "receiveEmail": True,
            "checkoutAmount": 1000,
            "partnerInfo": {
                "partnerSiteId": "...",
                "partnerPermaItemUrl": "...",
                "partnerTransactionId": "..."
            }
        }

        titles = inkling_tools.get_list_of_titles()

        response_data = inkling_tools.post('/purchases', data)

        #TODO: ENCAPSULATE THIS
        user_details = ''
        logging_details = ''
        success_or_fail = ''
        type = 'customer'
        if response_data['status']['statusCode'] == 'HTTPCreated':
            user_details = 'Thank you for your purchase, {}. Your copy of {} has been provisioned. An email has been ' \
                           'sent to {} with instructions for accessing your book'.format(first_name, book_choice, email)
            logging_details = 'Successfully Provisioned.'
            success_or_fail = 'success'
        elif response_data['status']['statusCode'] == 'DuplicatePurchase':
            user_details = 'According to our records, you have already purchased this book. Contact blah blah blah ' \
                           'if you think this to be an error.'
            logging_details = 'Duplicate purchase.'
            success_or_fail = 'fail'
        elif response_data['status']['statusCode'] == 'SchemaValidationError':
            user_details = 'Please fill in all form fields'
            logging_details = 'Missing one or more fields'
            success_or_fail = 'fail'
        else:
            user_details = 'Connection error'
            logging_details = 'Connection error'
            success_or_fail = 'fail'

        if first_name != '' and last_name != '' and email != '':
            new_log_entry = InklingTransaction(user_id=email,
                                               type=type,
                                               first_name=first_name,
                                               last_name=last_name,
                                               title=book_choice,
                                               success_or_fail=success_or_fail,
                                               details=logging_details)
            new_log_entry.save()

        display_dict = {'user_details': user_details}
        response_data['display_dict'] = display_dict

        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")