diff --git a/requirements/dev.txt b/requirements/dev.txt index ffad7ae..5c5ecb7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -3,7 +3,5 @@ flake8 mccabe pep8 -django-nose -nose +django_coverage_plugin coverage -pyflakes diff --git a/src/gwift/settings/__init__.py b/src/gwift/settings/__init__.py index c5fdfe2..9c4ab04 100644 --- a/src/gwift/settings/__init__.py +++ b/src/gwift/settings/__init__.py @@ -1,5 +1,5 @@ try: - from .local import * + from .local import * # NOQA except ImportError: # Dev env by defautl if no local file proviced - from .dev import * \ No newline at end of file + from .dev import * # NOQA diff --git a/src/gwift/settings/base.py b/src/gwift/settings/base.py index 36e8796..739c213 100644 --- a/src/gwift/settings/base.py +++ b/src/gwift/settings/base.py @@ -50,7 +50,7 @@ ROOT_URLCONF = 'gwift.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ 'templates' ], + 'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -65,8 +65,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'gwift.wsgi.application' - - # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ @@ -85,4 +83,3 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' - diff --git a/src/gwift/settings/dev.py b/src/gwift/settings/dev.py index 0ab3517..33637cc 100644 --- a/src/gwift/settings/dev.py +++ b/src/gwift/settings/dev.py @@ -1,4 +1,4 @@ -from .base import * +from .base import * # NOQA # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -8,7 +8,7 @@ SECRET_KEY = '5r4-zjux*_p7@^()pc+0sv(6rc@_vdjmce#!5!tx&qx7)opu$7' for template_engine in TEMPLATES: template_engine['OPTIONS']['debug'] = True - + '''INSTALLED_APPS += [ 'debug_toolbar', ]''' @@ -30,4 +30,4 @@ DATABASES = { STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), -] \ No newline at end of file +] diff --git a/src/gwift/settings/production.py b/src/gwift/settings/production.py index efd3cc8..5917768 100644 --- a/src/gwift/settings/production.py +++ b/src/gwift/settings/production.py @@ -1,4 +1,4 @@ -from .base import * +from .base import * # NOQA # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False @@ -26,4 +26,3 @@ CSRF_COOKIE_SECURE = True # Same for session cookie SESSION_COOKIE_SECURE = True - diff --git a/src/wish/admin.py b/src/wish/admin.py index 8c38f3f..ec52e6a 100644 --- a/src/wish/admin.py +++ b/src/wish/admin.py @@ -1,3 +1,8 @@ from django.contrib import admin +from .models import Wishlist, Wish, WishPart + # Register your models here. +admin.site.register(Wishlist) +admin.site.register(Wish) +admin.site.register(WishPart) diff --git a/src/wish/models.py b/src/wish/models.py index f7b54be..ca52c76 100644 --- a/src/wish/models.py +++ b/src/wish/models.py @@ -11,11 +11,13 @@ class AbstractModel(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) + class UnknownUser(models.Model): name = models.CharField(max_length=255) email = models.CharField(max_length=255, unique=True) + class Wishlist(AbstractModel): name = models.CharField(max_length=255) @@ -36,14 +38,14 @@ class Wish(AbstractModel): @property def percentage_of_completion(self): - """ - Calcule le pourcentage de complétion pour un élément. - """ + """Calcule le pourcentage de complétion pour un élément.""" + number_of_linked_parts = WishPart.objects.filter(wish=self).count() total = self.number_of_parts * self.numbers_available percentage = (number_of_linked_parts / total) return percentage * 100 + class WishPart(models.Model): wish = models.ForeignKey(Wish) diff --git a/src/wish/templatetags/tools.py b/src/wish/templatetags/tools.py index 1e47f70..f521e1a 100644 --- a/src/wish/templatetags/tools.py +++ b/src/wish/templatetags/tools.py @@ -1,19 +1,24 @@ # coding=utf-8 +import datetime + from django import template from wish.models import Wishlist register = template.Library() + @register.filter(is_safe=True) def add_xx(value): return '%sxx' % value + @register.simple_tag def current_time(format_string): return datetime.datetime.now().strftime(format_string) + @register.inclusion_tag('wish/templatetags/wishlists_list.html') def wishlists_list(): - return { 'list': Wishlist.objects.all() } + return {'list': Wishlist.objects.all()} diff --git a/src/wish/tests.py b/src/wish/tests.py index a0e9a7f..e5146ef 100644 --- a/src/wish/tests.py +++ b/src/wish/tests.py @@ -2,34 +2,35 @@ from django.test import TestCase from .models import Wishlist, Wish, WishPart + class TestWishModel(TestCase): def test_percentage_of_completion(self): """ - Vérifie que le pourcentage de complétion d'un souhait + Vérifie que le pourcentage de complétion d'un souhait est correctement calculé. """ - wishlist = Wishlist(name='Fake WishList', + wishlist = Wishlist(name='Fake WishList', description='This is a faked wishlist') wishlist.save() - - wish = Wish(wishlist=wishlist, - name='Fake Wish', + + wish = Wish(wishlist=wishlist, + name='Fake Wish', description='This is a faked wish', number_of_parts=4) wish.save() - + part1 = WishPart(wish=wish, comment='part1') part1.save() self.assertEqual(25, wish.percentage_of_completion) - + part2 = WishPart(wish=wish, comment='part2') part2.save() self.assertEqual(50, wish.percentage_of_completion) - + part3 = WishPart(wish=wish, comment='part3') part3.save() self.assertEqual(75, wish.percentage_of_completion) - + part4 = WishPart(wish=wish, comment='part4') part4.save() - self.assertEqual(100, wish.percentage_of_completion) \ No newline at end of file + self.assertEqual(100, wish.percentage_of_completion) diff --git a/src/wish/views.py b/src/wish/views.py index 2bba640..d1e287d 100644 --- a/src/wish/views.py +++ b/src/wish/views.py @@ -4,6 +4,7 @@ from django.views.generic import ListView from .models import Wishlist + class WishListList(ListView): context_object_name = 'wishlists' model = Wishlist diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c3ac1a4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 100 +exclude = migrations, manage.py +max-complexity = 6 +ignore = F405