From 1b51d8886830def4feef9a354dfac8c5efe3ce7d Mon Sep 17 00:00:00 2001
From: Bruno Nocera Zanette <brunonzanette@gmail.com>
Date: Wed, 8 Oct 2014 16:28:41 -0300
Subject: [PATCH] Fix "tipo_perfil" query

Fix "tipo_perfil" query
---
 lib/opendata_queries_definition.py | 31 +++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib/opendata_queries_definition.py b/lib/opendata_queries_definition.py
index ef5771b..6807be7 100644
--- a/lib/opendata_queries_definition.py
+++ b/lib/opendata_queries_definition.py
@@ -183,17 +183,27 @@ qry_post_content = \
 #--------------------------------------------------------------------#
 
 #--------------------------------------------------------------------#
+
+#--------------------------------------------------------------------#
+# ID of metastring for acctype
+acctype_id = None
+#--------------------------------------------------------------------#
+
 def user_acctype (db, user_guid):
+    user_acctype = ''
     
     content = db.cursor()
     
-    # 51477 = select * from elgg_metastrings where string='accType';
-    content.execute(qry_user_acctype, (user_guid, 51477,))
+    if acctype_id == None:
+        find_acctype_id(db)
+    if acctype_id == 0:
+        return user_acctype
+    
+    content.execute(qry_user_acctype, (user_guid, acctype_id,))
     
     if content.rowcount == 1:
         user_acctype = content.fetchone()[0]
     else:
-        user_acctype=''
         print "ERRO! Nenhum ou Mais do que um resultado para a query"
         
     content.close()
@@ -201,6 +211,21 @@ def user_acctype (db, user_guid):
     return user_acctype
 #--------------------------------------------------------------------#
 
+#--------------------------------------------------------------------#
+def find_acctype_id (db):
+    acctype_query = db.cursor()
+    acctype_query.execute("SELECT id FROM elgg_metastrings WHERE string='accType' LIMIT 1")
+
+    global acctype_id
+    if acctype_query.rowcount == 1:
+        acctype_id = acctype_query.fetchone()[0]
+    else:
+        acctype_id = 0
+        print "ERRO! Não existe 'tipo de usuário' no sistema"
+
+    acctype_query.close()
+#--------------------------------------------------------------------#
+
 #--------------------------------------------------------------------#
 def post_content (db, post_guid, content_typeid):
     
-- 
GitLab