Skip to content

Commit

Permalink
hide pools without a club linking to it (#94)
Browse files Browse the repository at this point in the history
With this change pools referred to by no clubs (with a link such as `[[<pool short name>]]` in the club markdown) no longer appear to general page viewers or on the map. When logged into an account with edit access the pools appear on the place page, but still don't appear on the map. This reduces clutter of unused pools. Long term I'd like something like #92 to hold a large repository of pools separate from hockey tourist data.
  • Loading branch information
TomGoBravo authored Sep 16, 2023
1 parent 46e633f commit aebfc27
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
7 changes: 6 additions & 1 deletion tourist/models/tstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def center_geojson_feature(self) -> Dict:

@property
def _pool_geojson_features(self) -> List[Dict]:
return [p.entrance_geojson_feature for p in self.child_pools if p.entrance_geojson_feature]
return [p.entrance_geojson_feature
for p in self.child_pools if p.has_entrance_and_club_back_links]

@property
def children_or_center_geojson_features(self) -> List[Dict]:
Expand Down Expand Up @@ -372,6 +373,10 @@ def entrance_geojson_feature(self) -> Dict:
'geometry': shapely_mapping(to_shape(self.entrance)),
}

@property
def has_entrance_and_club_back_links(self) -> bool:
return bool(self.entrance_geojson_feature) and bool(self.club_back_links)

@property
def entrance_shapely(self):
return to_shape(self.entrance)
Expand Down
19 changes: 13 additions & 6 deletions tourist/render_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import enum
import io
import itertools
from collections import defaultdict
from typing import List, Mapping
from typing import Type
from typing import Union
Expand Down Expand Up @@ -156,9 +157,13 @@ def _build_place_recursive_names(orm_place: tstore.Place) \
-> render.PlaceRecursiveNames:
child_places = [_build_place_recursive_names(p) for p in orm_place.child_places]
child_clubs = [render.PlaceRecursiveNames.Club(c.name) for c in orm_place.child_clubs]
pools_with_links = list(p for p in orm_place.child_pools if bool(p.club_back_links))
pools_without_links = list(p for p in orm_place.child_pools if not bool(p.club_back_links))
child_pools = [render.PlaceRecursiveNames.Pool(p.name) for p in pools_with_links]
pool_by_has_links = defaultdict(list)
for p in orm_place.child_pools:
pool_by_has_links[bool(p.club_back_links)].append(p)
pools_with_links = pool_by_has_links[True]
pools_without_links = pool_by_has_links[False]
child_pools_with_club_back_links = [render.PlaceRecursiveNames.Pool(p.name) for p in
pools_with_links]
child_pools_without_club_back_links = [render.PlaceRecursiveNames.Pool(p.name) for p in
pools_without_links]
return render.PlaceRecursiveNames(
Expand All @@ -167,17 +172,19 @@ def _build_place_recursive_names(orm_place: tstore.Place) \
path=orm_place.path,
area=orm_place.area,
child_clubs=child_clubs,
child_pools=child_pools,
child_pools=child_pools_with_club_back_links,
child_pools_without_club_back_links=child_pools_without_club_back_links,
child_places=child_places,
comment_count=len(orm_place.comments),
)


def _build_geojson_feature_collection(all_places, all_pools):
geojson_features = [p.entrance_geojson_feature for p in all_pools if p.entrance_geojson_feature]
pools_for_geojson = [p for p in all_pools if p.has_entrance_and_club_back_links]
geojson_features = [p.entrance_geojson_feature for p in pools_for_geojson]
set_pools_for_geojson = set(pools_for_geojson)
for p in all_places:
if p.child_places or p.child_pools:
if p.child_places or len(set(p.child_pools).intersection(set_pools_for_geojson)):
continue
geojson_features.append(p.center_geojson_feature)
geojson_feature_collection = geojson.FeatureCollection(geojson_features)
Expand Down
2 changes: 2 additions & 0 deletions tourist/templates/place.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h3 id='{{ club.short_name }}'>
{% endfor %}

{% for pool in place.child_pools %}
{% if current_user.edit_granted or pool.club_back_links %}
<h3 id='{{ pool.short_name }}'>{{ pool.name }}
{% if current_user.edit_granted -%}
<a href="{{ url_for('pool.edit_view', id=pool.id) }}" title="Edit pool"></a>
Expand All @@ -79,6 +80,7 @@ <h3 id='{{ pool.short_name }}'>{{ pool.name }}
https://medium.com/@MRWwebDesign/responsive-images-the-sizes-attribute-and-unexpected-image-sizes-882a2eadb6db
#}<img style="vertical-align: middle" width=32 height=32 src="/static/logo_maps_color.32x32.png" title="Google Maps"></a>
{% else %}Please add pool location.{% endif %}
{% endif -%}
{% endfor %}
</div>

Expand Down
19 changes: 12 additions & 7 deletions tourist/tests/test_render_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_geojson(test_app):
country = tstore.Place(name='Country Name', short_name='cc', parent=world, region=polygon1,
markdown='')
metro_with_pool = tstore.Place(
name='Metro Name',
name='Metro With Pool',
short_name='metro_with_pool',
parent=country,
region=polygon1,
Expand All @@ -29,11 +29,16 @@ def test_geojson(test_app):
region=polygon1,
markdown='',
)
pool = tstore.Pool(name='Pool', short_name='poolnogeo', parent=metro_with_pool,
markdown='')
poolgeo = tstore.Pool(name='Metro Pool', short_name='poolgeo', parent=metro_with_pool,
markdown='', entrance=point1)
tstore.db.session.add_all([world, country, metro_with_pool, metro_no_pool, pool, poolgeo])
poolnogeo = tstore.Pool(name='Pool No Geo', short_name='poolnogeo', parent=metro_with_pool,
markdown='')
poolgeoref = tstore.Pool(name='Pool Geo Ref', short_name='poolgeoref',
parent=metro_with_pool, markdown='', entrance=point1)
poolgeonoref = tstore.Pool(name='Pool Geo NoRef', short_name='poolgeonoref',
parent=metro_with_pool, markdown='', entrance=point1)
club = tstore.Club(name='Our Club', short_name='our_club', parent=metro_with_pool,
markdown='plays at [[poolgeoref]]')
tstore.db.session.add_all([world, country, metro_with_pool, metro_no_pool, poolnogeo,
poolgeoref, poolgeonoref, club])
tstore.db.session.commit()
tourist.update_render_cache(tstore.db.session)

Expand All @@ -43,5 +48,5 @@ def test_geojson(test_app):

titles = set(f['properties']['title'] for f in collection['features'])
# Check that the collection contains the pool with geometry and metro without a pool.
assert titles == {'Metro Pool', 'Metro No Pool'}
assert titles == {'Pool Geo Ref', 'Metro No Pool'}

6 changes: 3 additions & 3 deletions tourist/tests/testentities.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{"type": "place", "name": "Australia", "short_name": "au", "parent_short_name": "world", "markdown": "[Official website of the Australian Underwater Hockey Commission](http://underwaterhockeyaustralia.org.au/)", "region": {"type": "Polygon", "coordinates": [[[152.386444, -44.199502], [152.386444, -10.159118], [114.141853, -10.159118], [114.141853, -44.199502], [152.386444, -44.199502]]]}}
{"type": "place", "name": "New South Wales", "short_name": "newsouthwales", "parent_short_name": "au", "region": {"type": "Polygon", "coordinates": [[[157.544697, -39.130212], [157.544697, -26.532088], [142.560026, -26.532088], [142.560026, -39.130212], [157.544697, -39.130212]]]}}
{"type": "place", "name": "Newcastle", "short_name": "newcastlenewsouthwales", "parent_short_name": "newsouthwales", "region": {"type": "Polygon", "coordinates": [[[151.825499, -33.103872], [151.825499, -32.874815], [151.552563, -32.874815], [151.552563, -33.103872], [151.825499, -33.103872]]]}}
{"type": "club", "name": "Newcastle Underwater Hockey Club (NUHU)", "short_name": "newcastle", "parent_short_name": "newcastlenewsouthwales", "markdown": "* Contact: Jason at [email protected] or 0415 674 522; Woody [email protected] or 0413174297\n* Practice: Thursday nights 6:30-7:15 induction, basic skills, team slection; 7:30-8:30 game(s) start prompty at [The Forum Aquatics Centre](/page/theforumaquaticscentrene), Newcastle University; email if you need to borrow any gear; cost is the pool $6 per game (expert instruction for the beginners free).\n", "status_comment": "Jason Beck updated pool cost", "status_date": "2013-07-01"}
{"type": "club", "name": "Newcastle Underwater Hockey Club (NUHU)", "short_name": "newcastle", "parent_short_name": "newcastlenewsouthwales", "markdown": "* Contact: Jason at [email protected] or 0415 674 522; Woody [email protected] or 0413174297\n* Practice: Thursday nights 6:30-7:15 induction, basic skills, team slection; 7:30-8:30 game(s) start prompty at [[theforumaquaticscentrene]], Newcastle University; email if you need to borrow any gear; cost is the pool $6 per game (expert instruction for the beginners free).\n", "status_comment": "Jason Beck updated pool cost", "status_date": "2013-07-01"}
{"type": "pool", "name": "The Forum Aquatics Centre", "short_name": "theforumaquaticscentrene", "parent_short_name": "newcastlenewsouthwales", "point": {"type": "Point", "coordinates": [151.707202, -32.888715]}}
{"type": "place", "name": "Ryde", "short_name": "rydenewsouthwales", "parent_short_name": "newsouthwales", "region": {"type": "Polygon", "coordinates": [[[151.157965, -33.839664], [151.157965, -33.763312], [151.066132, -33.763312], [151.066132, -33.839664], [151.157965, -33.839664]]]}}
{"type": "pool", "name": "Ryde Aquatic Centre", "short_name": "rydeaquaticcentrevictori", "parent_short_name": "rydenewsouthwales", "point": {"type": "Point", "coordinates": [151.118381, -33.821674]}}
{"type": "club", "name": "Sydney Starfish", "short_name": "sydneystarfish", "parent_short_name": "rydenewsouthwales", "markdown": "* <http://au.geocities.com/sydney_uwh/>\n* Contact: Doug Cuthill - 0407 921 633 (mob) [email protected]\n* Practice: Sunday afternoons 1:30 pm - 2:30 pm at [Ryde Aquatic Centre](/page/rydeaquaticcentrevictori), 504 Victoria Road, Ryde\n", "status_comment": "Sorry we have not updated our tourist page....change of personnel etc [email protected] 2006-08-09", "status_date": "2006-08-09"}
{"type": "club", "name": "Sydney Starfish", "short_name": "sydneystarfish", "parent_short_name": "rydenewsouthwales", "markdown": "* <http://au.geocities.com/sydney_uwh/>\n* Contact: Doug Cuthill - 0407 921 633 (mob) [email protected]\n* Practice: Sunday afternoons 1:30 pm - 2:30 pm at [[rydeaquaticcentrevictori]]\n", "status_comment": "Sorry we have not updated our tourist page....change of personnel etc [email protected] 2006-08-09", "status_date": "2006-08-09"}
{"type": "place", "name": "Wollongong", "short_name": "wollongongnewsouthwales", "parent_short_name": "newsouthwales", "region": {"type": "Polygon", "coordinates": [[[151.025724, -34.560379], [151.025724, -34.293146], [150.701924, -34.293146], [150.701924, -34.560379], [151.025724, -34.560379]]]}}
{"type": "club", "name": "Wollongong University Underwater Hockey Club", "short_name": "wollongonguniversity", "parent_short_name": "wollongongnewsouthwales", "markdown": "* Contact: Andy Davis at [email protected]\n* Practice: Tuesday nights, 19h30 - 21h00 at the [Wollongong University Aquatics Center](/page/wollongonguniversityaqua), Campus Ring Road. The pool is located on the University of Wollongong Campus behind building 13 and is accessed via the main entrance to building 13 - the University Recreation & Aquatic Centre\n", "status_comment": "[email protected] The only change I would suggest is removing \"Robson Road\" - the Aquatic Centre is actually on the Campus Ring Road", "status_date": "2006-08-10"}
{"type": "club", "name": "Wollongong University Underwater Hockey Club", "short_name": "wollongonguniversity", "parent_short_name": "wollongongnewsouthwales", "markdown": "* Contact: Andy Davis\n* Practice: Tuesday nights, 19h30 - 21h00 at the [[wollongonguniversityaqua]]. Also plays at [[wollongonguniversityaqua2]]\n", "status_comment": "[email protected] The only change I would suggest is removing \"Robson Road\" - the Aquatic Centre is actually on the Campus Ring Road", "status_date": "2006-08-10"}
{"type": "pool", "name": "Wollongong University Aquatics Center", "short_name": "wollongonguniversityaqua", "parent_short_name": "wollongongnewsouthwales", "point": {"type": "Point", "coordinates": [150.880834, -34.404785]}}
{"type": "pool", "name": "Wollongong University Aquatics Center 2", "short_name": "wollongonguniversityaqua2", "parent_short_name": "wollongongnewsouthwales", "point": {"type": "Point", "coordinates": [152.880834, -34.404785]}}

0 comments on commit aebfc27

Please sign in to comment.