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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
c74aceba
Commit
c74aceba
authored
4 months ago
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
c3nav API export: use location_state and add 'is_preview' attribute
parent
76e155f6
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/tests/map.py
+2
-1
2 additions, 1 deletion
src/api/tests/map.py
src/api/views/maps.py
+15
-6
15 additions, 6 deletions
src/api/views/maps.py
with
17 additions
and
7 deletions
src/api/tests/map.py
+
2
−
1
View file @
c74aceba
...
...
@@ -49,6 +49,7 @@ class MapTest(TestCase):
# set POI on assembly and accept it
self
.
assembly
.
location_point
=
Point
(
8.9
,
52.9
)
self
.
assembly
.
location_state
=
Assembly
.
LocationState
.
ROUGH
self
.
assembly
.
state
=
Assembly
.
State
.
ACCEPTED
self
.
assembly
.
save
()
ConferenceExportCache
.
objects
.
all
().
delete
()
...
...
@@ -60,7 +61,7 @@ class MapTest(TestCase):
self
.
assertEqual
(
0
,
len
(
content
[
'
features
'
]))
# change state to 'placed', now there should be a POI
self
.
assembly
.
state
=
Assembly
.
State
.
PLACED
self
.
assembly
.
location_
state
=
Assembly
.
LocationState
.
FINAL
self
.
assembly
.
save
()
ConferenceExportCache
.
objects
.
all
().
delete
()
resp
=
self
.
client
.
get
(
url
)
...
...
This diff is collapsed.
Click to expand it.
src/api/views/maps.py
+
15
−
6
View file @
c74aceba
...
...
@@ -5,9 +5,10 @@ from rest_framework.response import Response
from
rest_framework.views
import
APIView
from
django.contrib.gis.gdal
import
CoordTransform
,
SpatialReference
from
django.db.models
import
Q
,
QuerySet
from
core.models.assemblies
import
Assembly
from
core.models.conference
import
ConferenceExportCache
from
core.models.conference
import
Conference
,
ConferenceExportCache
from
core.models.map
import
MapPOI
from
api.permissions
import
IsConferenceService
,
IsSuperUser
...
...
@@ -16,6 +17,13 @@ from api.views.mixins import ConferenceSlugMixin
_cts
=
{}
# cache of CoordTransforms (if needed)
def
get_exportable_assemblies
(
conference
:
Conference
)
->
QuerySet
[
Assembly
]:
"""
Fetches all assemblies in the given conference with publish-able location.
"""
exportable_states
=
[
*
Assembly
.
PUBLIC_STATES
,
Assembly
.
State
.
HIDDEN
]
q_placed_assemblies
=
Q
(
location_state__in
=
[
Assembly
.
LocationState
.
PREVIEW
,
Assembly
.
LocationState
.
FINAL
])
return
Assembly
.
objects
.
filter
(
conference
=
conference
,
state__in
=
exportable_states
).
filter
(
q_placed_assemblies
)
def
get_field_geojson
(
value
,
srid
:
int
,
ct_cache
:
dict
|
None
=
None
):
if
value
.
srid
!=
srid
:
if
ct_cache
is
None
:
...
...
@@ -70,8 +78,7 @@ class AssembliesExportView(ConferenceSlugMixin, APIView, metaclass=abc.ABCMeta):
geometry_field
=
None
def
get_queryset
(
self
):
exportable_states
=
[
*
Assembly
.
PLACED_STATES
,
Assembly
.
State
.
HIDDEN
]
return
Assembly
.
objects
.
filter
(
conference
=
self
.
conference
,
state__in
=
exportable_states
)
return
get_exportable_assemblies
(
conference
=
self
.
conference
)
def
get_geometry_field
(
self
,
obj
):
return
getattr
(
obj
,
self
.
geometry_field
)
...
...
@@ -137,8 +144,7 @@ class C3NavExportView(ConferenceSlugMixin, APIView):
data
=
[]
exportable_states
=
[
*
Assembly
.
PLACED_STATES
,
Assembly
.
State
.
HIDDEN
]
qs
=
self
.
conference
.
assemblies
.
filter
(
state__in
=
exportable_states
)
qs
=
get_exportable_assemblies
(
self
.
conference
)
if
request
.
GET
.
get
(
'
all
'
)
!=
'
1
'
:
qs
=
qs
.
exclude
(
location_data__point
=
None
,
location_data__boundaries
=
None
)
for
assembly
in
qs
.
all
():
# type: Assembly
...
...
@@ -153,8 +159,11 @@ class C3NavExportView(ConferenceSlugMixin, APIView):
'
description
'
:
{
'
de
'
:
assembly
.
description_de
,
'
en
'
:
assembly
.
description_en
},
'
public_url
'
:
hub_absolute
(
'
plainui:assembly
'
,
assembly_slug
=
assembly
.
slug
),
'
parent_id
'
:
assembly
.
parent_id
,
'
children
'
:
assembly
.
children
.
filter
(
state__in
=
exportable_states
).
values_list
(
'
slug
'
,
flat
=
True
)
if
assembly
.
is_cluster
else
None
,
'
children
'
:
get_exportable_assemblies
(
conference
=
self
.
conference
).
filter
(
parent
=
assembly
).
values_list
(
'
slug
'
,
flat
=
True
)
if
assembly
.
is_cluster
else
None
,
'
floor
'
:
assembly
.
get_location_floor_index
(),
'
is_preview
'
:
assembly
.
location_state
!=
Assembly
.
LocationState
.
FINAL
,
'
location
'
:
loc_data
.
get
(
'
point
'
),
# assembly.get_location_point_xy(),
'
polygons
'
:
loc_data
.
get
(
'
boundaries
'
),
# assembly.get_location_boundaries_xy(),
}
...
...
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