Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
c7cfe697
Commit
c7cfe697
authored
Jul 27, 2023
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
api: GeoJSON export for placed assemblies
parent
8f1b16ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/api/urls.py
+3
-1
3 additions, 1 deletion
src/api/urls.py
src/api/views/maps.py
+81
-0
81 additions, 0 deletions
src/api/views/maps.py
with
84 additions
and
1 deletion
src/api/urls.py
+
3
−
1
View file @
c7cfe697
...
@@ -3,7 +3,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
...
@@ -3,7 +3,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
from
rest_framework.authtoken
import
views
as
authtoken_views
from
rest_framework.authtoken
import
views
as
authtoken_views
from
.views
import
api_root
from
.views
import
api_root
from
.views
import
assemblies
,
badges
,
bbb
,
conferencemember
,
conferences
,
events
,
rooms
,
schedule
,
users
,
workadventure
from
.views
import
assemblies
,
badges
,
bbb
,
conferencemember
,
conferences
,
events
,
maps
,
rooms
,
schedule
,
users
,
workadventure
app_name
=
'
api
'
app_name
=
'
api
'
...
@@ -29,6 +29,8 @@ urlpatterns = [
...
@@ -29,6 +29,8 @@ urlpatterns = [
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/rooms
'
,
assemblies
.
ConferenceAssemblyRoomList
.
as_view
(),
name
=
'
assembly-rooms
'
),
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/rooms
'
,
assemblies
.
ConferenceAssemblyRoomList
.
as_view
(),
name
=
'
assembly-rooms
'
),
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/schedule
'
,
schedule
.
AssemblySchedule
.
as_view
(),
name
=
'
assembly-schedule
'
),
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/schedule
'
,
schedule
.
AssemblySchedule
.
as_view
(),
name
=
'
assembly-schedule
'
),
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/badges/new_redeem_token
'
,
badges
.
create_redeem_token
,
name
=
'
create-badge-redeem
'
),
path
(
'
c/<slug:conference>/assembly/<slug:assembly>/badges/new_redeem_token
'
,
badges
.
create_redeem_token
,
name
=
'
create-badge-redeem
'
),
path
(
'
c/<slug:conference>/map/assemblies/poi.json
'
,
maps
.
AssembliesPoiExportView
.
as_view
(),
name
=
'
map-assemblies-poi
'
),
path
(
'
c/<slug:conference>/map/assemblies/areas.json
'
,
maps
.
AssembliesAreasExportView
.
as_view
(),
name
=
'
map-assemblies-areas
'
),
path
(
'
c/<slug:conference>/badges/redeem_token
'
,
badges
.
redeem_badge_token
,
name
=
'
badge-redeem
'
),
path
(
'
c/<slug:conference>/badges/redeem_token
'
,
badges
.
redeem_badge_token
,
name
=
'
badge-redeem
'
),
path
(
'
c/<slug:conference>/badges/redeem_map_token
'
,
badges
.
RedeemBadgeMapTokenView
.
as_view
(),
name
=
'
badge-map-redeem
'
),
path
(
'
c/<slug:conference>/badges/redeem_map_token
'
,
badges
.
RedeemBadgeMapTokenView
.
as_view
(),
name
=
'
badge-map-redeem
'
),
path
(
'
c/<slug:conference>/rooms
'
,
rooms
.
ConferenceRoomList
.
as_view
(),
name
=
'
room-list
'
),
path
(
'
c/<slug:conference>/rooms
'
,
rooms
.
ConferenceRoomList
.
as_view
(),
name
=
'
room-list
'
),
...
...
This diff is collapsed.
Click to expand it.
src/api/views/maps.py
0 → 100644
+
81
−
0
View file @
c7cfe697
import
abc
import
json
from
django.contrib.gis.gdal
import
SpatialReference
,
CoordTransform
from
rest_framework.views
import
APIView
from
core.models.assemblies
import
Assembly
from
core.models.conference
import
ConferenceExportCache
from
.mixins
import
ConferenceSlugMixin
class
AssembliesExportView
(
ConferenceSlugMixin
,
APIView
,
metaclass
=
abc
.
ABCMeta
):
geometry_field
=
None
_cts
=
{}
# cache of CoordTransforms (if needed)
def
get_queryset
(
self
):
return
Assembly
.
objects
.
filter
(
conference
=
self
.
conference
,
state_assembly__in
=
Assembly
.
PLACED_STATES
)
@staticmethod
def
get_field_geojson
(
value
,
srid
:
int
,
ct_cache
:
dict
=
None
):
if
value
.
srid
!=
srid
:
if
ct_cache
is
None
:
ct_cache
=
{}
if
value
.
srid
not
in
ct_cache
:
srs
=
SpatialReference
(
srid
)
ct_cache
[
value
.
srid
]
=
CoordTransform
(
value
.
srs
,
srs
)
value
.
transform
(
ct_cache
[
value
.
srid
])
return
json
.
loads
(
value
.
geojson
)
def
get_geometry_field
(
self
,
obj
):
return
getattr
(
obj
,
self
.
geometry_field
)
def
get_geojson
(
self
):
srid
=
4326
# RFC7946 mandates WGS84
ct_cache
=
{}
features
=
[]
result
=
{
'
type
'
:
'
FeatureCollection
'
,
# 'crs': {'type': 'name', 'properties': {'name': f'EPSG:{srid}'}}, # deprecated, not in RFC7946
'
features
'
:
features
,
}
for
assembly
in
self
.
get_queryset
().
prefetch_related
(
'
parent
'
).
all
():
geometry
=
self
.
get_geometry_field
(
assembly
)
if
geometry
is
None
:
continue
feature
=
{
'
type
'
:
'
Feature
'
,
'
id
'
:
assembly
.
slug
,
'
geometry
'
:
self
.
get_field_geojson
(
geometry
,
srid
=
srid
,
ct_cache
=
ct_cache
),
'
properties
'
:
{
'
name
'
:
assembly
.
name
,
'
official
'
:
assembly
.
is_official
,
'
cluster
'
:
assembly
.
is_cluster
,
'
parent
'
:
assembly
.
parent
.
slug
if
assembly
.
parent
else
None
,
},
}
features
.
append
(
feature
)
return
result
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
cache_id
=
'
geojson-
'
+
self
.
geometry_field
return
ConferenceExportCache
.
handle_http_request
(
request
=
request
,
conference
=
self
.
conference
,
type
=
ConferenceExportCache
.
Type
.
MAP
,
ident
=
cache_id
,
content_type
=
'
application/geo+json
'
,
result_func
=
lambda
:
json
.
dumps
(
self
.
get_geojson
()),
)
class
AssembliesPoiExportView
(
AssembliesExportView
):
geometry_field
=
'
location_point
'
class
AssembliesAreasExportView
(
AssembliesExportView
):
geometry_field
=
'
location_boundaries
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment