# Get infos
get_data_object(response_content, object_name, object_label,
- object_col_id, object_id, map_projection, None)
+ object_col_id, object_id, map_projection, None, None, None)
response = HttpResponse()
simplejson.dump(response_content, response,
if object_name in settings.GRACE_TABLE_ASSOCIATED:
list_tab_assoc = settings.GRACE_TABLE_ASSOCIATED.get(object_name).split(",")
+
for table in list_tab_assoc:
# Get infos on associated objects
label = settings.GRACE_TABLE_INFOS.get(table).get('label')
get_data_object(response_content, table, label, object_col_id, object_id,
map_projection,
- settings.GRACE_TABLE_INFOS.get(table).get('id_col'))
-
+ settings.GRACE_TABLE_INFOS.get(table).get('id_col'), object_name+object_id, 1)
+
+ # TODO make a function for this code :
+ # Get infos on sub associated objects and link them to their parent
+ # 2 levels of herarchie MAX
+ response_content_sub = []
+ response_content_lvl1 = []
+ for assoc_feature in response_content:
+ # Get level 2 sub object
+ if table in settings.GRACE_TABLE_SUB_ASSOCIATED:
+ list_tab_lvl1 = settings.GRACE_TABLE_SUB_ASSOCIATED.get(table).get('list').split(",")
+ associated_id = assoc_feature['attributes'][settings.GRACE_TABLE_INFOS.get(table).get('id_col')]
+ for table_lvl1 in list_tab_lvl1:
+ label_sub = settings.GRACE_TABLE_INFOS.get(table_lvl1).get('label')
+ get_data_object(response_content_lvl1, table_lvl1, label_sub, settings.GRACE_TABLE_SUB_ASSOCIATED.get(table).get('id_parent'), associated_id,
+ map_projection,
+ settings.GRACE_TABLE_INFOS.get(table_lvl1).get('id_col'), table+associated_id, 2)
+
+ response_content_lvl2 = []
+ for assoc_feature_lvl2 in response_content_lvl1:
+ # Get level 3 sub object
+ if table_lvl1 in settings.GRACE_TABLE_SUB_ASSOCIATED:
+ list_tab_lvl2 = settings.GRACE_TABLE_SUB_ASSOCIATED.get(table_lvl1).get('list').split(",")
+ associated_id_lvl1 = assoc_feature_lvl2['attributes'][settings.GRACE_TABLE_INFOS.get(table_lvl1).get('id_col')]
+ for table_lvl2 in list_tab_lvl2:
+ label_sub_lvl2 = settings.GRACE_TABLE_INFOS.get(table_lvl2).get('label')
+ get_data_object(response_content_lvl2, table_lvl2, label_sub_lvl2, settings.GRACE_TABLE_SUB_ASSOCIATED.get(table_lvl1).get('id_parent'), associated_id_lvl1,
+ map_projection,
+ settings.GRACE_TABLE_INFOS.get(table_lvl2).get('id_col'), table_lvl1+associated_id_lvl1, 3)
+
+ # Transfert lvl2 features in temporary list
+ for tempo_feature in response_content_lvl2:
+ response_content_sub.append(tempo_feature)
+
+ # Careful. Some feaure maybe twice in response_content_lvl1 and response_content_sub (thats's because model is not fully filled
+ # So we have to delete the double :
+ response_content_final_lvl1 = []
+ for feature_lvl1 in response_content_lvl1:
+ isTwice = False
+ id_feature_lvl1 = feature_lvl1['fid']
+ for feature_lvl2 in response_content_sub:
+ id_feature_lvl2 = feature_lvl2['fid']
+ if id_feature_lvl1 == id_feature_lvl2:
+ isTwice = True
+ if not isTwice :
+ response_content_final_lvl1.append(feature_lvl1)
+
+ # Transfert all sub features in final list
+ for tempo_feature in response_content_final_lvl1:
+ response_content.append(tempo_feature)
+ for tempo_feature in response_content_sub:
+ response_content.append(tempo_feature)
+
response = HttpResponse()
simplejson.dump(response_content, response,
ensure_ascii=False, separators=(',', ':'))
def get_data_object(response_content, table_name, table_label,
- id_col_parent, id_val, map_projection, id_col_associated):
+ id_col_parent, id_val, map_projection, id_col_associated, parent, sub_level):
"""
Perform a SELECT on the DB to retreive infos on associated object
Param: table_name : name of the table to modify
'attributes_editable' : list_editable_columns,
'table_name' : table_name,
'table_label' : table_label,
+ 'parent' : parent,
+ 'sub_level' : sub_level,
'fid' : fid,
'geom' : geom
# (* for all)
#...............................
GRACE_TABLE_ASSOCIATED = {
- 'artere': 'fourreau,sous_tubage,cable',
+ #'artere': 'fourreau,sous_tubage,cable',
+ #'noeud': 'chambre,local_technique,sites_emission,element_branchement_passif',
+ 'artere': 'fourreau',
'noeud': 'chambre,local_technique,sites_emission,element_branchement_passif'
}
+
+#GRACE_TABLE_SUB_ASSOCIATED = {
+# 'fourreau' : 'sous_tubage,cable',
+# 'sous_tubage' : 'cable'
+#}
+GRACE_TABLE_SUB_ASSOCIATED = {
+ 'fourreau' : {
+ 'list': 'sous_tubage,cable',
+ 'id_parent': 'id_four'
+ },
+ 'sous_tubage' : {
+ 'list': 'cable',
+ 'id_parent': 'id_st'
+ }
+}
+
# fields editable must befollowed by: *
# fields of type DATE must befollowed by: #DATE
GRACE_TABLE_INFOS = {
'select_col': 'id_cable,type_cable*,etat_cable*,long_cable*,diam_ext_cable*,diam_int_cable*,num_cable*,coul_cable*,techno_cable*,nbr_fibre_cable*,nbr_fibre_util_cable*,date_instal_cable,id_prop_cable*,id_gestion_cable*,id_util_cable*,prop_md_cable,qlte_geoloc_cable,source_geoloc_cable,date_maj_cable,source_maj_cable,id_four,id_st,id_ep_a,id_ep_b,commentaire_cable',
'date_maj_col' : 'date_maj_cable',
'source_maj_col' : 'source_maj_cable',
- 'label':'Câble'
+ 'label':'Câble'
},
'sous_tubage': {
'id_col': 'id_st',
'select_col': 'id_st,type_st*,etat_st*,num_st*,diam_ext_st*,diam_int_st*,coul_st*,occp_st*,date_instal_st,id_prop_st*,id_gestion_st*,id_util_st*,prop_md_st,qlte_geoloc_st,source_geoloc_st,date_maj_st,source_maj_st,commentaire_st,id_artere,id_four',
'date_maj_col' : 'date_maj_st',
'source_maj_col' : 'source_maj_st',
- 'label':'Sous tubage'
+ 'label':'Sous tubage'
},
'l49': {
'id_col': 'id_work',