Skip to content

Commit

Permalink
use context processor to retrieve information about the kinds used to…
Browse files Browse the repository at this point in the history
… render the sidemenu
  • Loading branch information
dirtycoder committed Dec 23, 2017
1 parent 51c8178 commit ccca931
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 42 deletions.
9 changes: 8 additions & 1 deletion 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(),
}
Empty file.
14 changes: 0 additions & 14 deletions pets/meupet/templatetags/meupet_tags.py

This file was deleted.

13 changes: 11 additions & 2 deletions 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)
23 changes: 0 additions & 23 deletions pets/meupet/tests/test_template_tags.py

This file was deleted.

1 change: 1 addition & 0 deletions pets/pets/settings/prod.py
Expand Up @@ -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': [
Expand Down
23 changes: 21 additions & 2 deletions pets/templates/_layouts/base.html
@@ -1,4 +1,4 @@
{% load i18n static compress meupet_tags %}
{% load i18n static compress %}
<!DOCTYPE html>
<html>
<head lang="pt-br">
Expand Down Expand Up @@ -86,7 +86,26 @@ <h3 class="title-text text-center">{% block title %}{% endblock %}</h3>
{% endif %}

{% block body %}
{% sidemenu %}
<div class="col-md-2">
<div class="sidebar">
<h3 class="title-text">{% trans 'Missing' context 'plural' %}</h3>
<ul class="nav">
{% for kind in kind_lost %}
<li><a href="{% url 'meupet:lost' kind.slug %}">
{{ kind }} <span class="badge">{{ kind.num_pets }}</span></a>
</li>
{% endfor %}
</ul>
<h3 class="title-text">{% trans 'For Adoption' %}</h3>
<ul class="nav">
{% for kind in kind_adoption %}
<li><a href="{% url 'meupet:adoption' kind.slug %}">
{{ kind }} <span class="badge">{{ kind.num_pets }}</span></a>
</li>
{% endfor %}
</ul>
</div>
</div>

<div class="col-md-10">
{% block content %}
Expand Down

0 comments on commit ccca931

Please sign in to comment.