/
exportable.py
52 lines (47 loc) · 1.75 KB
/
exportable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django.core.exceptions import ObjectDoesNotExist
from import_export.fields import Field
from ..config.exportable import DeviceResource
class GeoDeviceResource(DeviceResource):
venue = Field(attribute='devicelocation__location__name', column_name='venue')
address = Field(
attribute='devicelocation__location__address', column_name='address'
)
coords = Field(attribute='devicelocation__location__geometry', column_name='coords')
is_mobile = Field(
attribute='devicelocation__location__is_mobile', column_name='is_mobile'
)
venue_type = Field(
attribute='devicelocation__location__type', column_name='venue_type'
)
floor = Field(attribute='devicelocation__floorplan__floor', column_name='floor')
floor_position = Field(
attribute='devicelocation__indoor', column_name='floor_position'
)
location_id = Field(
attribute='devicelocation__location_id', column_name='location_id'
)
floorplan_id = Field(
attribute='devicelocation__floorplan_id', column_name='floorplan_id'
)
def dehydrate_coords(self, device):
try:
return device.devicelocation.location.geometry.wkt
except ObjectDoesNotExist:
pass
class Meta(DeviceResource.Meta):
fields = DeviceResource.Meta.fields[:] # copy
# add geo fields after before last_ip
# fmt: off
fields[fields.index('last_ip'):fields.index('last_ip')] = [
'venue',
'address',
'coords',
'is_mobile',
'venue_type',
'floor',
'floor_position',
]
# fmt: on
# add id fields at the end
fields += ['location_id', 'floorplan_id']
export_order = fields