This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-opdp.py
executable file
·174 lines (145 loc) · 7.33 KB
/
load-opdp.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
import argparse
import os
import sys
from datetime import datetime, timezone
import django
sys.path.append('../cadasta')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
def load_opdp():
"""Load OPDP data."""
from organization.models import Organization, Project
from party.models import Party, TenureRelationship, TenureRelationshipType
from spatial.models import SpatialUnit
org = Organization.objects.create(
name='OPDP', slug='opdp',
description='',
urls=[''],
logo='https://s3.amazonaws.com/cadasta-dev-tmp/etl-test/opdp.jpg',
contacts=[]
)
proj1 = Project.objects.create(
organization=org,
name='Community Mapping',
slug='community-mapping',
description="""Community mapping of natural resources and physical features.""",
country='KE',
extent=("""SRID=4326;POLYGON ((33.7939453125 -5.00339434502215, 33.7939453125 5.003394345022162, 41.87988281249999 5.003394345022162, 41.87988281249999 -5.00339434502215, 33.7939453125 -5.00339434502215))""")
)
su1 = SpatialUnit.objects.create(
geometry=("""SRID=4326;POLYGON((35.5478096008301 0.0873112340607699,35.5483245849609 0.0850796386858006,35.5521011352539 0.0845646551192806,35.555362701416 0.0842213327378052,35.559139251709 0.0850796386858006,35.562744140625 0.0849079774977155,35.5660057067871 0.0852512998731224,35.5673789978027 0.086452928162811,35.5660057067871 0.0876545564144855,35.5639457702637 0.0883412011124513,35.562572479248 0.0893711681355713,35.559139251709 0.0928043913355374,35.5569076538086 0.0929760524868935,35.5543327331543 0.0924610690303317,35.5527877807617 0.0922894078764947,35.5510711669922 0.0898861516363302,35.5478096008301 0.0873112340607699))"""),
project=proj1,
type='PA')
p1 = Party.objects.create(
name="Koibatek",
type="GR",
project=proj1
)
proj2 = Project.objects.create(
organization=org,
name='Mapping Infrastructure Sasimwani',
slug='mapping-infrastructure-sasimwani',
description="""Mapping of man-made features found in the community, e.g., roads, schools, churches etc.""",
country='KE',
extent=('SRID=4326;'
"""POLYGON ((34.9200439453125 -1.2138984340943106, 34.9200439453125 0.05493163220967156, 36.6339111328125 0.05493163220967156, 36.6339111328125 -1.2138984340943106, 34.9200439453125 -1.2138984340943106))""")
)
su1 = SpatialUnit.objects.create(
geometry=("""SRID=4326;POINT(35.8236694335938 -0.748422319076921)"""),
project=proj2,
type='PA')
su2 = SpatialUnit.objects.create(
geometry=("""SRID=4326;LINESTRING(35.848388671875 -0.777730899383458,35.8514785766602 -0.76914861255639,35.8531951904297 -0.759879723404385,35.8538818359375 -0.752670573635443,35.8645248413086 -0.732759527000417,35.8641815185547 -0.7221173794242,35.8617782592773 -0.712161799452128,35.859375 -0.705982463117918,35.8600616455078 -0.699803118571605,35.8624649047852 -0.695340253554815,35.8617782592773 -0.689504192940443,35.8604049682617 -0.682981528496451,35.8604049682617 -0.675085659702511,35.8600616455078 -0.667533077552432)"""),
project=proj2,
type='RW')
p1 = Party.objects.create(
name="Sasimwani",
type="GR",
project=proj2
)
proj3 = Project.objects.create(
organization=org,
name='Mapping Natural Resource Rights',
slug='mapping-natural-resource-rights',
description="""Mapping forests, water sources, stones, grazing areas, pasture, gathering areas, boundaries, landmarks.""",
country='KE',
extent=("""SRID=4326;POLYGON ((35.4638671875 -0.46966026762837204, 35.4638671875 0.12084951976866681, 36.1724853515625 0.12084951976866681, 36.1724853515625 -0.46966026762837204, 35.4638671875 -0.46966026762837204))""")
)
su1 = SpatialUnit.objects.create(
geometry=("""SRID=4326;POLYGON((35.8353424072266 -0.372631307105529,35.8463287353516 -0.370571413906517,35.8573150634766 -0.364391731446192,35.8628082275391 -0.36267515222965,35.877571105957 -0.357525412632875,35.8871841430664 -0.352375670147851,35.8930206298828 -0.345852658918886,35.8889007568359 -0.333836573929815,35.8858108520508 -0.324223695341298,35.8731079101562 -0.323880378078442,35.8617782592773 -0.323537060803958,35.8477020263672 -0.325253647059945,35.841178894043 -0.321820474257548,35.8329391479492 -0.317014030395739,35.8205795288086 -0.316670712891275,35.8137130737305 -0.313924172447233,35.8119964599609 -0.325596964276162,35.8353424072266 -0.372631307105529))"""),
project=proj3,
type='CB')
su2 = SpatialUnit.objects.create(
geometry=("""SRID=4326;LINESTRING(35.8246994018555 -0.378998734327517,35.826416015625 -0.370072533450234,35.830192565918 -0.356683215360425,35.8315658569336 -0.346727043087433,35.8353424072266 -0.33265105759747,35.8370590209961 -0.326471350258376,35.8428955078125 -0.319261686901058,35.8518218994141 -0.314111924258455,35.8583450317383 -0.301752483642104,35.8607482910156 -0.291452939044748,35.8597183227539 -0.280810066403804,35.8610916137695 -0.282183340845174)"""),
project=proj3,
type='RW')
p1 = Party.objects.create(
name="Ogiek community of Ngongongeri",
type="GR",
project=proj3
)
cu = TenureRelationshipType.objects.get(id='CU')
TenureRelationship.objects.create(
project=proj3,
party=p1,
spatial_unit=su2,
tenure_type=cu
)
def load_users():
from organization.models import Organization, OrganizationRole
from accounts.models import User
users = [{'username': 'opdpadmin',
'full_name': 'OPDP Admin', 'admin': True},
{'username': 'john', 'full_name':
'John Samorai', 'admin': True},
{'username': 'perista', 'full_name':
'Perista Muthii', 'admin': False},
{'username': 'esther', 'full_name':
'Esther Cheburet', 'admin': False}]
org = Organization.objects.get(slug='opdp')
for user in users:
u = User.objects.create(
username=user['username'],
email='',
full_name=user['full_name'],
email_verified=True,
last_login=datetime.now(tz=timezone.utc)
)
u.set_password('password')
u.save()
OrganizationRole.objects.create(
organization=org, user=u, admin=user['admin']
)
def drop_users():
from organization.models import OrganizationRole
from accounts.models import User
users = ['opdpadmin', 'john', 'perista', 'esther']
for user in users:
try:
u = User.objects.get(username=user)
o = OrganizationRole.objects.get(user=u)
o.delete()
u.delete()
except:
pass
def drop_opdp():
"""Drop OPDP data."""
from organization.models import Organization
drop_users()
try:
Organization.objects.get(slug='opdp').delete()
except:
pass
if __name__ == '__main__':
django.setup()
parser = argparse.ArgumentParser()
parser.add_argument(
"--delete", help='delete all data for this organization',
action="store_true")
args = parser.parse_args()
if args.delete:
drop_opdp()
else:
drop_opdp()
load_opdp()
load_users()