diff --git a/pets/meupet/context_processors.py b/pets/meupet/context_processors.py index 80f1f96..fb22ef7 100644 --- a/pets/meupet/context_processors.py +++ b/pets/meupet/context_processors.py @@ -1,7 +1,14 @@ -from .models import Pet +from .models import Kind, Pet def pets_count(request): return { 'pets_count': Pet.objects.count(), } + + +def kinds_count(request): + return { + 'kind_lost': Kind.objects.lost_kinds(), + 'kind_adoption': Kind.objects.adoption_kinds(), + } diff --git a/pets/meupet/templatetags/__init__.py b/pets/meupet/templatetags/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pets/meupet/templatetags/meupet_tags.py b/pets/meupet/templatetags/meupet_tags.py deleted file mode 100644 index d585930..0000000 --- a/pets/meupet/templatetags/meupet_tags.py +++ /dev/null @@ -1,14 +0,0 @@ -from django import template -from django.template.loader import render_to_string - -from meupet.models import Kind - -register = template.Library() - - -@register.simple_tag() -def sidemenu(): - return render_to_string('meupet/_sidemenu.html', { - 'kind_lost': Kind.objects.lost_kinds(), - 'kind_adoption': Kind.objects.adoption_kinds(), - }) diff --git a/pets/meupet/tests/test_context_processors.py b/pets/meupet/tests/test_context_processors.py index 9c558ef..72e48b5 100644 --- a/pets/meupet/tests/test_context_processors.py +++ b/pets/meupet/tests/test_context_processors.py @@ -1,16 +1,25 @@ from django.test import TestCase from model_mommy import mommy -from meupet.context_processors import pets_count +from meupet.context_processors import pets_count, kinds_count from meupet.models import Pet class ContextProcessorsTestCase(TestCase): def setUp(self): - mommy.make(Pet) + mommy.make(Pet, kind__kind='Dog', status=Pet.ADOPTED) mommy.make(Pet, active=False) def test_pets_count(self): context = pets_count({}) self.assertEqual(2, context['pets_count']) + + def test_kind_count(self): + context = kinds_count({}) + + adoption_count = context['kind_adoption'].first().num_pets + + self.assertIn('kind_lost', context) + self.assertIn('kind_adoption', context) + self.assertEqual(adoption_count, 1) diff --git a/pets/meupet/tests/test_template_tags.py b/pets/meupet/tests/test_template_tags.py deleted file mode 100644 index cd71ee9..0000000 --- a/pets/meupet/tests/test_template_tags.py +++ /dev/null @@ -1,23 +0,0 @@ -from django.template import Template, Context -from django.test import TestCase - -from model_mommy import mommy - -from meupet.models import Pet, Kind - - -class TestTemplateTag(TestCase): - def setUp(self): - dog = Kind.objects.create(kind='Dog') - cat = Kind.objects.create(kind='Cat') - mommy.make(Pet, kind=dog, status=Pet.MISSING) - mommy.make(Pet, kind=cat, status=Pet.FOR_ADOPTION) - - def test_render_menu(self): - template = Template('{% load meupet_tags %}{% sidemenu %}') - content = template.render(Context()) - - self.assertIn('Dog 1', content) - self.assertIn('Cat 1', content) - self.assertIn('Missing', content) - self.assertIn('For Adoption', content) diff --git a/pets/pets/settings/prod.py b/pets/pets/settings/prod.py index 8a5a9a2..80cdb59 100644 --- a/pets/pets/settings/prod.py +++ b/pets/pets/settings/prod.py @@ -89,6 +89,7 @@ 'social_django.context_processors.backends', 'social_django.context_processors.login_redirect', 'meupet.context_processors.pets_count', + 'meupet.context_processors.kinds_count', 'users.context_processors.users_count', ], 'loaders': [ diff --git a/pets/templates/_layouts/base.html b/pets/templates/_layouts/base.html index 5db699b..be7309e 100644 --- a/pets/templates/_layouts/base.html +++ b/pets/templates/_layouts/base.html @@ -1,4 +1,4 @@ -{% load i18n static compress meupet_tags %} +{% load i18n static compress %} @@ -86,7 +86,26 @@

{% block title %}{% endblock %}

{% endif %} {% block body %} - {% sidemenu %} +
+ +
{% block content %}