def get_content_by_location_identifier(self, request): db = CSVDataProvider() system = check_auth(self, request, db) language = request.language.split('-')[0] #initialize response response = EndUserScanResponseMessage() #get marker marker = db.get_marker(request.location_identifier) #get spot connected to marker spot = db.get_spot(marker.spot_id) #get content content = db.get_content_by_id(spot.content) content_message = content.to_enduser_message(language, system, full=True) #set status flags #on the CSV backend both always have to be true response.has_spot = bool_to_string(True) response.has_content = bool_to_string(True) #get system name system_name = system.name l_infos = system.localized_information for info in l_infos: #try to find selected language if info.language == content_message.language: system_name = info.display_name #get settings settings = db.get_settings() response.app_id_google_play = settings[1] response.app_id_itunes = settings[0] #render message response.system_name = system_name response.system_url = system.base_url #not needed in apps or wordpress response.system_id = 1 #always 1, because this is single tenant response.content = content_message #render message if string_to_bool(request.include_style): response.style = content.style.to_enduser_message() if string_to_bool(request.include_menu): response.menu = db.get_menu().to_enduser_message( content_message.language, system, db) return response
def get_content_by_location_identifier(self, request): db = CSVDataProvider() system = check_auth(self,request,db) language = request.language.split('-')[0] #initialize response response = EndUserScanResponseMessage() #get marker marker = db.get_marker(request.location_identifier) #get spot connected to marker spot = db.get_spot(marker.spot_id) #get content content = db.get_content_by_id(spot.content) content_message = content.to_enduser_message(language, system, full=True) #set status flags #on the CSV backend both always have to be true response.has_spot = bool_to_string(True) response.has_content = bool_to_string(True) #get system name system_name = system.name l_infos = system.localized_information for info in l_infos: #try to find selected language if info.language == content_message.language: system_name = info.display_name #get settings settings = db.get_settings() response.app_id_google_play = settings[1] response.app_id_itunes = settings[0] #render message response.system_name = system_name response.system_url = system.base_url #not needed in apps or wordpress response.system_id = 1 #always 1, because this is single tenant response.content = content_message #render message if string_to_bool(request.include_style): response.style = content.style.to_enduser_message() if string_to_bool(request.include_menu): response.menu = db.get_menu().to_enduser_message(content_message.language, system, db) return response
def get_content_list(self, request): db = CSVDataProvider() system = check_auth(self, request, db) request.language = request.language.split('-')[0] cursor = request.cursor if hasattr( request, 'cursor') and request.cursor != None else 0 if cursor == 'null': cursor = '0' cursor = int(cursor) page_size = int(request.page_size) if hasattr( request, 'page_size' ) and request.page_size != None and request.page_size <= 100 else 10 tags = request.tags if hasattr(request, 'tags') else None tags = None if tags == 'null' else tags contents, next_curs, more = db.query_content_by_tags( tags, cursor, page_size) content_items = [ content_item.to_enduser_message(request.language, system, full=False) for content_item in contents ] return EnduserContentListResponseMessage(items=content_items, cursor=str(next_curs), more=bool_to_string(more))
def sql_handle(sql_exec, sql_filter, args): if args is None: args = {} strs = sql_exec.split(" ") for i in range(len(strs)): if strs[i].startswith("$"): strs[i] = strs[i][1:] ops = strs[i].split(".") if len(ops) != 2: abort(parm.ERR_ADMIN, message="sql format:%s error, please contact admin." % strs[i]) if ops[1] not in op_format: abort(parm.ERR_ADMIN, message="sql op format:%s error, please contact admin." % strs[i]) if ops[0] not in sql_filter: abort( parm.ERR_ADMIN, message="sql filter:%s not complete, please contact admin." % ops[0]) item = sql_filter[ops[0]] if item not in args: abort(parm.ERR_USER, message="user filter:%s not complete." % item) field = ops[0] op = op_format[ops[1]] value = args[item] # type int if type(value) == int: strs[i] = '%s%s%d' % (field, op, value) # type bool elif type(value) == bool: strs[i] = '%s%s%s' % (field, op, bool_to_string(value)) # type none elif value is None: strs[i] = '%s%s%s' % (field, op, 'NULL') # type string else: # ensure value is a single word, to avoid hack if ensure_single_word(value) is not True: abort(parm.ERR_USER, message="value of user filter:%s not valid." % item) strs[i] = '%s%s\'%s\'' % (field, op, value) res = " ".join(strs) return res
def sql_handle_filter(format_filter, sql_where): if sql_where is None: decode_sql_where = {} else: decode_sql_where = json.loads(sql_where) strs = format_filter.split(" ") for i in range(len(strs)): if strs[i].startswith("$"): strs[i] = strs[i][1:] ops = strs[i].split(".") if len(ops) != 2: abort(parm.ERR_ADMIN, message="sql format:%s error, please contact admin." % strs[i]) if ops[1] not in op_format: abort(parm.ERR_ADMIN, message="sql format:%s error, please contact admin." % strs[i]) if ops[0] not in sql_where: abort(parm.ERR_USER, message="filter:%s not complete." % ops[0]) field = ops[0] op = op_format[ops[1]] value = decode_sql_where[ops[0]] # type int if type(value) == int: strs[i] = '%s%s%d' % (field, op, value) # type bool elif type(value) == bool: strs[i] = '%s%s%s' % (field, op, bool_to_string(value)) # type none elif value is None: strs[i] = '%s%s%s' % (field, op, 'NULL') # type string else: # ensure value is a single word, to avoid hack if ensure_single_word(value) is not True: abort(parm.ERR_USER, message="value of user filter:%s not valid." % value) strs[i] = '%s%s\'%s\'' % (field, op, value) res = " ".join(strs) return res
def to_integration_message(self): message = IntegrationContentBlock() if self.content_block_type == ContentBlockTypes.TEXT: message.title = self.title message.text = self.text elif self.content_block_type == ContentBlockTypes.AUDIO: message.title = self.title message.artists = self.artists message.file_id = file_dir + self.file_id elif self.content_block_type == ContentBlockTypes.VIDEO: message.title = self.title message.video_url = self.youtube_url elif self.content_block_type == ContentBlockTypes.IMAGE: message.title = self.title message.file_id = file_dir + self.file_id if self.link_url == None: message.link_url = "" else: if self.link_url.startswith('http://') == False and self.link_url.startswith('https://') == False: message.link_url = "http://" + self.link_url else: message.link_url = self.link_url if hasattr(self,"scale_x") and self.scale_x != None: message.scale_x = self.scale_x if hasattr(self,"alt_text") and self.alt_text != None: message.alt_text = self.alt_text elif self.content_block_type == ContentBlockTypes.LINK: message.title = self.title message.text = self.text message.link_type = self.link_type #add special link type prefixes if self.link_type == ContentLinkTypes.EMAIL and self.link_url.startswith('mailto:') == False: message.link_url = "mailto:" + self.link_url elif self.link_type == ContentLinkTypes.TEL and self.link_url.startswith('tel:') == False: message.link_url = "tel:" + self.link_url elif self.link_type != ContentLinkTypes.TEL and self.link_type != ContentLinkTypes.EMAIL: if self.link_url.startswith('http://') == False and self.link_url.startswith('https://') == False: message.link_url = "http://" + self.link_url else: message.link_url = self.link_url else: message.link_url = self.link_url elif self.content_block_type == ContentBlockTypes.EBOOK: message.title = self.title message.artists = self.artists message.file_id = file_dir + self.file_id elif self.content_block_type == ContentBlockTypes.CONTENT: message.title = self.title message.content_id = self.content_id elif self.content_block_type == ContentBlockTypes.SOUNDCLOUD: message.title = self.title message.soundcloud_url = self.soundcloud_url elif self.content_block_type == ContentBlockTypes.DOWNLOAD: message.title = self.title message.text = self.text message.download_type = self.download_type message.file_id = file_dir + self.file_id elif self.content_block_type == ContentBlockTypes.SPOTMAP: message.title = self.title message.spot_map_tag = self.spot_map_tag else: logging.error('Invalid Content Block Type in Entity! ' + str(self.content_block_type)) message.content_block_type = self.content_block_type message.public = bool_to_string(self.public) return message
def query_content(self, request): db = CSVDataProvider() system = check_auth(self,request,db) cursor = int(request.cursor) if hasattr(request, 'cursor') and request.cursor != None else 0 page_size = int(request.page_size) if hasattr(request, 'page_size') and request.page_size != None and request.page_size <= 100 else 10 sort_direction = request.sort_direction if hasattr(request, 'sort_direction') and request.sort_direction != None else 'ASC' contents, next_curs, more = db.query_content(request.ft_query,cursor,page_size,sort_direction) content_items = [content_item.to_integration_message(system) for content_item in contents] return IntegrationContentListResponseMessage(items=content_items, cursor=str(next_curs), has_more=bool_to_string(more))
def get_content_list(self, request): db = CSVDataProvider() system = check_auth(self,request,db) request.language = request.language.split('-')[0] cursor = request.cursor if hasattr(request, 'cursor') and request.cursor != None else 0 if cursor == 'null': cursor = '0' cursor = int(cursor) page_size = int(request.page_size) if hasattr(request, 'page_size') and request.page_size != None and request.page_size <= 100 else 10 tags = request.tags if hasattr(request, 'tags') else None tags = None if tags == 'null' else tags contents, next_curs, more = db.query_content_by_tags(tags,cursor,page_size) content_items = [content_item.to_enduser_message(request.language, system, full=False) for content_item in contents] return EnduserContentListResponseMessage(items=content_items, cursor=str(next_curs), more=bool_to_string(more))