-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentities_to_java.py
101 lines (67 loc) · 2.62 KB
/
entities_to_java.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
import os
os.environ['DJANGO_SETTINGS_MODULE'] = os.environ.get('DJANGO_SETTINGS_MODULE',
'settings')
from bolibana.models import EntityType
from unfpa_core.models import UEntity
header = """
package unfpa;
import java.util.Hashtable;
/**
* List of static codes and names for Entities/Locations
* Automatically generated.
* @author reg
*/
public class StaticCodes {
public Hashtable cercles = new Hashtable();
public Hashtable names = new Hashtable();
public StaticCodes() {
// COMMUNES HASH TABLES
// contains a list of vil_code/vil_name for each village in commune."""
cercle_intro = """
// CERCLES HASH TABLES
// contains a list of com_code/com_ht for each commune in cercle."""
main_intro = """
// MAIN HASH TABLE
// contains a list of cercle_code/cercle_ht for each cercle."""
names_intro = """
// NAMES HASH TABLE
// contains names of code/name for all communes and cercles"""
footer = """
}
}"""
def println(text):
print(text.encode('utf-8'))
println(header)
# loop on communes to add villages
for commune in UEntity.objects.filter(type__slug='commune'):
println(u"")
println(u"\t\t// %s" % commune.name.title())
println(u"\t\tHashtable %s_ht = new Hashtable();" % commune.slug)
for village in commune.get_children():
println(u"\t\t%(com_slug)s_ht.put(\"%(vil_slug)s\", \"%(vil_name)s\");"
% {'com_slug': commune.slug,
'vil_name': village.name.title(),
'vil_slug': village.slug})
println(cercle_intro)
for cercle in UEntity.objects.filter(type__slug='cercle'):
println(u"")
println(u"\t\t// %s" % cercle.name.title())
println(u"\t\tHashtable %s_ht = new Hashtable();" % cercle.slug)
for commune in cercle.get_children():
println(u"\t\t%(c_slug)s_ht.put(\"%(com_slug)s\", %(com_slug)s_ht);"
u" // %(com_name)s"
% {'c_slug': cercle.slug,
'com_slug': commune.slug,
'com_name': commune.name.title()})
println(main_intro)
for cercle in UEntity.objects.filter(type__slug='cercle'):
println(u"\t\tcercles.put(\"%(slug)s\", %(slug)s_ht); // %(name)s"
% {'slug': cercle.slug, 'name': cercle.name.title()})
println(names_intro)
for entity in UEntity.objects.filter(type__slug__in=('cercle', 'commune')):
println(u"\t\tnames.put(\"%(slug)s\", \"%(name)s\");"
% {'slug': entity.slug, 'name': entity.name.title()})
println(footer)