Example #1
0
def delete_content_block(cid):
    ret = True
    cb = ContentBlock.get_by_id(cid)
    if cb:
        cb.delete()
    else:
        ret = False
    if cb.category in ['header', 'footer']:
        ret = {'reload': True}
    return ret
Example #2
0
def save_content_block(form):
    cb = ContentBlock()
    for b in json.loads(form):
        if b.get('name') == 'cid':
            cb.cid = int(b.get('value'))
        elif b.get('name') == 'title':
            cb.title = b.get('value')
        elif b.get('name') == 'weight':
            cb.weight = int(b.get('value'))
        elif b.get('name') == 'category':
            cb.category = b.get('value')
        elif b.get('name') == 'content':
            cb.content = b.get('value')
    return cb.save()
Example #3
0
def management_section_edit(section_id, args):
    curr_user = auth.current_user.username
    if int(section_id) > 0:
        cb = ContentBlock.get_by_id(int(section_id))
    else:
        cb = ContentBlock()
        cb.cid = 0
        cb.title = 'New block'
        cb.content = ''
        cb.category = args if args else 'block'
        cb.weight = 1
    return bottle.template('./templates/admin_content_detail',
        username=curr_user,
        pathname=bottle.request.path,
        block = cb
    )
Example #4
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])
Example #5
0
def render_index_page():
    return bottle.template('./templates/index',
        header = ContentBlock.get_header(),
        footer = ContentBlock.get_footer(),
        blocks = ContentBlock.get_blocks()
    )
Example #6
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])