def write_archive(self, settings): logging.info("[Blog] Generating Archive") archive = render(self.archive_template_string, {"articles":self.part_article,"settings":self.params}, settings) f = open(settings.get("output")+self.params["archive_file"],"w") f.write(archive.encode('utf8')) f.close()
def teardown(self, settings): logging.debug("[Slide] Teardown") output_content = render(self.slides_template, {"slides":self.slides}, settings) try: f = open(settings.get("output")+"index.html","w") f.write(output_content.encode('utf8')) f.close() except: logging.debug("[Slide] Error when writing index.html on disk.")
def write_rss(self, settings): logging.info("[Blog] Generating RSS") path = settings.get("output")+self.params["rss_path"] if not os.path.exists(path): os.makedirs(path) feed = render(self.rss_template_string, {"articles":self.part_article,"updated":datetime.datetime.now(),"settings":self.params}, settings) f = open(path+self.params["rss_file"],"w") f.write(feed.encode('utf8')) f.close()
def write_page(self, settings): logging.info("[Blog] Writing pages") nb_page = int(math.ceil(len(self.part_article)/float(self.params['nb_per_page']))) current_page = 1 pagination = range(0, len(self.part_article), self.params["nb_per_page"]) for i in pagination: # Gestion de la pagination paginator = {} if current_page < len(pagination): paginator["has_next"] = True paginator["next_page"] = self.params["other_page"]+str(current_page+1) # Uri de la page suivante else: paginator["has_next"] = False if i == 0: paginator["has_previous"] = False else: paginator["has_previous"] = True if current_page-1 == 1: # Premiere page alors on prend la page d'index paginator["previous_page"] = self.params["index_page"] else: # Sinon on genere la page correspondante paginator["previous_page"] = self.params["other_page"]+str(current_page-1) # If one article (or more) on the current set is a new or a modify article we don't skip the current writing # if all("loaded_from_db" in d[0] for d in self.part_article[i:i+self.params["nb_per_page"]]): # # All article in the set are loaded from the db we skip the writing of the current page # # logging.debug("Ignoring writing the pagination number {0}".format(current_page)) # current_page = current_page + 1 # continue # Render the template output output_content = render(self.template_string, {"articles":self.part_article[i:i+self.params["nb_per_page"]], "nb_page":nb_page,"current_page":current_page,"paginator":paginator}, settings) # Generate the name of the current output file. if i == 0: # First iteration # This is the first page of the pagination logging.debug("[Blog] Output to {0}.html".format(self.params["index_page"])) output_file = settings.get("output")+self.params["index_page"]+".html" else: # Other iteration, we take the current page number logging.debug("[Blog] Output to {0}{1}.html".format(self.params["other_page"], current_page)) output_file = settings.get("output")+"{0}{1}.html".format(self.params["other_page"], current_page) # Writing file f = open(output_file,"w") f.write(output_content.encode('utf8')) f.close() current_page = current_page + 1