Skip to content
Newer
Older
100644 65 lines (50 sloc) 1.66 KB
c94ebfe Refactored admin code into separate modules
Nicholas Johnson authored
1 import os
2 import re
3 import unicodedata
4
5 from google.appengine.ext import webapp
6 from google.appengine.ext.webapp import template
7
8 import config
9
10
11 def slugify(s):
12 s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore')
13 return re.sub('[^a-zA-Z0-9-]+', '-', s).strip('-')
14
15
16 def format_post_path(post, num):
17 slug = slugify(post.title)
18 if num > 0:
19 slug += "-" + str(num)
20 return config.post_path_format % {
21 'slug': slug,
22 'year': post.published.year,
23 'month': post.published.month,
24 'day': post.published.day,
25 }
26
27
7b5b638 @Arachnid Added andialbrecht's markup language patch.
Arachnid authored
28 def get_template_vals_defaults(template_vals=None):
29 if template_vals is None:
1f6619b Fixed bugs identified by IRC folks
Nicholas Johnson authored
30 template_vals = {}
17e6451 Content generation and dependency system.
Nicholas Johnson authored
31 template_vals.update({
32 'config': config,
abb3287 @Arachnid Added disqus support
Arachnid authored
33 'devel': os.environ['SERVER_SOFTWARE'].startswith('Devel'),
17e6451 Content generation and dependency system.
Nicholas Johnson authored
34 })
7b5b638 @Arachnid Added andialbrecht's markup language patch.
Arachnid authored
35 return template_vals
36
37
38 def render_template(template_name, template_vals=None, theme=None):
39 template_vals = get_template_vals_defaults(template_vals)
40 template_vals.update({'template_name': template_name})
c94ebfe Refactored admin code into separate modules
Nicholas Johnson authored
41 template_path = os.path.join("themes", theme or config.theme, template_name)
1f6619b Fixed bugs identified by IRC folks
Nicholas Johnson authored
42 return template.render(template_path, template_vals)
a3f160d Fixed sitemap regeneration pickling errors
Nicholas Johnson authored
43
44
45 def _get_all_paths():
46 import static
47 keys = []
48 q = static.StaticContent.all(keys_only=True).filter('indexed', True)
49 cur = q.fetch(1000)
50 while len(cur) == 1000:
51 keys.extend(cur)
52 q = static.StaticContent.all(keys_only=True)
53 q.filter('indexed', True)
54 q.filter('__key__ >', cur[-1])
55 cur = q.fetch(1000)
56 keys.extend(cur)
57 return [x.name() for x in keys]
58
59
60 def _regenerate_sitemap():
d920aa8 @Arachnid Fixed missing import. Fixes #26.
Arachnid authored
61 import static
a3f160d Fixed sitemap regeneration pickling errors
Nicholas Johnson authored
62 paths = _get_all_paths()
63 rendered = render_template('sitemap.xml', {'paths': paths})
d920aa8 @Arachnid Fixed missing import. Fixes #26.
Arachnid authored
64 static.set('/sitemap.xml', rendered, 'application/xml', False)
Something went wrong with that request. Please try again.