def queue_index_actions(blog, include_manual=False): ''' Pushes to the publishing queue all the index pages for a given blog that are marked for Immediate publishing. :param blog: The blog object whose index templates will be pushed to the queue. :param include_manual: If set to True, all templates, including those set to the Manual publishing mode, will be pushed to the queue. Default is False, since those templates are not pushed in most publishing actions. ''' templates = blog.index_templates.select().where( Template.publishing_mode != publishing_mode.do_not_publish) if include_manual is False: templates = templates.select().where( Template.publishing_mode == publishing_mode.immediate) if templates.count() == 0: raise Template.DoesNotExist( "No valid index templates exist for blog {}.".format(blog.for_log)) mappings = TemplateMapping.select().where( TemplateMapping.template << templates) fileinfos = FileInfo.select().where(FileInfo.template_mapping << mappings) for f in fileinfos: Queue.push(job_type=job_type.index, priority=1, blog=blog, site=blog.site, data_integer=f.id)
def build_indexes_fileinfos(templates): ''' Rebuilds a fileinfo entry for a given main index. This will need to be run every time we create a new index type, or change a mapping. (Most of these should have a 1:1 mapping) A control message should not be needed, since these are 1:1 This will port the code currently found in build_blog_fileinfo, much as the above function did. ''' n = 0 for template in templates: n += 1 index_mappings = TemplateMapping.select().where( TemplateMapping.template == template) blog = index_mappings[0].template.blog tags = template_tags(blog_id=blog.id) for i in index_mappings: path_string = tpl(tpl_oneline(i.path_string), **tags.__dict__) if path_string == '': continue master_path_string = path_string add_page_fileinfo(None, i, master_path_string, blog.url + "/" + master_path_string, blog.path + '/' + master_path_string) return n
def queue_index_actions(blog): ''' Pushes to the publishing queue all the index pages for a given blog that are marked for Immediate publishing. ''' try: templates = Template.select().where( Template.blog == blog, Template.template_type == template_type.index, Template.publishing_mode == publishing_mode.immediate) if templates.count() == 0: raise Template.DoesNotExist except Template.DoesNotExist: raise Template.DoesNotExist( "No index templates exist for blog {}.".format(blog.for_log)) else: mappings = TemplateMapping.select().where( TemplateMapping.template << templates) fileinfos = FileInfo.select().where( FileInfo.template_mapping << mappings) for f in fileinfos: push_to_queue(job_type=job_type.index, priority=1, blog=blog, site=blog.site, data_integer=f.id)
def queue_index_actions(blog, include_manual=False): ''' Pushes to the publishing queue all the index pages for a given blog that are marked for Immediate publishing. :param blog: The blog object whose index templates will be pushed to the queue. :param include_manual: If set to True, all templates, including those set to the Manual publishing mode, will be pushed to the queue. Default is False, since those templates are not pushed in most publishing actions. ''' templates = blog.index_templates.select().where( Template.publishing_mode != publishing_mode.do_not_publish) if include_manual is False: templates = templates.select().where( Template.publishing_mode == publishing_mode.immediate) if templates.count() == 0: raise Template.DoesNotExist("No valid index templates exist for blog {}.".format( blog.for_log)) mappings = TemplateMapping.select().where(TemplateMapping.template << templates) fileinfos = FileInfo.select().where(FileInfo.template_mapping << mappings) for f in fileinfos: Queue.push(job_type=job_type.index, priority=1, blog=blog, site=blog.site, data_integer=f.id)
def export_theme_for_blog(blog_id): from core.models import Template, TemplateMapping, KeyValue theme_to_export = Template.select().where( Template.blog == blog_id) theme = {} theme["title"] = theme_to_export[0].theme.title theme["description"] = theme_to_export[0].theme.description theme["data"] = {} for n in theme_to_export: theme["data"][n.id] = {} theme["data"][n.id]["template"] = json_dump(n) mappings_to_export = TemplateMapping.select().where( TemplateMapping.template == n) theme["data"][n.id]["mapping"] = {} for m in mappings_to_export: theme["data"][n.id]["mapping"][m.id] = json_dump(m) theme["kv"] = {} kv_list = [] top_kvs = KeyValue.select().where( KeyValue.object == 'Theme', KeyValue.objectid == theme_to_export[0].theme.id, KeyValue.is_schema == True) for n in top_kvs: kv_list.append(n) while len(kv_list) > 0: theme["kv"][kv_list[0].id] = json_dump(kv_list[0]) next_kvs = KeyValue.select().where( KeyValue.parent == kv_list[0], KeyValue.is_schema == True) for f in next_kvs: kv_list.append(f) del kv_list[0] import settings with open(settings.APPLICATION_PATH + settings._sep + "install" + settings._sep + "templates.json", "w", encoding='utf-8') as output_file: output_file.write(json.dumps(theme, indent=1, sort_keys=True, allow_nan=True)) return theme
def build_indexes_fileinfos(templates): ''' Rebuilds a fileinfo entry for a given main index. This will need to be run every time we create a new index type, or change a mapping. (Most of these should have a 1:1 mapping) A control message should not be needed, since these are 1:1 This will port the code currently found in build_blog_fileinfo, much as the above function did. :param templates: A list of templates, typically for main indexes, to rebuild fileinfo entries for. ''' for n, template in enumerate(templates): index_mappings = TemplateMapping.select().where( TemplateMapping.template == template) blog = index_mappings[0].template.blog tags = template_tags(blog_id=blog.id) for i in index_mappings: path_string = replace_mapping_tags(i.path_string) path_string = eval(path_string, tags.__dict__) if path_string == '' or path_string is None: continue # why are we doing this twice? # path_string = replace_mapping_tags(path_string) # raise Exception(path_string) master_path_string = path_string add_page_fileinfo(None, i, master_path_string, blog.url + "/" + master_path_string, blog.path + '/' + master_path_string) try: return n + 1 except Exception: return 0