def site_verification(previous_version): static.set( "/" + config.google_site_verification, utils.render_template("site_verification.html"), config.html_mime_type, False, )
def generate_resource(cls, post, resource): assert resource == post.path template_vals = { 'post': post } rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource, pagenum=1, start_ts=None): import models q = models.BlogPost.all().order('-published') q.filter('published <', start_ts or datetime.datetime.max) cls._filter_query(resource, q) posts = q.fetch(config.posts_per_page + 1) more_posts = len(posts) > config.posts_per_page path_args = { 'resource': resource, } _get_path = lambda: \ cls.first_page_path if path_args['pagenum'] == 1 else cls.path path_args['pagenum'] = pagenum - 1 prev_page = _get_path() % path_args path_args['pagenum'] = pagenum + 1 next_page = cls.path % path_args template_vals = { 'generator_class': cls.__name__, 'posts': posts[:config.posts_per_page], 'prev_page': prev_page if pagenum > 1 else None, 'next_page': next_page if more_posts else None, } rendered = utils.render_template("listing.html", template_vals) path_args['pagenum'] = pagenum static.set(_get_path() % path_args, rendered, config.html_mime_type) if more_posts: deferred.defer(cls.generate_resource, None, resource, pagenum + 1, posts[-2].published)
def generate_resource(cls, page, resource, action='post'): curr_page = models.Page.get_by_id(resource); if ( curr_page ): # Handle deletion if action == 'delete': static.remove(curr_page.path); curr_page.delete(); return; # Generate a list of links to print a breadcrumb breadcrumb_stack = [] # Start from the first parent parent_page = curr_page.parent_page while ( parent_page ): # Put the current parent page on the stack breadcrumb_stack.append(parent_page) # Move to the parent's parent parent_page = parent_page.parent_page template_vals = { 'page': curr_page, 'breadcrumb_stack' : breadcrumb_stack } rendered = utils.render_template("page.html", template_vals) static.set(curr_page.path, rendered, config.html_mime_type, last_modified=curr_page.updated, type=static.TYPE_PAGE)
def generate_resource(cls, post, resource, pagenum=1, start_ts=None): # Seems that 'post' is not used. Delete? import models q = models.BlogPost.all().order("-published") q.filter("published <", start_ts or datetime.datetime.max) cls._filter_query(resource, q) posts = q.fetch(config.posts_per_page + 1) more_posts = len(posts) > config.posts_per_page path_args = {"resource": resource} _get_path = lambda: cls.first_page_path if path_args["pagenum"] == 1 else cls.path path_args["pagenum"] = pagenum - 1 prev_page = _get_path() % path_args path_args["pagenum"] = pagenum + 1 next_page = cls.path % path_args template_vals = { "generator_class": cls.__name__, "posts": posts[: config.posts_per_page], "prev_page": prev_page if pagenum > 1 else None, "next_page": next_page if more_posts else None, } rendered = utils.render_template("listing.html", template_vals) path_args["pagenum"] = pagenum static.set(_get_path() % path_args, rendered, config.html_mime_type) if more_posts: deferred.defer(cls.generate_resource, None, resource, pagenum + 1, posts[-2].published)
def post(self): import static atom = static.get('/stage/atom.xml') static.set('/feed/atom.xml', atom.body, 'application/atom+xml; charset=utf-8', indexed=False, last_modified=datetime.datetime.now()) self.redirect('/admin/')
def _regenerate_sitemap(): """Regenerate the site map (contains all the paths of the indexed static content), put it on /sitemap.xml and /sitemap.xml.gz and tell Google if required by 'config'.""" import static import gzip from StringIO import StringIO # Get all indexed paths in the list 'paths'. paths = _get_all_paths() # Use the Django 'sitemap.xml' template and fill it with # all indexed paths of the app. rendered = render_template( 'sitemap.xml', {'paths': paths, 'host': config.host} ) # Set the map as SataticContent at /sitemap.xml and don't index it # (to prevent entering an infinite loop). static.set('/sitemap.xml', rendered, 'application/xml', False) # Also gzip it, and set this at /sitemap.xml.gz. s = StringIO() gzip.GzipFile(fileobj=s, mode='wb').write(rendered) s.seek(0) rendrdgz = s.read() static.set('/sitemap.xml.gz', rendrdgz, 'application/x-gzip', False) # If required by 'config', tell Google where we put it. if config.google_sitemap_ping: ping_googlesitemap()
def generate_resource(cls, page, resource, action="post"): # Handle deletion if action == "delete": static.remove(page.path) else: template_vals = {"page": page} rendered = utils.render_template("pages/%s" % (page.template,), template_vals) static.set(page.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource): from models import BlogPost # Query all posts, and filter out drafts. q = BlogPost.all().order("-published") q.filter("published !=", datetime.datetime.max) html = utils.render_template("labnotes.html", {"generator_class": cls.__name__, "posts": q}) static.set("/labnotes", html, config.html_mime_type)
def generate_resource(cls, post, resource): assert resource == "index" import models q = models.BlogPost.all().order('-published') posts = q.fetch(config.posts_per_page) template_vals = { 'posts': posts, } rendered = utils.render_template("listing.html", template_vals) static.set('/', rendered, config.html_mime_type)
def generate_resource(cls, page, resource, action='post'): # Handle deletion if action == 'delete': static.remove(page.path) else: template_vals = { 'page': page, } rendered = utils.render_template('pages/%s' % (page.template,), template_vals) static.set(page.path, rendered, config.html_mime_type, indexed=page.indexed)
def generate_resource(cls, post, resource): import models if not post: post = models.BlogPost.get_by_id(resource) else: assert resource == post.key().id() template_vals = { 'post': post, } rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def regenerate_static_pages(): PAGES = os.path.join(os.path.dirname(__file__), 'pages') for (base, ignore, pages) in os.walk(PAGES): for page in pages: path = re.sub('.*/pages', '', os.path.join('/', base, page).lower()) try: rendered = utils.render_template(path) static.set(re.sub(r'\..*?$', '', path), rendered, config.html_mime_type, True) except Exception as e: logging.warn('could not create page from %s: %s' % (page, str(e)))
def generate_resource(cls, page, resource, action='post'): # Handle deletion if action == 'delete': static.remove(page.path) else: template_vals = { 'page': page, } rendered = utils.render_template('pages/%s' % (page.template, ), template_vals) static.set(page.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource): import models q = models.BlogPost.all().order('-updated') posts = q.fetch(10) template_vals = { 'posts': posts, } rendered = utils.render_template("atom.xml", template_vals) static.set('/feeds/atom.xml', rendered, 'application/atom+xml; charset=utf-8', indexed=False) if config.hubbub_hub_url: cls.send_hubbub_ping(config.hubbub_hub_url)
def generate_resource(cls, post, resource): q = models.BlogDate.all().order('-__key__') dates = [x.date for x in q] date_struct = {} for date in dates: date_struct.setdefault(date.year, []).append(date) str = utils.render_template("archive.html", { 'generator_class': cls.__name__, 'dates': dates, 'date_struct': date_struct.values(), }) static.set('/archive/', str, config.html_mime_type, type=static.TYPE_INDEX);
def generate_resource(cls, post, resource): import models q = models.BlogPost.all().order('-updated') # Fetch the 10 most recently updated non-draft posts posts = list(itertools.islice((x for x in q if x.path), 10)) template_vals = { 'posts': posts, } rendered = utils.render_template("atom.xml", template_vals) static.set('/feeds/atom.xml', rendered, 'application/atom+xml; charset=utf-8', indexed=False) if config.hubbub_hub_url: cls.send_hubbub_ping(config.hubbub_hub_url)
def update_lastpost(): q = models.BlogPost.all().order('-published') q.filter('published !=', datetime.datetime.max)# Filter drafts out post = q.get() postobj = {} postobj['path'] = post.path postobj['title'] = post.title postobj['summary'] = utils.absolutify_url(post.summary) postobj['tag_pairs'] = post.tag_pairs postobj['pubdate'] = post.published.strftime('%B %d, %Y') static.set('/lastpost.json', json.dumps(postobj, indent=4), 'text/plain; charset=utf-8', indexed=False, last_modified=post.published_tz.replace(second=0, microsecond=0))
def generate_resource(cls, post, resource): post = models.BlogPost.get_by_id(resource) if post is None: return template_vals = { 'post': post, } prev, next = cls.get_prev_next(post) if prev is not None: template_vals['prev']=prev if next is not None: template_vals['next']=next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type, last_modified=post.updated, type=static.TYPE_POST)
def generate_resource(cls, post, resource): import models post = models.BlogPost.get_by_id(resource) if post is None: return template_vals = {"post": post, "path": post.path} prev, next = cls.get_prev_next(post) if prev is not None: template_vals["prev"] = prev if next is not None: template_vals["next"] = next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def _regenerate_sitemap(): import static import gzip from StringIO import StringIO paths = _get_all_paths() rendered = render_template('sitemap.xml', {'paths': paths}) static.set('/sitemap.xml', rendered, 'application/xml', False) s = StringIO() gzip.GzipFile(fileobj=s, mode='wb').write(rendered) s.seek(0) renderedgz = s.read() static.set('/sitemap.xml.gz', renderedgz, 'application/x-gzip', False) if config.google_sitemap_ping: ping_googlesitemap()
def _regenerate_sitemap(): import static import gzip from StringIO import StringIO paths = _get_all_paths() rendered = render_template('sitemap.xml', {'paths': paths}) static.set('/sitemap.xml', rendered, 'application/xml', False) s = StringIO() gzip.GzipFile(fileobj=s,mode='wb').write(rendered) s.seek(0) renderedgz = s.read() static.set('/sitemap.xml.gz',renderedgz, 'application/x-gzip', False) if config.google_sitemap_ping: ping_googlesitemap()
def generate_resource(cls, post, resource): import models post = models.BlogPost.get_by_id(resource) if post is None: return template_vals = { 'post': post, } prev, next = cls.get_prev_next(post) if prev is not None: template_vals['prev']=prev if next is not None: template_vals['next']=next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered.encode('utf-8'), config.html_mime_type)
def generate_resource(cls, post, resource): from models import BlogPost # Query all posts, and filter out drafts. q = BlogPost.all().order("-published") q.filter("published !=", datetime.datetime.max) by_year = {} for post in q: by_year.setdefault(post.published.year, []).append(post) html = utils.render_template( "archive.html", {"generator_class": cls.__name__, "by_year": [by_year[y] for y in sorted(by_year, reverse=True)]}, ) static.set("/archive/", html, config.html_mime_type)
def generate_resource(cls, post, resource): import models post = models.BlogPost.get_by_id(resource) if post is None: return template_vals = { 'post': post, } prev, next = cls.get_prev_next(post) if prev is not None: template_vals['prev'] = prev if next is not None: template_vals['next'] = next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource): from models import BlogDate q = BlogDate.all().order('-__key__') dates = [x.date for x in q] date_struct = {} for date in dates: date_struct.setdefault(date.year, []).append(date) str = utils.render_template( "archive.html", { 'generator_class': cls.__name__, 'dates': dates, 'date_struct': date_struct.values(), }) static.set('/archive/', str, config.html_mime_type)
def post(self, id): import os, static, hashlib from models import StoryAuthor, Story, StoryDocument from django.template.defaultfilters import slugify from google.appengine.runtime.apiproxy_errors import RequestTooLargeError content = self.request.get('content') title = self.request.get('title') story = Story.get_by_id(int(id, 10)) story.content = content story.title = title story.put() try: request_document = self.request.get('document') document_file = self.request.POST['document'] if request_document: document_body = document_file.value document_digest = hashlib.sha1(document_body).hexdigest() split_name = os.path.splitext(os.path.basename(document_file.filename)) filename = slugify(split_name[0]) or document_digest document_name = filename + split_name[1] document_path = '/story/%d/document/%s/%s' % (story.key().id(), document_digest, document_name) logging.info(document_path) story_document = StoryDocument(story=story, path=document_path, name=document_name) story_document.put() document = static.set(document_path, document_body, document_file.type) self.get(id) except RequestTooLargeError, message: self.render_to_response("story_edit.html", story=Story.get_by_id(int(id, 10)), request_too_large_error=True)
def generate_resource(cls, post, resource): import models q = models.BlogPost.all().order('-published') # Fetch the 10 most recently updated non-draft posts posts = list(itertools.islice((x for x in q if x.path), 10)) now = datetime.datetime.now().replace(second=0, microsecond=0) template_vals = { 'posts': posts, 'updated': now, } rendered = utils.render_template("atom.xml", template_vals) static.set('/feeds/atom.xml', rendered, 'application/atom+xml; charset=utf-8', indexed=False, last_modified=now) if config.hubbub_hub_url: cls.send_hubbub_ping(config.hubbub_hub_url)
def _regenerate_sitemap(): import static import gzip from StringIO import StringIO static_contents = _get_all_static_content_data() rendered = render_template('sitemap.xml', {'static_contents': static_contents}) static.set('/sitemap.xml', rendered, 'application/xml', indexed=False, type=static.TYPE_OTHER) s = StringIO() gzip.GzipFile(fileobj=s,mode='wb').write(rendered) s.seek(0) renderedgz = s.read() static.set('/sitemap.xml.gz',renderedgz, 'application/x-gzip', indexed=False, type=static.TYPE_OTHER) # Ping Google only if configured to do so and NOT on localhost if ( config.google_sitemap_ping and not (config.host.find("localhost") > -1) ): ping_googlesitemap();
def generate_resource(cls, post, resource, action='post'): import models if not post: post = models.BlogPost.get_by_id(resource) else: assert resource == post.key().id() # Handle deletion if action == 'delete': static.remove(post.path) return template_vals = { 'post': post, 'tags': TagGenerator.get_tags(), 'pages': PagesGenerator.get_pages() } rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource): import models post = models.BlogPost.get_by_id(resource) if post is None: return pages = models.BlogPost.gql("WHERE page = True") template_vals = { 'post': post, 'pages': pages, } prev, next = cls.get_prev_next(post) if prev is not None: template_vals['prev']=prev if next is not None: template_vals['next']=next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource): import models q = models.BlogPost.all().order('-updated') # Fetch the 10 most recently updated non-draft posts posts = list(itertools.islice((x for x in q if x.path), 10)) now = datetime.datetime.now().replace(second=0, microsecond=0) template_vals = { 'posts': posts, 'updated': now, } rendered = utils.render_template("atom.xml", template_vals) static.set('/feeds/atom.xml', rendered, 'application/atom+xml; charset=utf-8', indexed=False, last_modified=now) if config.hubbub_hub_url: cls.send_hubbub_ping(config.hubbub_hub_url)
def generate_resource(cls, post, resource): """ Updates the counts for each tag in a given post. """ import models # resource is the ID of the post. if not post: post = models.BlogPost.get_by_id(resource) else: assert resource == post.key().id() import logging for tag in post.normalized_tags: logging.debug('TagCloudContentGenerator.generate_resource in generators.py, tag = ' + tag) tag_counter = models.TagCounter.get_by_key_name( key_names=str(tag) ) if not tag_counter: tag_counter = models.TagCounter(key_name=str(tag), tagname=str(tag), tagcount=0) tag_counter.tagcount += 1 tag_counter.put() # Build triples of (tag, url, count) by extract the 'tag_cloud_max_size' most popular tags. q = models.TagCounter.all().order('-tagcount') tags_and_counts = list(itertools.islice((x.tag_and_count for x in q if x.tagcount != 0), config.tag_cloud_max_size)) # Calculate font sizes for tags from math import log tags_and_counts_dict=dict(tags_and_counts) logging.debug('TagCloudContentGenerator.generate_resource in generators.py, tags_and_counts_dict = ' + str(tags_and_counts_dict)) min_count = min(tags_and_counts_dict.values()) max_count = max(tags_and_counts_dict.values()) c = log( max_count - (min_count-1) ) / (config.tag_cloud_max_fontsize - config.tag_cloud_min_fontsize or 1) # scaling constant c = c or 1 # Avoid div by zero if min and max are equal. logging.debug('TagCloudContentGenerator.generate_resource in generators.py, min_count = ' + str(min_count) + ', max_count = ' + str(max_count) + ', c = ' + str(c)) tagcloud = [] for tag_name, tag_count in tags_and_counts_dict.items(): size = log( tag_count - (min_count-1) ) / c + config.tag_cloud_min_fontsize tagcloud.append({'tag':tag_name, 'url':tag_name, 'count':tag_count, 'fontsize':round(size)}) # Pass these tag pairs and counts as template variables to the tag cloud template. template_vals = { 'tagcloud': tagcloud, } rendered = utils.render_template('tagcloud.html', template_vals) # Store the tagcloud HTML in the static store undrthe path 'tagcloud'. static.set('tagcloud', rendered, config.html_mime_type, indexed=False)
def generate_resource(cls, post, resource, action="post"): import models if not post: post = models.BlogPost.get_by_id(resource) else: assert resource == post.key().id() # Handle deletion if action == "delete": static.remove(post.path) return template_vals = {"post": post, "path": post.path} prev, next = cls.get_prev_next(post) if prev is not None: template_vals["prev"] = prev if next is not None: template_vals["next"] = next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource, action='post'): import models if not post: post = models.BlogPost.get_by_id(resource) else: assert resource == post.key().id() # Handle deletion if action == 'delete': static.remove(post.path) return template_vals = { 'post': post, } prev, next = cls.get_prev_next(post) if prev is not None: template_vals['prev'] = prev if next is not None: template_vals['next'] = next rendered = utils.render_template("post.html", template_vals) static.set(post.path, rendered, config.html_mime_type)
def generate_resource(cls, post, resource, action='post'): if not post: post = models.BlogPost.get_by_id(resource); else: assert resource == post.key().id(); if ( post ): # Handle deletion if action == 'delete': static.remove(post.path); post.delete(); return; template_vals = { 'post': post }; prev, next = cls.get_prev_next(post); if prev is not None: template_vals['prev'] = prev; if next is not None: template_vals['next'] = next; rendered = utils.render_template("post.html", template_vals); static.set(post.path, rendered, config.html_mime_type, last_modified=post.updated, type=static.TYPE_POST);
def site_verification(previous_version): static.set('/' + config.google_site_verification, utils.render_template('site_verification.html'), config.html_mime_type, False)
def generate(previous_version): for path, template, indexed in pages: rendered = utils.render_template(template) static.set(path, rendered, config.html_mime_type, indexed)