-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean.py
368 lines (269 loc) · 9.92 KB
/
clean.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import argparse
import subprocess
def cleanFacility(model_id):
from facilities.models import Facility
qs = Facility.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityAdmissionStatus(model_id):
from facilities.models import FacilityAdmissionStatus
qs = FacilityAdmissionStatus.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityApproval(model_id):
from facilities.models import FacilityApproval
qs = FacilityApproval.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityContact(model_id):
from facilities.models import FacilityContact
qs = FacilityContact.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityDepartment(model_id):
from facilities.models import FacilityDepartment
qs = FacilityDepartment.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityExportExcelMaterialView(model_id):
from facilities.models import FacilityExportExcelMaterialView
qs = FacilityExportExcelMaterialView.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityInfrastructure(model_id):
from facilities.models import FacilityInfrastructure
qs = FacilityInfrastructure.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityKephManager(model_id):
from facilities.models import FacilityKephManager
qs = FacilityKephManager.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityLevelChangeReason(model_id):
from facilities.models import FacilityLevelChangeReason
qs = FacilityLevelChangeReason.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityOfficer(model_id):
from facilities.models import FacilityOfficer
qs = FacilityOfficer.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityOperationState(model_id):
from facilities.models import FacilityOperationState
qs = FacilityOperationState.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityRegulationStatus(model_id):
from facilities.models import FacilityRegulationStatus
qs = FacilityRegulationStatus.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityService(model_id):
from facilities.models import FacilityService
qs = FacilityService.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityServiceRating(model_id):
from facilities.models import FacilityServiceRating
qs = FacilityServiceRating.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilitySpecialist(model_id):
from facilities.models import FacilitySpecialist
qs = FacilitySpecialist.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityStatus(model_id):
from facilities.models import FacilityStatus
qs = FacilityStatus.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityType(model_id):
from facilities.models import FacilityType
qs = FacilityType.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityUnit(model_id):
from facilities.models import FacilityUnit
qs = FacilityUnit.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityUnitRegulation(model_id):
from facilities.models import FacilityUnitRegulation
qs = FacilityUnitRegulation.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityUpdates(model_id):
from facilities.models import FacilityUpdates
qs = FacilityUpdates.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanFacilityUpgrade (model_id):
from facilities.models import FacilityUpgrade
qs = FacilityUpgrade .objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOfficer(model_id):
from facilities.models import Officer
qs = Officer.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOfficerContact(model_id):
from facilities.models import OfficerContact
qs = OfficerContact.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanKephLevel(model_id):
from facilities.models import KephLevel
qs = KephLevel.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOptionGroup(model_id):
from facilities.models import OptionGroup
qs = OptionGroup.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOption(model_id):
from facilities.models import Option
qs = Option.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOwner(model_id):
from facilities.models import Owner
qs = Owner.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanOwnerType(model_id):
from facilities.models import OwnerType
qs = OwnerType.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanRegulatingBody(model_id):
from facilities.models import RegulatingBody
qs = RegulatingBody.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanRegulatingBodyContact(model_id):
from facilities.models import RegulatingBodyContact
qs = RegulatingBodyContact.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanRegulatoryBodyUser(model_id):
from facilities.models import RegulatoryBodyUser
qs = RegulatoryBodyUser.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanService(model_id):
from facilities.models import Service
qs = Service.objects.get(code=model_id)
qs.deleted = True
qs.save()
def cleanServiceCategory(model_id):
from facilities.models import ServiceCategory
qs = ServiceCategory.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanSpeciality(model_id):
from facilities.models import Speciality
qs = Speciality.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanSpecialityCategory(model_id):
from facilities.models import SpecialityCategory
qs = SpecialityCategory.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanInfrastructure(model_id):
from facilities.models import Infrastructure
qs = Infrastructure.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanCounties(model_id):
from common.models import County
qs = County.objects.get(code=model_id)
qs.deleted = True
qs.save()
def cleanSubCounties(model_id):
from common.models import SubCounty
qs = SubCounty.objects.get(code=model_id)
qs.deleted = True
qs.save()
def cleanConstituencies(model_id):
from common.models import Constituency
qs = Constituency.objects.get(code=model_id)
qs.deleted = True
qs.save()
def cleanWards(model_id):
from common.models import Ward
qs = Ward.objects.get(code=model_id)
qs.deleted = True
qs.save()
def cleanInfrastructureCategory(model_id):
from facilities.models import InfrastructureCategory
qs = InfrastructureCategory.objects.get(id=model_id)
qs.deleted = True
qs.save()
def cleanClassException():
raise cleanError("Unable to import requested model")
data_classes = {
"Facility": cleanFacility,
"FacilityAdmissionStatus": cleanFacilityAdmissionStatus,
"FacilityApproval": cleanFacilityApproval,
"FacilityContact": cleanFacilityContact,
"FacilityDepartment": cleanFacilityDepartment,
"FacilityExportExcelMaterialView": cleanFacilityExportExcelMaterialView,
"FacilityInfrastructure": cleanFacilityInfrastructure,
"FacilityKephManager": cleanFacilityKephManager,
"FacilityLevelChangeReason": cleanFacilityLevelChangeReason,
"FacilityOfficer": cleanFacilityOfficer,
"FacilityOperationState": cleanFacilityOperationState,
"FacilityRegulationStatus": cleanFacilityRegulationStatus,
"FacilityService": cleanFacilityService,
"FacilityServiceRating": cleanFacilityServiceRating,
"FacilitySpecialist": cleanFacilitySpecialist,
"FacilityStatus": cleanFacilityStatus,
"FacilityType": cleanFacilityType,
"FacilityUnit": cleanFacilityUnit,
"FacilityUnitRegulation": cleanFacilityUnitRegulation,
"FacilityUpdates": cleanFacilityUpdates,
"FacilityUpgrade ": cleanFacilityUpgrade ,
"Officer": cleanOfficer,
"OfficerContact": cleanOfficerContact,
"KephLevel": cleanKephLevel,
"OptionGroup": cleanOptionGroup,
"Option": cleanOption,
"Owner": cleanOwner,
"OwnerType": cleanOwnerType,
"RegulatingBody": cleanRegulatingBody,
"RegulatingBodyContact": cleanRegulatingBodyContact,
"RegulatoryBodyUser": cleanRegulatoryBodyUser,
"Service": cleanService,
"ServiceCategory": cleanServiceCategory,
"Speciality": cleanSpeciality,
"SpecialityCategory": cleanSpecialityCategory,
"Infrastructure": cleanInfrastructure,
"InfrastructureCategory": cleanInfrastructureCategory,
"County": cleanCounties,
"SubCounty": cleanSubCounties,
"Constituency": cleanConstituencies,
"Ward": cleanWards
}
def run(model, data_class, uuids):
if model == 'facilities':
for uuid in uuids:
data_classes.get(data_class, cleanClassException())(uuid)
print ("[+] Successfully deleted {} in {}".format(uuid, data_class))
print ("[+] Done")
def getParams():
parser = argparse.ArgumentParser(description='soft delete parsed uuids')
parser.add_argument('uuids', metavar='uuid', nargs='+', help='uuids to be deleted')
parser.add_argument('--model', nargs=1, help='model name')
parser.add_argument('--data_class', nargs=1, help='data class name')
args = parser.parse_args()
return tuple([args.uuids, args.model, args.data_class])
if __name__ == "__main__":
params = getParams()
uuids,[model],[data_class] = params[0], params[1], params[2]
run(model, data_class, uuids)