Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
powellc committed Nov 30, 2011
0 parents commit 10f53f8
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include README
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Django Shop BulkForm plugin
============================

All this plugin does is give you access to a "bulk" order form that
lists all the products in your site with quantity boxes and adds
them to the cart on submission. Not rocket science.

It also may not work for every shop. If you have more than 25 or so
items, a page that lists them all could get unwieldy. But if you
only have a small number of items and want an easy view to let
people add multiple products at the same time, this is your plugin.
33 changes: 33 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from setuptools import setup, find_packages

setup(
name='django-shop-bulkform',
version=__import__('shop_bulkform').__version__,
license="BSD",

install_requires = [],

description='A bulk order form for a django-shop site.',
long_description=open('README').read(),

author='Colin Powell',
author_email='colin@onecardinal.com',

url='http://github.com/powellc/django-shop-bulkform',
download_url='http://github.com/powellc/django-shop-bulkform/downloads',

include_package_data=True,

packages=['shop_bulkform'],

zip_safe=True,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Framework :: Django',
]
)
Empty file added shop_bulkform/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions shop_bulkform/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Stub of models.py

7 changes: 7 additions & 0 deletions shop_bulkform/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#-*- coding: utf-8 -*-
from django.conf.urls.defaults import patterns, url
from shop_bulkorder.views import CartBulkView

urlpatterns = patterns('',
url(r'^order-form/$', CartBulkView.as_view(), name='shop_order_form'),
)
32 changes: 32 additions & 0 deletions shop_bulkform/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from shop.models.productmodel import Product
from shop.util.cart import get_or_create_cart
from django.views.generic import ListView
from datetime import date

class CartBulkView(ListView):
''' An addon view for django-shop to allow bulk adding to the cart. '''

model = Product
template_name='shop/order_bulk_form.html'
action=None

def post(self, *args, **kwargs):
"""
This is to *add* items in bulk to the cart. Optionally, you can pass it
quantity parameters to specify how many you wish to add at once (defaults
to 0)
"""
qty_field_prefix = 'add_item_quantity-'
qty_fields = [k for k in self.request.POST.keys()
if k.startswith(qty_field_prefix)]
cart_object = get_or_create_cart(self.request)

for key in qty_fields:
id = key[len(qty_field_prefix):]
product = Product.objects.get(pk=id)
if int(self.request.POST[key]) > 0:
cart_item = cart_object.add_product(product, int(self.request.POST[key]))
cart_object.save()
return HttpResponseRedirect(reverse('cart'))

0 comments on commit 10f53f8

Please sign in to comment.