Skip to content

Commit

Permalink
singular and plural on entry_list
Browse files Browse the repository at this point in the history
  • Loading branch information
rg3915 committed Jan 10, 2016
1 parent 5ea0b67 commit 2f1901a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 4 additions & 0 deletions core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def get_context_data(self, **kwargs):
context['count'] = self.get_queryset().count()
return context

def name_(self, singular='', plural=''):
name = self.singular if self.count == 1 else self.plural
return name


class FirstnameSearchMixin(object):

Expand Down
10 changes: 1 addition & 9 deletions core/templates/core/entry/entry_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ <h2><i class="fa fa-inbox"></i> Lista de Entradas </h2>

<hr>
<div>
{% if count > 0 %}
<h3><b>Total:</b> {{ count }}
{% if count == 1 %}
entrada
{% elif count > 1 %}
entradas
{% endif %}
</h3>
{% endif %}
<h3><b>Total:</b> {{ count }} {{ name }}</h3>
</div>

<!-- pagination -->
Expand Down
12 changes: 4 additions & 8 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ class EntryList(CounterMixin, ListView):
model = Entry
context_object_name = 'entrys'
paginate_by = 10

# def get_context_data(self, **kwargs):
# context = super(EntryList, self).get_context_data(**kwargs)
# context['urgente'] = Entry.objects.filter(priority='u')
# context['alta'] = Entry.objects.filter(priority='a')
# context['normal'] = Entry.objects.filter(priority='n')
# context['baixa'] = Entry.objects.filter(priority='b')
# return context
singular = 'entrada'
plural = 'entradas'

def get_context_data(self, **kwargs):
priority_classes = {'u': 'fa-flash urgente',
Expand All @@ -94,6 +88,8 @@ def get_context_data(self, **kwargs):
context.update({'priority_search_form': PrioritySearchForm(), })
context['priority'] = [(item, item_display, priority_classes[item])
for item, item_display in priority_list]
self.name = self.name_(EntryList.singular, EntryList.plural)
context['name'] = self.name
return context

def get_queryset(self):
Expand Down

0 comments on commit 2f1901a

Please sign in to comment.