Skip to content
Newer
Older
100644 60 lines (47 sloc) 1.51 KB
c94ebfe Refactored admin code into separate modules
Nicholas Johnson authored Oct 8, 2009
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
28 def render_template(template_name, template_vals=None, theme=None):
1f6619b Fixed bugs identified by IRC folks
Nicholas Johnson authored Oct 15, 2009
29 if not template_vals:
30 template_vals = {}
17e6451 Content generation and dependency system.
Nicholas Johnson authored Oct 9, 2009
31 template_vals.update({
c8d437d @Arachnid Added menu items on admin pages. Fixes #6.
Arachnid authored Oct 17, 2009
32 'template_name': template_name,
17e6451 Content generation and dependency system.
Nicholas Johnson authored Oct 9, 2009
33 'config': config,
abb3287 @Arachnid Added disqus support
Arachnid authored Oct 15, 2009
34 'devel': os.environ['SERVER_SOFTWARE'].startswith('Devel'),
17e6451 Content generation and dependency system.
Nicholas Johnson authored Oct 9, 2009
35 })
c94ebfe Refactored admin code into separate modules
Nicholas Johnson authored Oct 8, 2009
36 template_path = os.path.join("themes", theme or config.theme, template_name)
1f6619b Fixed bugs identified by IRC folks
Nicholas Johnson authored Oct 15, 2009
37 return template.render(template_path, template_vals)
a3f160d Fixed sitemap regeneration pickling errors
Nicholas Johnson authored Oct 23, 2009
38
39
40 def _get_all_paths():
41 import static
42 keys = []
43 q = static.StaticContent.all(keys_only=True).filter('indexed', True)
44 cur = q.fetch(1000)
45 while len(cur) == 1000:
46 keys.extend(cur)
47 q = static.StaticContent.all(keys_only=True)
48 q.filter('indexed', True)
49 q.filter('__key__ >', cur[-1])
50 cur = q.fetch(1000)
51 keys.extend(cur)
52 return [x.name() for x in keys]
53
54
55 def _regenerate_sitemap():
d920aa8 @Arachnid Fixed missing import. Fixes #26.
Arachnid authored Oct 23, 2009
56 import static
a3f160d Fixed sitemap regeneration pickling errors
Nicholas Johnson authored Oct 23, 2009
57 paths = _get_all_paths()
58 rendered = render_template('sitemap.xml', {'paths': paths})
d920aa8 @Arachnid Fixed missing import. Fixes #26.
Arachnid authored Oct 23, 2009
59 static.set('/sitemap.xml', rendered, 'application/xml', False)
Something went wrong with that request. Please try again.