<s> from tornado import locale <EOL> from datetime import datetime <EOL> from decimal import Decimal <EOL> from operator import itemgetter <EOL> import dateutil <EOL> import hashlib <EOL> import logging <EOL> import math <EOL> import os <EOL> import random <EOL> import re <EOL> import string <EOL> import time <EOL> from helper import * <EOL> class Entity ( ) : <EOL> """<STR_LIT>""" <EOL> __translation = None <EOL> @ property <EOL> def __user_id ( self ) : <EOL> if not self . current_user : <EOL> return None <EOL> if not self . current_user . get ( '<STR_LIT:id>' ) : <EOL> return None <EOL> return self . current_user . get ( '<STR_LIT:id>' ) <EOL> @ property <EOL> def __language ( self ) : <EOL> return self . get_user_locale ( ) . code <EOL> def __get_system_translation ( self , field , entity_definition_keyname = '<STR_LIT>' , property_definition_keyname = '<STR_LIT>' ) : <EOL> if not self . __translation : <EOL> self . __translation = { } <EOL> for t in self . db_query ( '<STR_LIT>' , self . get_user_locale ( ) . code ) : <EOL> self . __translation [ '<STR_LIT>' % ( t . get ( '<STR_LIT>' ) , t . get ( '<STR_LIT>' ) , t . get ( '<STR_LIT>' ) ) ] = t . get ( '<STR_LIT:value>' ) <EOL> return self . __translation . get ( '<STR_LIT>' % ( entity_definition_keyname , property_definition_keyname , field ) , None ) <EOL> def create_entity ( self , entity_definition_keyname , parent_entity_id = None , ignore_user = False ) : <EOL> """<STR_LIT>""" <EOL> if ignore_user == True : <EOL> user_id = None <EOL> else : <EOL> if not self . __user_id : <EOL> return <EOL> user_id = self . __user_id <EOL> if not entity_definition_keyname : <EOL> return <EOL> sql = """<STR_LIT>""" <EOL> entity_id = self . db_execute_lastrowid ( sql , entity_definition_keyname , user_id ) <EOL> if not parent_entity_id : <EOL> return entity_id <EOL> parent = self . db_get ( '<STR_LIT>' , parent_entity_id ) <EOL> self . db_execute ( '<STR_LIT>' , parent . get ( '<STR_LIT>' ) , entity_id ) <EOL> sql = """<STR_LIT>""" <EOL> self . db_execute ( sql , entity_id , user_id , entity_definition_keyname , parent_entity_id , entity_id , user_id ) <EOL> for row in self . db_query ( "<STR_LIT>" , entity_id ) : <EOL> self . db_execute ( '<STR_LIT>' , row . get ( '<STR_LIT>' ) , entity_id ) <EOL> self . db_execute ( '<STR_LIT>' , entity_id , row . get ( '<STR_LIT>' ) ) <EOL> sql = """<STR_LIT>""" <EOL> self . db_execute ( sql , entity_id , user_id , entity_id ) <EOL> if user_id : <EOL> self . set_rights ( entity_id = entity_id , related_entity_id = user_id , right = '<STR_LIT>' ) <EOL> for default_value in self . db_query ( '<STR_LIT>' , entity_definition_keyname ) : <EOL> self . set_property ( entity_id = entity_id , property_definition_keyname = default_value . get ( '<STR_LIT>' ) , value = default_value . get ( '<STR_LIT>' ) ) <EOL> sql = """<STR_LIT>""" <EOL> self . db_execute ( sql , entity_id , user_id , parent_entity_id ) <EOL> self . db_execute ( """<STR_LIT>""" , entity_id , user_id , entity_definition_keyname ) <EOL> if user_id : <EOL> self . db_execute ( """<STR_LIT>""" , entity_id , user_id , user_id , entity_definition_keyname ) <EOL> return entity_id <EOL> def duplicate_entity ( self , entity_id , copies = <NUM_LIT:1> , skip_property_definition_keyname = None ) : <EOL> if not entity_id : <EOL> return <EOL> if skip_property_definition_keyname : <EOL> if type ( skip_property_definition_keyname ) is not list : <EOL> skip_property_definition_keyname = [ skip_property_definition_keyname ] <EOL> properties_sql = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in map ( str , skip_property_definition_keyname ) ] ) <EOL> else : <EOL> properties_sql = '<STR_LIT>' <EOL> for x in range ( int ( copies ) ) : <EOL> new_entity_id = self . db_execute_lastrowid ( """<STR_LIT>""" , self . __user_id , entity_id ) <EOL> self . db_execute ( """<STR_LIT>""" % ( new_entity_id , self . __user_id , entity_id , properties_sql ) ) <EOL> self . db_execute ( """<STR_LIT>""" , new_entity_id , self . __user_id , entity_id ) <EOL> self . db_execute ( """<STR_LIT>""" , new_entity_id , self . __user_id , entity_id ) <EOL> self . db_execute ( """<STR_LIT>""" , new_entity_id , self . __user_id , new_entity_id ) <EOL> self . db_execute ( """<STR_LIT>""" , new_entity_id , self . __user_id , self . __user_id , new_entity_id ) <EOL> def delete_entity ( self , entity_id ) : <EOL> if not self . db_get ( """<STR_LIT>""" , <EOL> entity_id , <EOL> self . __user_id <EOL> ) : <EOL> return <EOL> for child_id in self . get_relatives ( ids_only = True , entity_id = entity_id , relationship_definition_keyname = '<STR_LIT>' ) : <EOL> self . delete_entity ( child_id ) <EOL> self . db_execute ( '<STR_LIT>' , self . __user_id , entity_id ) <EOL> self . db_execute ( '<STR_LIT>' , entity_id , entity_id ) <EOL> return True <EOL> def set_property ( self , entity_id = None , relationship_id = None , property_definition_keyname = None , value = None , old_property_id = None , uploaded_file = None , ignore_user = False ) : <EOL> """<STR_LIT>""" <EOL> if not entity_id : <EOL> return <EOL> if ignore_user == True : <EOL> user_id = None <EOL> else : <EOL> if not self . __user_id : <EOL> return <EOL> user_id = self . __user_id <EOL> if old_property_id : <EOL> definition = self . db_get ( '<STR_LIT>' , old_property_id ) <EOL> elif property_definition_keyname : <EOL> definition = self . db_get ( '<STR_LIT>' , property_definition_keyname ) <EOL> else : <EOL> return <EOL> if not definition : <EOL> return <EOL> if old_property_id : <EOL> self . db_execute ( '<STR_LIT>' , user_id , old_property_id ) <EOL> self . db_execute ( '<STR_LIT>' , user_id , entity_id ) <EOL> if self . db_get ( """<STR_LIT>""" , entity_id ) : <EOL> self . db_execute ( """<STR_LIT>""" , user_id , entity_id ) <EOL> else : <EOL> self . db_execute ( """<STR_LIT>""" , entity_id , user_id , entity_id ) <EOL> if user_id : <EOL> if self . db_get ( """<STR_LIT>""" , entity_id ) : <EOL> self . db_execute ( """<STR_LIT>""" , user_id , user_id , entity_id ) <EOL> else : <EOL> self . db_execute ( """<STR_LIT>""" , entity_id , user_id , user_id , entity_id ) <EOL> if not value : <EOL> self . set_mongodb_entity ( entity_id ) <EOL> return <EOL> value_display = None <EOL> if definition . get ( '<STR_LIT>' ) == <NUM_LIT:1> : <EOL> field = '<STR_LIT>' <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT:text>' : <EOL> field = '<STR_LIT>' <EOL> value_display = '<STR_LIT:%s>' % value <EOL> value_display = value_display [ : <NUM_LIT> ] <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> value_display = '<STR_LIT:%s>' % value <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> value = value . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:.>' ) <EOL> value = float ( re . sub ( r'<STR_LIT>' , '<STR_LIT>' , value ) ) <EOL> value_display = round ( value , <NUM_LIT:2> ) <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT:date>' : <EOL> field = '<STR_LIT>' <EOL> value_display = '<STR_LIT:%s>' % value <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> value_display = '<STR_LIT:%s>' % value <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> r = self . __get_properties ( entity_id = value ) <EOL> if r : <EOL> value_display = self . __get_properties ( entity_id = value ) [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT:file>' : <EOL> uploaded_file = value <EOL> field = '<STR_LIT>' <EOL> value_display = uploaded_file [ '<STR_LIT:filename>' ] [ : <NUM_LIT> ] <EOL> if uploaded_file . get ( '<STR_LIT:url>' ) : <EOL> value = self . db_execute_lastrowid ( '<STR_LIT>' , uploaded_file . get ( '<STR_LIT:url>' , '<STR_LIT>' ) , uploaded_file . get ( '<STR_LIT:filename>' , '<STR_LIT>' ) , user_id ) <EOL> elif uploaded_file . get ( '<STR_LIT>' ) : <EOL> value = self . db_execute_lastrowid ( '<STR_LIT>' , uploaded_file . get ( '<STR_LIT>' , '<STR_LIT>' ) , uploaded_file . get ( '<STR_LIT:filename>' , '<STR_LIT>' ) , uploaded_file . get ( '<STR_LIT>' , '<STR_LIT>' ) , user_id ) <EOL> else : <EOL> md5 = hashlib . md5 ( uploaded_file . get ( '<STR_LIT:body>' ) ) . hexdigest ( ) <EOL> directory = os . path . join ( '<STR_LIT:/>' , '<STR_LIT>' , '<STR_LIT>' , self . app_settings ( '<STR_LIT>' ) , md5 [ <NUM_LIT:0> ] ) <EOL> filename = os . path . join ( directory , md5 ) <EOL> if not os . path . exists ( directory ) : <EOL> os . makedirs ( directory ) <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( uploaded_file . get ( '<STR_LIT:body>' , '<STR_LIT>' ) ) <EOL> f . close ( ) <EOL> value = self . db_execute_lastrowid ( '<STR_LIT>' , md5 , uploaded_file . get ( '<STR_LIT:filename>' , '<STR_LIT>' ) , len ( uploaded_file . get ( '<STR_LIT:body>' , '<STR_LIT>' ) ) , user_id ) <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> value = <NUM_LIT:1> if value . lower ( ) == '<STR_LIT:true>' else <NUM_LIT:0> <EOL> value_display = '<STR_LIT:%s>' % bool ( value ) <EOL> elif definition . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> field = '<STR_LIT>' <EOL> value_display = '<STR_LIT:%s>' % value <EOL> else : <EOL> field = '<STR_LIT>' <EOL> value = value [ : <NUM_LIT> ] <EOL> value_display = '<STR_LIT:%s>' % value <EOL> new_property_id = self . db_execute_lastrowid ( """<STR_LIT>""" % field , <EOL> entity_id , <EOL> definition . get ( '<STR_LIT>' ) , <EOL> value , <EOL> value_display , <EOL> user_id <EOL> ) <EOL> if definition . get ( '<STR_LIT>' ) == '<STR_LIT:file>' and uploaded_file . get ( '<STR_LIT>' ) : <EOL> self . db_execute ( '<STR_LIT>' , new_property_id , value ) <EOL> self . db_execute ( '<STR_LIT>' , user_id , entity_id ) <EOL> self . set_mongodb_entity ( entity_id ) <EOL> return new_property_id <EOL> def set_mongodb_entity ( self , entity_id ) : <EOL> sql = """<STR_LIT>""" <EOL> r = self . db_get ( sql , entity_id ) <EOL> mysql_id = r . get ( '<STR_LIT>' ) <EOL> e = { } <EOL> e [ '<STR_LIT>' ] = mysql_id <EOL> e [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> e [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if e . get ( '<STR_LIT>' ) : <EOL> e [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] = '<STR_LIT:action>' <EOL> e [ '<STR_LIT>' ] = [ e . get ( '<STR_LIT>' ) ] <EOL> if r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if e . get ( '<STR_LIT>' ) : <EOL> e [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] = '<STR_LIT:action>' <EOL> e [ '<STR_LIT>' ] = [ e . get ( '<STR_LIT>' ) ] <EOL> if r . get ( '<STR_LIT>' ) and r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if r . get ( '<STR_LIT>' ) and r . get ( '<STR_LIT>' ) : <EOL> e . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = r . get ( '<STR_LIT>' ) <EOL> if e . get ( '<STR_LIT>' ) : <EOL> e [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] = '<STR_LIT:action>' <EOL> e [ '<STR_LIT>' ] = [ e . get ( '<STR_LIT>' ) ] <EOL> viewers = self . __get_mongodb_right ( mysql_id , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if viewers : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( viewers ) ) ] <EOL> expanders = self . __get_mongodb_right ( mysql_id , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if expanders : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( expanders ) ) ] <EOL> editors = self . __get_mongodb_right ( mysql_id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if editors : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( editors ) ) ] <EOL> owners = self . __get_mongodb_right ( mysql_id , [ '<STR_LIT>' ] ) <EOL> if owners : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( owners ) ) ] <EOL> parent = self . __get_mongodb_parent ( entity_id = mysql_id , recursive = False ) <EOL> if parent : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( parent ) ) ] <EOL> ancestor = self . __get_mongodb_parent ( entity_id = mysql_id , recursive = True ) <EOL> if ancestor : <EOL> e [ '<STR_LIT>' ] = [ { '<STR_LIT>' : x , '<STR_LIT:type>' : '<STR_LIT>' } for x in list ( set ( ancestor ) ) ] <EOL> sql = """<STR_LIT>""" <EOL> properties = { } <EOL> for r2 in self . db_query ( sql , mysql_id ) : <EOL> value = { } <EOL> if r2 . get ( '<STR_LIT>' ) == '<STR_LIT:string>' and r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT:text>' and r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT>' and r2 . get ( '<STR_LIT>' ) != None : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT>' and r2 . get ( '<STR_LIT>' ) != None : <EOL> value [ '<STR_LIT:value>' ] = float ( r2 . get ( '<STR_LIT>' ) ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT>' and r2 . get ( '<STR_LIT>' ) != None : <EOL> value [ '<STR_LIT:value>' ] = bool ( r2 . get ( '<STR_LIT>' ) ) <EOL> elif r2 . get ( '<STR_LIT>' ) in [ '<STR_LIT:date>' , '<STR_LIT>' ] and r2 . get ( '<STR_LIT>' ) != None : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT>' and r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT>' and r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> elif r2 . get ( '<STR_LIT>' ) == '<STR_LIT:file>' and r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT:value>' ] = r2 . get ( '<STR_LIT>' ) <EOL> if r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT:url>' ] = r2 . get ( '<STR_LIT:file>' ) <EOL> else : <EOL> value [ '<STR_LIT:size>' ] = r2 . get ( '<STR_LIT>' ) <EOL> if r2 . get ( '<STR_LIT>' , None ) : <EOL> value [ '<STR_LIT>' ] = r2 . get ( '<STR_LIT>' ) <EOL> if r2 . get ( '<STR_LIT>' , None ) : <EOL> value [ '<STR_LIT>' ] = r2 . get ( '<STR_LIT>' ) <EOL> if not value : <EOL> continue <EOL> value [ '<STR_LIT>' ] = r2 . get ( '<STR_LIT>' ) <EOL> value [ '<STR_LIT:type>' ] = r2 . get ( '<STR_LIT>' ) <EOL> if r2 . get ( '<STR_LIT>' ) : <EOL> value [ '<STR_LIT>' ] = r2 . get ( '<STR_LIT>' ) <EOL> e . setdefault ( r2 . get ( '<STR_LIT>' ) , [ ] ) . append ( value ) <EOL> try : <EOL> mongo_entity_version = self . mongodb ( ) . entityVersion . find_one ( { '<STR_LIT>' : mysql_id } , { '<STR_LIT>' : False , '<STR_LIT>' : True } ) <EOL> if mongo_entity_version : <EOL> e [ '<STR_LIT>' ] = mongo_entity_version . get ( '<STR_LIT>' ) <EOL> else : <EOL> e [ '<STR_LIT>' ] = self . mongodb ( ) . entity . insert_one ( { } ) . inserted_id <EOL> self . mongodb ( ) . entityVersion . insert_one ( e ) <EOL> except Exception , err : <EOL> self . captureException ( ) <EOL> logging . error ( '<STR_LIT>' % ( err , e ) ) <EOL> def __get_mongodb_parent ( self , entity_id , recursive = False ) : <EOL> sql = """<STR_LIT>""" % entity_id <EOL> entities = [ ] <EOL> for r in self . db_query ( sql ) : <EOL> entities . append ( r . get ( '<STR_LIT>' ) ) <EOL> if recursive : <EOL> entities = entities + self . __get_mongodb_parent ( entity_id = r . get ( '<STR_LIT>' ) , recursive = True ) <EOL> return entities <EOL> def __get_mongodb_right ( self , entity_id , rights ) : <EOL> sql = """<STR_LIT>""" % ( '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % x for x in rights ] ) , entity_id ) <EOL> entities = [ ] <EOL> for r in self . db_query ( sql ) : <EOL> entities . append ( r . get ( '<STR_LIT>' ) ) <EOL> return entities <EOL> def set_counter ( self , entity_id ) : <EOL> """<STR_LIT>""" <EOL> if not entity_id : <EOL> return <EOL> if self . db_get ( '<STR_LIT>' , entity_id ) . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> parent = self . get_relatives ( related_entity_id = entity_id , relationship_definition_keyname = '<STR_LIT>' , reverse_relation = True , limit = <NUM_LIT:1> ) . values ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> childs = self . get_relatives ( entity_id = parent . get ( '<STR_LIT:id>' , None ) , relationship_definition_keyname = '<STR_LIT>' ) . values ( ) <EOL> if childs : <EOL> childs_count = len ( [ y . get ( '<STR_LIT:id>' , <NUM_LIT:0> ) for y in childs [ <NUM_LIT:0> ] if y . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , None ) ] ) + <NUM_LIT:1> <EOL> else : <EOL> childs_count = <NUM_LIT:1> <EOL> parent_number = '<STR_LIT>' . join ( [ '<STR_LIT:%s>' % x [ '<STR_LIT:value>' ] for x in parent . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , [ ] ) if x [ '<STR_LIT:value>' ] ] ) <EOL> counter_value = '<STR_LIT>' % ( parent_number , childs_count ) <EOL> self . set_property ( entity_id = entity_id , property_definition_keyname = '<STR_LIT>' , value = counter_value ) <EOL> return counter_value <EOL> property_id = self . db_execute_lastrowid ( """<STR_LIT>""" % { '<STR_LIT>' : entity_id , '<STR_LIT>' : self . __user_id } ) <EOL> self . db_execute ( """<STR_LIT>""" % { '<STR_LIT>' : entity_id , '<STR_LIT>' : self . __user_id } ) <EOL> self . db_execute ( '<STR_LIT>' , property_id ) <EOL> return self . db_get ( '<STR_LIT>' , property_id ) . get ( '<STR_LIT>' ) <EOL> def set_relations ( self , entity_id , related_entity_id , relationship_definition_keyname , delete = False , update = False ) : <EOL> """<STR_LIT>""" <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> if type ( related_entity_id ) is not list : <EOL> related_entity_id = [ related_entity_id ] <EOL> if type ( relationship_definition_keyname ) is not list : <EOL> relationship_definition_keyname = [ relationship_definition_keyname ] <EOL> for e in entity_id : <EOL> for r in related_entity_id : <EOL> for t in relationship_definition_keyname : <EOL> self . db_execute ( '<STR_LIT>' , r if t == '<STR_LIT>' else e ) <EOL> if delete == True : <EOL> sql = """<STR_LIT>""" % ( self . __user_id , t , e , r ) <EOL> self . db_execute ( sql ) <EOL> elif update == True : <EOL> sql = """<STR_LIT>""" % ( self . __user_id , t , e , r ) <EOL> old = self . db_execute_rowcount ( sql ) <EOL> if not old : <EOL> sql = """<STR_LIT>""" % ( t , e , r , self . __user_id ) <EOL> self . db_execute ( sql ) <EOL> else : <EOL> sql = """<STR_LIT>""" % ( t , e , r ) <EOL> old = self . db_get ( sql ) <EOL> if not old : <EOL> sql = """<STR_LIT>""" % ( t , e , r , self . __user_id ) <EOL> self . db_execute ( sql ) <EOL> def get_rights ( self , entity_id ) : <EOL> if not entity_id : <EOL> return <EOL> rights = { } <EOL> for right in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> sql = """<STR_LIT>""" <EOL> relationship = self . db_query ( sql , right , entity_id ) <EOL> if not relationship : <EOL> continue <EOL> ids = [ x . get ( '<STR_LIT>' ) for x in relationship if x . get ( '<STR_LIT>' ) ] <EOL> if ids : <EOL> entities = self . __get_properties ( entity_id = ids , full_definition = False , only_public = False ) <EOL> if entities : <EOL> rights [ right ] = entities <EOL> return rights <EOL> def set_rights ( self , entity_id , related_entity_id , right = None , ignore_user = False ) : <EOL> if not entity_id or not related_entity_id : <EOL> return <EOL> if ignore_user == True : <EOL> user_id = None <EOL> else : <EOL> if not self . __user_id : <EOL> return <EOL> user_id = self . __user_id <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> if type ( related_entity_id ) is not list : <EOL> related_entity_id = [ related_entity_id ] <EOL> sql = """<STR_LIT>""" % ( '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) , '<STR_LIT:U+002C>' . join ( map ( str , related_entity_id ) ) ) <EOL> self . db_execute ( sql , user_id ) <EOL> if right in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> for e in entity_id : <EOL> for re in related_entity_id : <EOL> self . db_execute ( '<STR_LIT>' , right , int ( e ) , int ( re ) , user_id ) <EOL> self . db_execute ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) ) <EOL> def set_sharing ( self , entity_id , sharing ) : <EOL> if not entity_id or not sharing : <EOL> return <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> sql = """<STR_LIT>""" % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) <EOL> self . db_execute ( sql , sharing , self . __user_id ) <EOL> def set_sharing_key ( self , entity_id , generate = False ) : <EOL> if not entity_id : <EOL> return <EOL> if generate : <EOL> sharing_key = '<STR_LIT>' . join ( random . choice ( string . ascii_letters + string . digits ) for x in range ( <NUM_LIT:64> ) ) <EOL> else : <EOL> sharing_key = None <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> sql = """<STR_LIT>""" % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) <EOL> self . db_execute ( sql , sharing_key , self . __user_id ) <EOL> return sharing_key <EOL> def get_users ( self , search = None ) : <EOL> """<STR_LIT>""" <EOL> query_re = '<STR_LIT>' <EOL> if search != None : <EOL> join_parts = [ ] <EOL> for s in search . split ( '<STR_LIT:U+0020>' ) [ : <NUM_LIT:5> ] : <EOL> if not s : <EOL> continue <EOL> join_parts . append ( '<STR_LIT>' % { '<STR_LIT>' : s } ) <EOL> query_re = '<STR_LIT:U+0020>' . join ( join_parts ) <EOL> sql = """<STR_LIT>""" % { '<STR_LIT>' : self . __user_id , '<STR_LIT>' : query_re } <EOL> ids = self . db_query ( sql ) <EOL> entities = self . __get_properties ( entity_id = [ x . get ( '<STR_LIT:id>' ) for x in ids ] ) <EOL> if not entities : <EOL> return [ ] <EOL> return entities <EOL> def get_entities ( self , ids_only = False , entity_id = None , search = None , entity_definition_keyname = None , dataproperty = None , limit = None , full_definition = False , only_public = False , sharing_key = None ) : <EOL> """<STR_LIT>""" <EOL> ids = self . __get_id_list ( entity_id = entity_id , search = search , entity_definition_keyname = entity_definition_keyname , limit = limit , only_public = only_public , sharing_key = sharing_key ) <EOL> if ids_only == True : <EOL> return ids <EOL> entities = self . __get_properties ( entity_id = ids , entity_definition_keyname = entity_definition_keyname , dataproperty = dataproperty , full_definition = full_definition , only_public = only_public , sharing_key = sharing_key ) <EOL> if not entities and full_definition == False and entity_definition_keyname == None : <EOL> return <EOL> if limit == <NUM_LIT:1> and len ( entities ) > <NUM_LIT:0> : <EOL> return entities [ <NUM_LIT:0> ] <EOL> return entities <EOL> def __get_id_list ( self , entity_id = None , search = None , entity_definition_keyname = None , limit = None , only_public = False , sharing_key = None ) : <EOL> """<STR_LIT>""" <EOL> select_parts = [ '<STR_LIT>' ] <EOL> join_parts = [ ] <EOL> where_parts = [ '<STR_LIT>' ] <EOL> sql_parts = [ ] <EOL> if search != None : <EOL> i = <NUM_LIT:0> <EOL> for s in search . split ( '<STR_LIT:U+0020>' ) [ : <NUM_LIT:5> ] : <EOL> if not s : <EOL> continue <EOL> i += <NUM_LIT:1> <EOL> join_parts . append ( '<STR_LIT>' % { '<STR_LIT>' : i } ) <EOL> if not self . __user_id or only_public == True : <EOL> join_parts . append ( '<STR_LIT>' % ( i , i , i ) ) <EOL> where_parts . append ( '<STR_LIT>' % ( i , s ) ) <EOL> where_parts . append ( '<STR_LIT>' % i ) <EOL> if entity_definition_keyname != None : <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> where_parts . append ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in map ( str , entity_definition_keyname ) ] ) ) <EOL> if entity_id != None : <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> where_parts . append ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) ) <EOL> if self . __user_id and only_public == False : <EOL> where_parts . append ( '<STR_LIT>' ) <EOL> join_parts . append ( '<STR_LIT>' ) <EOL> where_parts . append ( '<STR_LIT>' % self . __user_id ) <EOL> elif sharing_key : <EOL> where_parts . append ( '<STR_LIT>' % sharing_key ) <EOL> else : <EOL> where_parts . append ( '<STR_LIT>' ) <EOL> i = <NUM_LIT:0> <EOL> if search != None : <EOL> for s in search . split ( '<STR_LIT:U+0020>' ) : <EOL> i += <NUM_LIT:1> <EOL> where_parts . append ( '<STR_LIT>' % i ) <EOL> if len ( select_parts ) > <NUM_LIT:0> : <EOL> sql_parts . append ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( select_parts ) ) <EOL> sql_parts . append ( '<STR_LIT>' ) <EOL> if len ( join_parts ) > <NUM_LIT:0> : <EOL> sql_parts . append ( '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( join_parts ) ) <EOL> if len ( where_parts ) > <NUM_LIT:0> : <EOL> sql_parts . append ( '<STR_LIT>' % '<STR_LIT>' . join ( where_parts ) ) <EOL> if limit : <EOL> limit = '<STR_LIT>' % limit <EOL> else : <EOL> limit = '<STR_LIT>' <EOL> sql_parts . append ( '<STR_LIT>' % limit ) <EOL> sql = '<STR_LIT>' . join ( sql_parts ) <EOL> items = self . db_query ( sql ) <EOL> if not items : <EOL> return [ ] <EOL> return [ x . get ( '<STR_LIT:id>' ) for x in items ] <EOL> def __get_properties ( self , entity_id = None , entity_definition_keyname = None , dataproperty = None , full_definition = False , only_public = False , sharing_key = None ) : <EOL> """<STR_LIT>""" <EOL> items = None <EOL> if entity_id : <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> if self . __user_id and only_public == False : <EOL> rights = '<STR_LIT>' % self . __user_id <EOL> public = '<STR_LIT>' <EOL> elif sharing_key : <EOL> rights = '<STR_LIT>' <EOL> public = '<STR_LIT>' % sharing_key <EOL> else : <EOL> rights = '<STR_LIT>' <EOL> public = '<STR_LIT>' <EOL> datapropertysql = '<STR_LIT>' <EOL> if dataproperty : <EOL> if type ( dataproperty ) is not list : <EOL> dataproperty = [ dataproperty ] <EOL> datapropertysql = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in dataproperty ] ) <EOL> sql = """<STR_LIT>""" % { '<STR_LIT>' : self . get_user_locale ( ) . code , '<STR_LIT>' : public , '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) , '<STR_LIT>' : datapropertysql , '<STR_LIT>' : rights } <EOL> items = { } <EOL> for row in self . db_query ( sql ) : <EOL> if row . get ( '<STR_LIT>' ) == '<STR_LIT>' and not row . get ( '<STR_LIT>' ) and not sharing_key : <EOL> continue <EOL> if row . get ( '<STR_LIT>' ) in [ '<STR_LIT>' , '<STR_LIT>' ] and row . get ( '<STR_LIT>' ) not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] and row . get ( '<STR_LIT>' ) != <NUM_LIT:1> and not sharing_key : <EOL> continue <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:id>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:label>' ] = self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:description>' ] = self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:right>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) if row . get ( '<STR_LIT>' ) else datetime . datetime . now ( ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , property_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:label>' ] = self . __get_system_translation ( field = '<STR_LIT:label>' , property_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , property_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:description>' ] = self . __get_system_translation ( field = '<STR_LIT:description>' , property_definition_keyname = row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = bool ( row . get ( '<STR_LIT>' ) ) <EOL> value = row . get ( '<STR_LIT>' ) if row . get ( '<STR_LIT>' ) else '<STR_LIT>' <EOL> if row . get ( '<STR_LIT>' ) == <NUM_LIT:1> : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT:string>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT:text>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> value = row . get ( '<STR_LIT>' ) if row . get ( '<STR_LIT>' ) else '<STR_LIT>' <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT:date>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT:file>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> elif row . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> db_value = row . get ( '<STR_LIT>' ) <EOL> else : <EOL> db_value = '<STR_LIT>' <EOL> value = '<STR_LIT:X>' <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:id>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:value>' ] = value <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = db_value <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> items . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % row . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT>' % row . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT>' ] = row . get ( '<STR_LIT>' ) <EOL> if not items : <EOL> if not full_definition : <EOL> return [ ] <EOL> if entity_definition_keyname : <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> items = { } <EOL> for e in entity_definition_keyname : <EOL> items . setdefault ( '<STR_LIT>' % e , { } ) [ '<STR_LIT>' ] = e <EOL> items . setdefault ( '<STR_LIT>' % e , { } ) [ '<STR_LIT>' ] = '<STR_LIT:X>' <EOL> for key , value in items . iteritems ( ) : <EOL> if value . get ( '<STR_LIT:id>' , None ) : <EOL> items [ key ] = dict ( items [ key ] . items ( ) + self . __get_displayfields ( value ) . items ( ) ) <EOL> items [ key ] [ '<STR_LIT>' ] = self . __get_picture_url ( value [ '<STR_LIT:id>' ] , value [ '<STR_LIT>' ] ) <EOL> items [ key ] [ '<STR_LIT>' ] = True <EOL> for d in self . get_definition ( entity_definition_keyname = value [ '<STR_LIT>' ] ) : <EOL> if not value . get ( '<STR_LIT:id>' , None ) : <EOL> items [ key ] [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT:label>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT:description>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = d [ '<STR_LIT>' ] <EOL> if d [ '<STR_LIT>' ] and len ( value . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) . get ( '<STR_LIT>' , { } ) . values ( ) ) < <NUM_LIT:1> : <EOL> items [ key ] [ '<STR_LIT>' ] = False <EOL> if full_definition : <EOL> if not d [ '<STR_LIT>' ] or d [ '<STR_LIT>' ] > len ( value . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) . get ( '<STR_LIT>' , { } ) . values ( ) ) : <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) . setdefault ( '<STR_LIT>' , { } ) [ '<STR_LIT>' ] = { '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:X>' , '<STR_LIT:value>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> if not d [ '<STR_LIT>' ] or d [ '<STR_LIT>' ] > len ( value . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) . get ( '<STR_LIT>' , { } ) . values ( ) ) : <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = True <EOL> else : <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) [ '<STR_LIT>' ] = False <EOL> if d [ '<STR_LIT>' ] and d [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> for c in self . get_entities ( entity_definition_keyname = d [ '<STR_LIT>' ] , only_public = True ) : <EOL> if c . get ( '<STR_LIT:id>' , None ) : <EOL> items [ key ] . setdefault ( '<STR_LIT>' , { } ) . setdefault ( '<STR_LIT:%s>' % d [ '<STR_LIT>' ] , { } ) . setdefault ( '<STR_LIT>' , [ ] ) . append ( { '<STR_LIT:id>' : c . get ( '<STR_LIT:id>' , '<STR_LIT>' ) , '<STR_LIT:label>' : c . get ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> for p_key , p_value in value . get ( '<STR_LIT>' , { } ) . iteritems ( ) : <EOL> if p_value . get ( '<STR_LIT>' ) : <EOL> items [ key ] [ '<STR_LIT>' ] [ p_key ] [ '<STR_LIT>' ] = sorted ( p_value . get ( '<STR_LIT>' , { } ) . values ( ) , key = itemgetter ( '<STR_LIT>' ) ) <EOL> if p_value [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> reference_definition = self . db_get ( '<STR_LIT>' , p_value [ '<STR_LIT>' ] ) <EOL> if reference_definition : <EOL> if reference_definition . get ( '<STR_LIT>' ) : <EOL> items [ key ] [ '<STR_LIT>' ] [ p_key ] [ '<STR_LIT>' ] = reference_definition . get ( '<STR_LIT>' ) <EOL> if p_value [ '<STR_LIT>' ] == '<STR_LIT:file>' : <EOL> for f_key , f_value in enumerate ( p_value . get ( '<STR_LIT>' , { } ) ) : <EOL> if not f_value . get ( '<STR_LIT>' ) : <EOL> continue <EOL> file_result = self . db_get ( '<STR_LIT>' , f_value . get ( '<STR_LIT>' ) ) <EOL> if not file_result : <EOL> continue <EOL> items [ key ] [ '<STR_LIT>' ] [ p_key ] [ '<STR_LIT>' ] [ f_key ] [ '<STR_LIT>' ] = file_result . get ( '<STR_LIT>' ) <EOL> items [ key ] [ '<STR_LIT>' ] [ p_key ] [ '<STR_LIT>' ] [ f_key ] [ '<STR_LIT>' ] = file_result . get ( '<STR_LIT>' ) <EOL> items [ key ] [ '<STR_LIT>' ] [ p_key ] [ '<STR_LIT>' ] [ f_key ] [ '<STR_LIT>' ] = file_result . get ( '<STR_LIT>' ) <EOL> return items . values ( ) <EOL> def __get_displayfields ( self , entity_dict ) : <EOL> """<STR_LIT>""" <EOL> result = { } <EOL> for displayfield in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> result [ displayfield ] = entity_dict . get ( displayfield , '<STR_LIT>' ) if entity_dict . get ( displayfield , '<STR_LIT>' ) else None <EOL> for data_property in findTags ( entity_dict . get ( displayfield , '<STR_LIT>' ) , '<STR_LIT:@>' , '<STR_LIT:@>' ) : <EOL> dataproperty_dict = entity_dict . get ( '<STR_LIT>' , { } ) . get ( data_property , { } ) <EOL> result [ displayfield ] = result [ displayfield ] . replace ( '<STR_LIT>' % data_property , '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT:%s>' % x [ '<STR_LIT:value>' ] for x in dataproperty_dict . get ( '<STR_LIT>' , { } ) . values ( ) ] ) ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> result [ '<STR_LIT>' ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = entity_dict . get ( '<STR_LIT>' ) ) <EOL> if not result [ '<STR_LIT>' ] : <EOL> result [ '<STR_LIT>' ] = entity_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) if entity_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) else None <EOL> for data_property in findTags ( entity_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:@>' , '<STR_LIT:@>' ) : <EOL> result [ '<STR_LIT>' ] = result [ '<STR_LIT>' ] . replace ( '<STR_LIT>' % data_property , entity_dict . get ( '<STR_LIT>' , { } ) . get ( data_property , { } ) . get ( '<STR_LIT:label>' , '<STR_LIT>' ) ) <EOL> result [ '<STR_LIT>' ] = result [ '<STR_LIT>' ] . split ( '<STR_LIT:|>' ) if result [ '<STR_LIT>' ] else None <EOL> result [ '<STR_LIT>' ] = result [ '<STR_LIT>' ] . split ( '<STR_LIT:|>' ) if result [ '<STR_LIT>' ] else None <EOL> if entity_dict . get ( '<STR_LIT:id>' , None ) and entity_dict . get ( '<STR_LIT>' , None ) != result [ '<STR_LIT>' ] : <EOL> self . db_execute ( '<STR_LIT>' , result [ '<STR_LIT>' ] , entity_dict . get ( '<STR_LIT:id>' ) ) <EOL> return result <EOL> def __get_picture_url ( self , entity_id , entity_definition_keyname ) : <EOL> """<STR_LIT>""" <EOL> sql = """<STR_LIT>""" <EOL> f = self . db_get ( sql , entity_id ) <EOL> if f : <EOL> return '<STR_LIT>' % entity_id <EOL> elif entity_definition_keyname in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return '<STR_LIT>' % entity_id <EOL> elif entity_definition_keyname == '<STR_LIT>' : <EOL> return '<STR_LIT>' % ( hashlib . md5 ( str ( entity_id ) ) . hexdigest ( ) ) <EOL> else : <EOL> return '<STR_LIT>' % ( hashlib . md5 ( str ( entity_id ) ) . hexdigest ( ) ) <EOL> def get_definition ( self , entity_definition_keyname ) : <EOL> """<STR_LIT>""" <EOL> if not entity_definition_keyname : <EOL> return <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> sql = """<STR_LIT>""" % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in map ( str , entity_definition_keyname ) ] ) <EOL> defs = [ ] <EOL> for r in self . db_query ( sql ) : <EOL> defs . append ( { <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , property_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT:label>' , property_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , property_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT:description>' , property_definition_keyname = r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : bool ( r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : bool ( r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : bool ( r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : bool ( r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : bool ( r . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : r . get ( '<STR_LIT>' ) , <EOL> } ) <EOL> return defs <EOL> def get_entity_definition ( self , entity_definition_keyname ) : <EOL> """<STR_LIT>""" <EOL> if entity_definition_keyname : <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> sql = """<STR_LIT>""" % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in map ( str , entity_definition_keyname ) ] ) <EOL> defs = [ ] <EOL> for d in self . db_query ( sql ) : <EOL> defs . append ( { <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:label>' : self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:description>' : self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) <EOL> } ) <EOL> return defs <EOL> def get_relatives ( self , ids_only = False , relationship_ids_only = False , entity_id = None , related_entity_id = None , relationship_definition_keyname = None , reverse_relation = False , entity_definition_keyname = None , full_definition = False , limit = None , only_public = False ) : <EOL> """<STR_LIT>""" <EOL> if entity_id : <EOL> if type ( entity_id ) is not list : <EOL> entity_id = [ entity_id ] <EOL> if related_entity_id : <EOL> if type ( related_entity_id ) is not list : <EOL> related_entity_id = [ related_entity_id ] <EOL> if relationship_definition_keyname : <EOL> if type ( relationship_definition_keyname ) is not list : <EOL> relationship_definition_keyname = [ relationship_definition_keyname ] <EOL> if entity_definition_keyname : <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> unionsql = '<STR_LIT>' <EOL> if reverse_relation == True : <EOL> sql = """<STR_LIT>""" <EOL> else : <EOL> sql = """<STR_LIT>""" <EOL> if not ids_only : <EOL> unionsql = """<STR_LIT>""" <EOL> if entity_id : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) <EOL> if related_entity_id : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( map ( str , related_entity_id ) ) <EOL> if self . __user_id and only_public == False : <EOL> sql += '<STR_LIT>' % self . __user_id <EOL> else : <EOL> sql += '<STR_LIT>' <EOL> if relationship_definition_keyname : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in relationship_definition_keyname ] ) <EOL> if entity_definition_keyname : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in entity_definition_keyname ] ) <EOL> if unionsql : <EOL> sql += unionsql <EOL> if entity_id : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( map ( str , entity_id ) ) <EOL> if self . __user_id and only_public == False : <EOL> sql += '<STR_LIT>' % self . __user_id <EOL> else : <EOL> sql += '<STR_LIT>' <EOL> if entity_definition_keyname : <EOL> sql += '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in entity_definition_keyname ] ) <EOL> sql += '<STR_LIT>' <EOL> if limit : <EOL> sql += '<STR_LIT>' % limit <EOL> sql += '<STR_LIT:;>' <EOL> if ids_only == True : <EOL> items = [ ] <EOL> for item in self . db_query ( sql ) : <EOL> items . append ( item . get ( '<STR_LIT:id>' ) ) <EOL> elif relationship_ids_only == True : <EOL> items = [ ] <EOL> for item in self . db_query ( sql ) : <EOL> items . append ( item . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> items = { } <EOL> for item in self . db_query ( sql ) : <EOL> ent = self . __get_properties ( entity_id = item . get ( '<STR_LIT:id>' ) , full_definition = full_definition , entity_definition_keyname = entity_definition_keyname , only_public = only_public ) <EOL> if not ent : <EOL> continue <EOL> ent = ent [ <NUM_LIT:0> ] <EOL> items . setdefault ( '<STR_LIT:%s>' % ent . get ( '<STR_LIT>' , '<STR_LIT>' ) , [ ] ) . append ( ent ) <EOL> return items <EOL> def get_file ( self , file_id , sharing_key = None ) : <EOL> """<STR_LIT>""" <EOL> if type ( file_id ) is not list : <EOL> file_id = [ file_id ] <EOL> if self . __user_id : <EOL> user_where = """<STR_LIT>""" % self . __user_id <EOL> elif sharing_key : <EOL> user_where = '<STR_LIT>' % sharing_key <EOL> else : <EOL> user_where = '<STR_LIT>' <EOL> sql = """<STR_LIT>""" % { '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( map ( str , file_id ) ) , '<STR_LIT>' : user_where } <EOL> result = [ ] <EOL> for f in self . db_query ( sql ) : <EOL> if f . get ( '<STR_LIT>' ) : <EOL> filename = os . path . join ( '<STR_LIT:/>' , '<STR_LIT>' , '<STR_LIT>' , self . app_settings ( '<STR_LIT>' ) , f . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] , f . get ( '<STR_LIT>' ) ) <EOL> if os . path . isfile ( filename ) : <EOL> with open ( filename , '<STR_LIT:r>' ) as myfile : <EOL> filecontent = myfile . read ( ) <EOL> else : <EOL> filecontent = None <EOL> else : <EOL> filecontent = None <EOL> result . append ( { <EOL> '<STR_LIT:id>' : f . get ( '<STR_LIT:id>' ) , <EOL> '<STR_LIT>' : f . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:file>' : filecontent , <EOL> '<STR_LIT:filename>' : f . get ( '<STR_LIT:filename>' ) , <EOL> '<STR_LIT>' : f . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:url>' : f . get ( '<STR_LIT:url>' ) <EOL> } ) <EOL> return result <EOL> def get_allowed_childs ( self , entity_id ) : <EOL> """<STR_LIT>""" <EOL> if not self . db_get ( '<STR_LIT>' , entity_id , self . __user_id ) : <EOL> return [ ] <EOL> sql = """<STR_LIT>""" % entity_id <EOL> result = self . db_query ( sql ) <EOL> if not result : <EOL> sql = """<STR_LIT>""" % entity_id <EOL> result = self . db_query ( sql ) <EOL> defs = [ ] <EOL> for d in result : <EOL> defs . append ( { <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:label>' : self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:description>' : self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> } ) <EOL> return defs <EOL> def get_allowed_parents ( self , entity_id ) : <EOL> """<STR_LIT>""" <EOL> sql = """<STR_LIT>""" % entity_id <EOL> result = self . db_query ( sql ) <EOL> defs = [ ] <EOL> for d in self . db_query ( sql ) : <EOL> defs . append ( { <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:label>' : self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:description>' : self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> } ) <EOL> return defs <EOL> def get_definitions_with_optional_parent ( self , entity_definition_keyname ) : <EOL> """<STR_LIT>""" <EOL> if not entity_definition_keyname : <EOL> return { } <EOL> if entity_definition_keyname : <EOL> if type ( entity_definition_keyname ) is not list : <EOL> entity_definition_keyname = [ entity_definition_keyname ] <EOL> sql = """<STR_LIT>""" % ( self . __user_id , '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % x for x in map ( str , entity_definition_keyname ) ] ) ) <EOL> defs = [ ] <EOL> for d in self . db_query ( sql ) : <EOL> related_entity = self . get_entities ( entity_id = d . get ( '<STR_LIT>' ) , limit = <NUM_LIT:1> ) <EOL> defs . append ( { <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:label>' : self . __get_system_translation ( field = '<STR_LIT:label>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:description>' : self . __get_system_translation ( field = '<STR_LIT:description>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = d . get ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : d . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : related_entity . get ( '<STR_LIT>' ) if related_entity else '<STR_LIT>' , <EOL> } ) <EOL> return defs <EOL> def get_public_paths ( self ) : <EOL> """<STR_LIT>""" <EOL> paths = { } <EOL> for i in self . db_query ( '<STR_LIT>' ) : <EOL> paths [ i . get ( '<STR_LIT>' ) ] = self . __get_system_translation ( field = '<STR_LIT>' , entity_definition_keyname = i . get ( '<STR_LIT>' ) ) <EOL> return paths <EOL> def get_public_path ( self , entity_id ) : <EOL> """<STR_LIT>""" <EOL> path = self . db_query ( """<STR_LIT>""" % entity_id ) <EOL> return path <EOL> def get_menu ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __user_id : <EOL> user_select = """<STR_LIT>""" % { '<STR_LIT>' : self . __user_id , '<STR_LIT>' : self . __language } <EOL> else : <EOL> user_select = """<STR_LIT>""" % { '<STR_LIT>' : self . __language } <EOL> sql = """<STR_LIT>""" % user_select <EOL> menu = { } <EOL> for m in self . db_query ( sql ) : <EOL> menu . setdefault ( m . get ( '<STR_LIT>' ) , { } ) [ '<STR_LIT:label>' ] = m . get ( '<STR_LIT>' ) <EOL> menu . setdefault ( m . get ( '<STR_LIT>' ) , { } ) . setdefault ( '<STR_LIT>' , [ ] ) . append ( { '<STR_LIT>' : m . get ( '<STR_LIT>' ) , '<STR_LIT:title>' : m . get ( '<STR_LIT>' ) } ) <EOL> return sorted ( menu . values ( ) , key = itemgetter ( '<STR_LIT:label>' ) ) <EOL> def findTags ( s , beginning , end ) : <EOL> """<STR_LIT>""" <EOL> if not s : <EOL> return [ ] <EOL> return re . compile ( '<STR_LIT>' % ( beginning , end ) , re . DOTALL ) . findall ( s ) </s>
