diff --git a/.travis.yml b/.travis.yml index 6630d1a..47b4cc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,17 +2,14 @@ language: python sudo: false -env: - - TOX_ENV=py27-django1.7 - - TOX_ENV=py27-django1.8 - - TOX_ENV=py27-django1.9 - - TOX_ENV=py27-django1.10 - - TOX_ENV=py27-django1.11 - - TOX_ENV=py34-django1.7 - - TOX_ENV=py34-django1.8 - - TOX_ENV=py34-django1.9 - - TOX_ENV=py34-django1.10 - - TOX_ENV=py34-django1.11 +matrix: + include: + - env: TOX_ENV=py36-django3.0 + python: 3.6 + - env: TOX_ENV=py37-django3.0 + python: 3.7 + - env: TOX_ENV=py38-django3.0 + python: 3.8 install: - pip install tox coverage coveralls diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..6305e38 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,111 @@ +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +You can contribute in many ways: + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/angvp/django-changuito/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" +is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "feature" +is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +django-changuito could always use more documentation, whether as part of the +official django-changuito docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at https://github.com/angvp/django-changuito/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `django-changuito` for local development. + +1. Fork the `django-changuito` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/django-changuito.git + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: + + $ mkvirtualenv django-changuito + $ cd django-changuito/ + +4. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + +Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the +tests, including testing other Python versions with tox:: + + $ flake8 changuito tests + $ python setup.py test + $ tox + +To get flake8 and tox, just pip install them into your virtualenv. + +6. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website to the ``develop`` repo. + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality into a function with a docstring, and add the + feature to the list in README.rst. +3. The pull request should work for Python 2.7, and 3.4, and for PyPy. Check + https://travis-ci.org/angvp/django-changuito/pull_requests + and make sure that the tests pass for all supported Python versions. + +Tips +---- + +To run a subset of tests:: + + $ python -m unittest tests.test_changuito diff --git a/README.md b/README.md index 53c53d6..8537a10 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,14 @@ and make everything open source on a public repo and uploaded to PyPI. We are already using it on production and we want to encourage old users of django-cart or forked projects of django-cart to migrate to changuito instead. +This was upgrade to the newest Django version, codebase will partially upgraded +in order to support all the features that Django 3 / Python 3.6+ offers to us, +as usual PR are accepted :) see [CONTRIBUTING](https://github.com/angvp/CONTRIBUTING.rst). + ## Prerequisites -- Django 1.7, 1.8, 1.9, 1.10, 1.11 -- Python 2.7 and Python 3.4+ +- Django 3.0,3.1 +- Python 3.6+ - django content type framework in your INSTALLED_APPS ## Installation @@ -109,7 +113,7 @@ This is from the original project that I've forked, I just renamed the project s is not officialy dead and continued my work on this project ``` -This project was abandoned and I got it and added tests and South migrations, +This project was abandoned and I got it and added tests and migrations, and I will be maintaining it from now on. ``` @@ -117,6 +121,3 @@ and I will be maintaining it from now on. This project is a fork of django-cart which was originally started by Eric Woudenberg and followed up by Marc Garcia , and then continued by Bruno Carvalho, which adds a lot of stuff and then wasn't much aware of the status of the project. The last change ocurred in Jan 29 2012. Bruno and other authors added tests and cool stuff and we are thankful for that, and we will continue with that spirit. - - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/angvp/django-changuito/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/changuito/migrations/0001_initial.py b/changuito/migrations/0001_initial.py index 13e6576..1971ec0 100644 --- a/changuito/migrations/0001_initial.py +++ b/changuito/migrations/0001_initial.py @@ -16,31 +16,61 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Cart', fields=[ - ('id', models.AutoField(serialize=False, verbose_name='ID', primary_key=True, auto_created=True)), - ('creation_date', models.DateTimeField(verbose_name='creation date', default=django.utils.timezone.now)), - ('checked_out', models.BooleanField(verbose_name='checked out', default=False)), - ('user', models.ForeignKey(blank=True, null=True, to=settings.AUTH_USER_MODEL)), + ('id', + models.AutoField(serialize=False, + verbose_name='ID', + primary_key=True, + auto_created=True)), + ('creation_date', + models.DateTimeField(verbose_name='creation date', + default=django.utils.timezone.now)), + ('checked_out', + models.BooleanField(verbose_name='checked out', + default=False)), + ('user', + models.ForeignKey( + blank=True, + null=True, + to=settings.AUTH_USER_MODEL, + on_delete=django.db.models.deletion.CASCADE)), ], options={ 'verbose_name_plural': 'carts', 'verbose_name': 'cart', - 'ordering': ('-creation_date',), + 'ordering': ('-creation_date', ), }, ), migrations.CreateModel( name='Item', fields=[ - ('id', models.AutoField(serialize=False, verbose_name='ID', primary_key=True, auto_created=True)), - ('quantity', models.DecimalField(decimal_places=3, verbose_name='quantity', max_digits=18)), - ('unit_price', models.DecimalField(decimal_places=2, verbose_name='unit price', max_digits=18)), + ('id', + models.AutoField(serialize=False, + verbose_name='ID', + primary_key=True, + auto_created=True)), + ('quantity', + models.DecimalField(decimal_places=3, + verbose_name='quantity', + max_digits=18)), + ('unit_price', + models.DecimalField(decimal_places=2, + verbose_name='unit price', + max_digits=18)), ('object_id', models.PositiveIntegerField()), - ('cart', models.ForeignKey(verbose_name='cart', to='changuito.Cart')), - ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ('cart', + models.ForeignKey( + verbose_name='cart', + to='changuito.Cart', + on_delete=django.db.models.deletion.CASCADE)), + ('content_type', + models.ForeignKey( + to='contenttypes.ContentType', + on_delete=django.db.models.deletion.CASCADE)), ], options={ 'verbose_name_plural': 'items', 'verbose_name': 'item', - 'ordering': ('cart',), + 'ordering': ('cart', ), }, ), ] diff --git a/changuito/models.py b/changuito/models.py index 0155dc2..2961dc1 100644 --- a/changuito/models.py +++ b/changuito/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.contrib.contenttypes.models import ContentType try: @@ -15,7 +15,10 @@ class Cart(models.Model): - user = models.ForeignKey(User, null=True, blank=True) + user = models.ForeignKey(User, + null=True, + blank=True, + on_delete=models.CASCADE) creation_date = models.DateTimeField(verbose_name=_('creation date'), default=timezone.now) checked_out = models.BooleanField(default=False, @@ -24,7 +27,7 @@ class Cart(models.Model): class Meta: verbose_name = _('cart') verbose_name_plural = _('carts') - ordering = ('-creation_date',) + ordering = ('-creation_date', ) app_label = 'changuito' def __unicode__(self): @@ -43,21 +46,25 @@ def total_quantity(self): class ItemManager(models.Manager): def get(self, *args, **kwargs): if 'product' in kwargs: - kwargs['content_type'] = ContentType.objects.get_for_model(type(kwargs['product']), - for_concrete_model=False) + kwargs['content_type'] = ContentType.objects.get_for_model( + type(kwargs['product']), for_concrete_model=False) kwargs['object_id'] = kwargs['product'].pk - del(kwargs['product']) + del (kwargs['product']) return super(ItemManager, self).get(*args, **kwargs) class Item(models.Model): - cart = models.ForeignKey(Cart, verbose_name=_('cart')) - quantity = models.DecimalField(max_digits=18, decimal_places=3, + cart = models.ForeignKey(Cart, + verbose_name=_('cart'), + on_delete=models.CASCADE) + quantity = models.DecimalField(max_digits=18, + decimal_places=3, verbose_name=_('quantity')) - unit_price = models.DecimalField(max_digits=18, decimal_places=2, + unit_price = models.DecimalField(max_digits=18, + decimal_places=2, verbose_name=_('unit price')) # product as generic relation - content_type = models.ForeignKey(ContentType) + content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() objects = ItemManager() @@ -65,7 +72,7 @@ class Item(models.Model): class Meta: verbose_name = _('item') verbose_name_plural = _('items') - ordering = ('cart',) + ordering = ('cart', ) app_label = 'changuito' def __unicode__(self): @@ -75,6 +82,7 @@ def __unicode__(self): def total_price(self): return float(self.quantity) * float(self.unit_price) + total_price = property(total_price) # product @@ -82,8 +90,8 @@ def get_product(self): return self.content_type.get_object_for_this_type(pk=self.object_id) def set_product(self, product): - self.content_type = ContentType.objects.get_for_model(type(product), - for_concrete_model=False) + self.content_type = ContentType.objects.get_for_model( + type(product), for_concrete_model=False) self.object_id = product.pk product = property(get_product, set_product) @@ -97,8 +105,8 @@ def update_price(self, price): self.save() def update_contenttype(self, ctype_obj): - new_content_type = ContentType.objects.get_for_model(type(ctype_obj), - for_concrete_model=False) + new_content_type = ContentType.objects.get_for_model( + type(ctype_obj), for_concrete_model=False) # Let's search if the new contenttype had previous items on the cart try: new_items = Item.objects.get(cart=self.cart, diff --git a/changuito/proxy.py b/changuito/proxy.py index 95fdca2..1da13f3 100644 --- a/changuito/proxy.py +++ b/changuito/proxy.py @@ -1,4 +1,5 @@ from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ObjectDoesNotExist from . import models @@ -32,14 +33,14 @@ def __init__(self, request): user = request.user try: # First search by user - if not user.is_anonymous(): + if not user.is_anonymous: cart = models.Cart.objects.get(user=user, checked_out=False) # If not, search by request id else: user = None cart_id = request.session.get(CART_ID) cart = models.Cart.objects.get(id=cart_id, checked_out=False) - except: + except (ObjectDoesNotExist, models.Cart.DoesNotExist): cart = self.new(request, user=user) self.cart = cart diff --git a/requirements-test.txt b/requirements-test.txt index 7be4aa4..41b6bd8 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,6 @@ coverage coveralls -flake8>=2.1.0 -tox>=2.1.1 +flake8 +tox pytest pytest-django diff --git a/runtests.py b/runtests.py index 53831a9..fd60547 100644 --- a/runtests.py +++ b/runtests.py @@ -6,15 +6,15 @@ import os import subprocess - PYTEST_ARGS = { - 'default': ['tests', ], + 'default': [ + 'tests', + ], 'fast': ['tests', '-q'], } FLAKE8_ARGS = ['changuito', 'tests', '--ignore=E501'] - sys.path.append(os.path.dirname(__file__)) diff --git a/setup.py b/setup.py index 01c8980..a53af8f 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,15 @@ #!/usr/bin/env python -from setuptools import setup +from setuptools import setup, find_packages setup( name='django-changuito', - version='1.2', + version='2.0', description='A fork of django-cart with the same simplicity but updated', maintainer='Angel Velasquez', maintainer_email='angvp@archlinux.org', license="LGPL v3", url='https://github.com/angvp/django-changuito', - packages=['changuito'], + packages=find_packages(), classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", diff --git a/tests/test_models.py b/tests/test_models.py index 5e6fd23..698f471 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -27,26 +27,31 @@ def _create_item_in_db(self, product=None, quantity=2, unit_price=125): return item def test_cart_creation(self): - self.assertEquals(self.cart.id, 1) - self.assertEquals(self.cart.is_empty(), True, "Cart must be empty") + self.assertEqual(self.cart.id, 1) + self.assertEqual(self.cart.is_empty(), True, "Cart must be empty") def test_item_creation(self): item = self._create_item_in_db() item_in_cart = self.cart.item_set.all()[0] - self.assertEquals(item_in_cart, item, - "First item in cart should be equal the item we created") - self.assertEquals(self.cart.is_empty(), False) - self.assertEquals(item_in_cart.product, self.user, - "Product associated with the first item in cart should equal the user we're selling") - self.assertEquals(item_in_cart.unit_price, Decimal("125"), - "Unit price of the first item stored in the cart should equal 125") - self.assertEquals(item_in_cart.quantity, 2, - "The first item in cart should have 2 in it's quantity") + self.assertEqual( + item_in_cart, item, + "First item in cart should be equal the item we created") + self.assertEqual(self.cart.is_empty(), False) + self.assertEqual( + item_in_cart.product, self.user, + "Product associated with the first item in cart should equal the user we're selling" + ) + self.assertEqual( + item_in_cart.unit_price, Decimal("125"), + "Unit price of the first item stored in the cart should equal 125") + self.assertEqual( + item_in_cart.quantity, 2, + "The first item in cart should have 2 in it's quantity") def test_cart_total_price(self): self._create_item_in_db() self._create_item_in_db(unit_price=Decimal("100.00"), quantity=1) - self.assertEquals(self.cart.total_price(), 350, "Price == (125*2)+100") + self.assertEqual(self.cart.total_price(), 350, "Price == (125*2)+100") def test_cart_total_quantity(self): from django.contrib.sites.models import Site @@ -55,23 +60,22 @@ def test_cart_total_quantity(self): self._create_item_in_db(product=obj_site[0], unit_price=Decimal("100.00"), quantity=1) - self.assertEquals(self.cart.total_quantity(), 4) + self.assertEqual(self.cart.total_quantity(), 4) def test_cart_item_price(self): - item = self._create_item_in_db(quantity=4, - unit_price=Decimal("3.20")) - self.assertEquals(float(item.total_price), float("12.80")) + item = self._create_item_in_db(quantity=4, unit_price=Decimal("3.20")) + self.assertEqual(float(item.total_price), float("12.80")) def test_item_unicode(self): item = self._create_item_in_db() - self.assertEquals(item.__unicode__(), - "%s units of User %s" % (2, self.user.id)) + self.assertEqual(item.__unicode__(), + "%s units of User %s" % (2, self.user.id)) def test_item_update_quantity(self): item = self._create_item_in_db() - self.assertEquals(item.quantity, 2) + self.assertEqual(item.quantity, 2) item.update_quantity(7) - self.assertEquals(item.quantity, 7) + self.assertEqual(item.quantity, 7) def test_item_update_contenttype(self): # Let's import different contenttype objects @@ -89,15 +93,15 @@ def test_item_update_contenttype(self): quantity=2, unit_price=Decimal("100")) - self.assertEquals(item_user.content_type, ctype_user) - self.assertEquals(item_site.content_type, ctype_site) + self.assertEqual(item_user.content_type, ctype_user) + self.assertEqual(item_site.content_type, ctype_site) item_site.update_contenttype(obj_user) - self.assertEquals(item_site.quantity, 3) - self.assertEquals(item_site.total_price, 300) + self.assertEqual(item_site.quantity, 3) + self.assertEqual(item_site.total_price, 300) def test_item_update_price(self): item = self._create_item_in_db() item.update_price(137) - self.assertEquals(item.unit_price, 137) + self.assertEqual(item.unit_price, 137) diff --git a/tox.ini b/tox.ini index 0a3d520..e77a83a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] downloadcache = {toxworkdir}/_download/ -envlist = {py27,py34}-django{1.11,1.10,1.9,1.8,1.7} +envlist = {py36,py37,py38,py39}-django{3.0,3.1} [testenv] commands = @@ -9,8 +9,5 @@ setenv = PYTHONDONTWRITEBYTECODE=1 deps = -r{toxinidir}/requirements-test.txt - django1.11: Django<1.12 - django1.10: Django<1.11 - django1.9: Django<1.10 - django1.8: Django<1.9 - django1.7: Django<1.8 + django3.0: Django<3.1 + django3.1: Django<3.2