Ejemplo n.º 1
0
def add_product_to_list(request, *args):
    try:
        collection = get_or_create_collection(request, args[0])
        p_id = int(args[0].get('product_id'))
        products_in_list = CollectionSetElement.objects.filter(
            object_id=p_id, type='product', set=collection).values('object_id')
        if {'object_id': p_id} not in products_in_list:
            item = CollectionSetElement(object_id=p_id,
                                        set=collection,
                                        type='product',
                                        style='',
                                        class_name='')
            item.save()
    except Exception, err:
        pass
Ejemplo n.º 2
0
def add_this_product(request, signed_request):

    parse_signed = parse_signed_request(signed_request)
    #Get values
    access_token = parse_signed['oauth_token']

    product_url = parse_signed['objects'][0]['url']
    exp = product_url.split('_')
    product_id = int(exp[len(exp) - 1].replace('/', ''))
    product = Product.objects.get(pk__exact=product_id)

    if request.is_secure():
        host = 'https://%s' % request.get_host()
    else:
        host = 'http://%s' % request.get_host()

    if request.user.is_authenticated():
        publish_product = publish_product_to_facebook_timeline(
            access_token, product, host)

        if 'id' in publish_product:
            #add this product to default list
            default_list = CollectionSet.objects.filter(user=request.user,
                                                        default=True)
            if len(default_list) > 0:
                default_list = default_list[0]
            else:
                default_list = CollectionSet(name='Default', user=request.user)
                default_list.save()
            list_item = CollectionSetElement(product=product, set=default_list)
            list_item.save()

            result = {"success": True}
        else:
            result = {"redirect": product_url}
    else:
        result = {"redirect": '%s/accounts/login/' % host}

    return HttpResponse(json.dumps(result))