Skip to content

Commit

Permalink
Fix Cadasta#674: Fix resource count on project dashboard (Cadasta#721)
Browse files Browse the repository at this point in the history
* Fix Cadasta#674: Fix resource count on project dashboard

* Resolve review feedback
  • Loading branch information
seav authored and manoramahp committed Sep 27, 2016
1 parent 04591a0 commit 15cf4ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion cadasta/organization/tests/test_views_default_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
from questionnaires.tests.factories import QuestionnaireFactory
from questionnaires.tests.utils import get_form
from questionnaires.models import Questionnaire
from resources.tests.factories import ResourceFactory
from resources.tests.utils import clear_temp # noqa
from resources.utils.io import ensure_dirs
from spatial.serializers import SpatialUnitGeoJsonSerializer
from spatial.tests.factories import SpatialUnitFactory
from party.tests.factories import PartyFactory

from .. import forms
from ..views import default
Expand Down Expand Up @@ -207,7 +211,7 @@ def setup_template_context(self):
'project': self.project,
'geojson': '{"type": "FeatureCollection", "features": []}',
'is_superuser': False,
'is_administrator': False
'is_administrator': False,
}

def setup_url_kwargs(self):
Expand Down Expand Up @@ -400,6 +404,24 @@ def test_get_archived_project_with_org_admin(self):
is_allowed_add_resource=True)
assert response.content == expected

def test_get_with_overview_stats(self):
su = SpatialUnitFactory.create(project=self.project)
PartyFactory.create(project=self.project)
ResourceFactory.create(project=self.project)
ResourceFactory.create(project=self.project, archived=True)
geojson = json.dumps(
SpatialUnitGeoJsonSerializer([su], many=True).data)
response = self.request(user=self.user)
assert response.status_code == 200
assert response.content == self.render_content(geojson=geojson,
has_content=True,
num_locations=1,
num_parties=1,
num_resources=1)
assert "<div class=\"num\">1</div> location" in response.content
assert "<div class=\"num\">1</div> party" in response.content
assert "<div class=\"num\">1</div> resource" in response.content


@pytest.mark.usefixtures('make_dirs')
class ProjectAddTest(UserTestCase, TestCase):
Expand Down
2 changes: 1 addition & 1 deletion cadasta/organization/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_context_data(self, **kwargs):
context = super(ProjectDashboard, self).get_context_data(**kwargs)
num_locations = self.object.spatial_units.count()
num_parties = self.object.parties.count()
num_resources = self.object.resource_set.count()
num_resources = self.object.resource_set.filter(archived=False).count()
context['has_content'] = (
num_locations > 0 or num_parties > 0 or num_resources > 0)
context['num_locations'] = num_locations
Expand Down

0 comments on commit 15cf4ff

Please sign in to comment.