Ejemplo n.º 1
0
    def load_content(self):
        content_data = self.__read_csv("content")
        localized_content_data = self.__read_csv("content_localized")
        contentblocks_data = self.__read_csv("content_blocks")
        style_sys_data = self.__read_csv("system_style")[0]

        #load style
        ## READ STYLE
        style = SystemStyle()
        self.__fill_members_with_csv_data(
            style, ('fg_color', 'bg_color', 'hl_color', 'ch_color', 'icon',
                    'custom_marker'), style_sys_data)

        #load content
        self.content = {}
        for item in content_data:
            c = Content()
            self.__fill_members_with_csv_data(
                c, ('content_id', 'name', 'image_name', 'tags', 'category'),
                item)
            c.tags = c.tags.split(',')  #split tags
            c.category = int(c.category)  #parse category to int
            c.style = style

            self.content[c.content_id] = c  #add to content items

        #load localized info
        for item in localized_content_data:
            lang = LocalizedContentInformation()
            self.__fill_members_with_csv_data(
                lang, ('content_id', 'language', 'title', 'description'), item)

            #add to right content
            if self.content.has_key(item[0]):
                self.content[item[0]].localized_content_information[
                    item[1]] = lang
            else:
                logging.warn(
                    "Localized Content Data with invalid content id: " +
                    item[0])

        #load content blocks
        for item in contentblocks_data:
            #they have to be parsed in a special way,because they vary in terms of fields
            b = ContentBlock()
            b.content_id = item[0]
            b.content_block_type = int(item[2])
            b.public = string_to_bool(item[3])

            if b.content_block_type == ContentBlockTypes.TEXT:
                b.title = item[4]
                b.text = item[5]
            elif b.content_block_type == ContentBlockTypes.AUDIO:
                b.title = item[4]
                b.artists = item[5]
                b.file_id = item[6]
            elif b.content_block_type == ContentBlockTypes.VIDEO:
                b.title = item[4]
                b.youtube_url = item[5]
            elif b.content_block_type == ContentBlockTypes.IMAGE:
                b.title = item[4]
                b.file_id = item[5]
                b.scale_x = float(item[6])
                b.alt_text = item[7]
            elif b.content_block_type == ContentBlockTypes.LINK:
                b.title = item[4]
                b.text = item[5]
                b.link_type = int(item[6])
                b.link_url = item[7]
            elif b.content_block_type == ContentBlockTypes.EBOOK:
                b.title = item[4]
                b.artists = item[5]
                b.file_id = item[6]
            elif b.content_block_type == ContentBlockTypes.CONTENT:
                b.title = item[4]
                b.content_id = item[5]
            elif b.content_block_type == ContentBlockTypes.SOUNDCLOUD:
                b.title = item[4]
                b.soundcloud_url = item[5]
            elif b.content_block_type == ContentBlockTypes.DOWNLOAD:
                b.title = item[4]
                b.text = item[5]
                b.download_type = int(item[6])
                b.file_id = item[7]
            elif b.content_block_type == ContentBlockTypes.SPOTMAP:
                b.title = item[4]
                b.spot_map_tag = item[5]
            else:
                raise Exception("Unknown Content Block Type: " +
                                str(b.content_block_type))

            #add to right content and lang
            if self.content.has_key(item[0]):
                if self.content[item[0]].localized_content_information.has_key(
                        item[1]):
                    self.content[item[0]].localized_content_information[
                        item[1]].content_blocks.append(b)
                else:
                    logging.warn("Content Block Data with invalid lang: " +
                                 item[0] + "/" + item[1])
            else:
                logging.warn("Content Block Data with invalid content id: " +
                             item[0])
Ejemplo n.º 2
0
 def load_content(self):
     content_data = self.__read_csv("content")
     localized_content_data = self.__read_csv("content_localized")
     contentblocks_data = self.__read_csv("content_blocks")
     style_sys_data = self.__read_csv("system_style")[0]
     
     #load style
     ## READ STYLE
     style = SystemStyle()
     self.__fill_members_with_csv_data(style,('fg_color','bg_color','hl_color','ch_color','icon','custom_marker'),style_sys_data)
     
     #load content
     self.content = {}
     for item in content_data:
         c = Content()
         self.__fill_members_with_csv_data(c,('content_id','name','image_name','tags','category'),item)
         c.tags = c.tags.split(',') #split tags
         c.category = int(c.category) #parse category to int
         c.style = style
     
         self.content[c.content_id] = c #add to content items
     
     #load localized info
     for item in localized_content_data:
         lang = LocalizedContentInformation()
         self.__fill_members_with_csv_data(lang,('content_id','language','title','description'),item)
         
         #add to right content
         if self.content.has_key(item[0]):
             self.content[item[0]].localized_content_information[item[1]] = lang
         else:
             logging.warn("Localized Content Data with invalid content id: " + item[0])
             
     #load content blocks
     for item in contentblocks_data:
         #they have to be parsed in a special way,because they vary in terms of fields
         b = ContentBlock()
         b.content_id = item[0]
         b.content_block_type = int(item[2])
         b.public = string_to_bool(item[3])
         
         if b.content_block_type == ContentBlockTypes.TEXT:
             b.title = item[4]
             b.text = item[5]
         elif b.content_block_type == ContentBlockTypes.AUDIO:
             b.title = item[4]
             b.artists = item[5]
             b.file_id = item[6]
         elif b.content_block_type == ContentBlockTypes.VIDEO:
             b.title = item[4]
             b.youtube_url = item[5]
         elif b.content_block_type == ContentBlockTypes.IMAGE:
             b.title = item[4]
             b.file_id = item[5]
             b.scale_x = float(item[6])
             b.alt_text = item[7]
         elif b.content_block_type == ContentBlockTypes.LINK:
             b.title = item[4]
             b.text = item[5]
             b.link_type = int(item[6])
             b.link_url = item[7]
         elif b.content_block_type == ContentBlockTypes.EBOOK:
             b.title = item[4]
             b.artists = item[5]
             b.file_id = item[6]
         elif b.content_block_type == ContentBlockTypes.CONTENT:
             b.title = item[4]
             b.content_id = item[5]
         elif b.content_block_type == ContentBlockTypes.SOUNDCLOUD:
             b.title = item[4]
             b.soundcloud_url = item[5]
         elif b.content_block_type == ContentBlockTypes.DOWNLOAD:
             b.title = item[4]
             b.text = item[5]
             b.download_type = int(item[6])
             b.file_id = item[7]
         elif b.content_block_type == ContentBlockTypes.SPOTMAP:
             b.title = item[4]
             b.spot_map_tag = item[5]
         else:
             raise Exception("Unknown Content Block Type: " + str(b.content_block_type))
             
         #add to right content and lang
         if self.content.has_key(item[0]):
             if self.content[item[0]].localized_content_information.has_key(item[1]):
                 self.content[item[0]].localized_content_information[item[1]].content_blocks.append(b)
             else:
                 logging.warn("Content Block Data with invalid lang: " + item[0] + "/" + item[1])
         else:
             logging.warn("Content Block Data with invalid content id: " + item[0])