Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Feature/upgrade django3.0 #26

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
111 changes: 111 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,14 +113,11 @@ 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.
```

## A note on the authors of this project

This project is a fork of django-cart which was originally started by Eric Woudenberg and followed up by Marc Garcia <http://vaig.be>, 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")
52 changes: 41 additions & 11 deletions changuito/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ),
},
),
]
38 changes: 23 additions & 15 deletions changuito/models.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,7 +15,10 @@


class Cart(models.Model):
user = models.ForeignKey(User, null=True, blank=True)
user = models.ForeignKey(User,
angvp marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand All @@ -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):
Expand All @@ -43,29 +46,33 @@ 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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, with an explicit related_name would be better.

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, with an explicit related_name would be better.

object_id = models.PositiveIntegerField()

objects = ItemManager()

class Meta:
verbose_name = _('item')
verbose_name_plural = _('items')
ordering = ('cart',)
ordering = ('cart', )
app_label = 'changuito'

def __unicode__(self):
Expand All @@ -75,15 +82,16 @@ def __unicode__(self):

def total_price(self):
return float(self.quantity) * float(self.unit_price)

total_price = property(total_price)

# product
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)
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions changuito/proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist

from . import models

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage
coveralls
flake8>=2.1.0
tox>=2.1.1
flake8
tox
pytest
pytest-django
6 changes: 3 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))


Expand Down
Loading