Guest User

Untitled

a guest
May 27th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Copyright 2011, The Board of Regents of Leland Stanford, Jr. University
  3. # All rights reserved. See LICENSE.
  4. # Author: Christine Williams <christine.bennett.williams@gmail.com>
  5. # Description: Pulls events from database and writes them to disc.
  6.  
  7.  
  8. from Cheetah.Template import Template
  9. from lxml import etree
  10. from pprint import pprint
  11. from optparse import OptionParser
  12. from StringIO import StringIO
  13. import bisect
  14. import datetime
  15. import re
  16. import sys
  17.  
  18. import datastore
  19. import config
  20. import file_manager
  21.  
  22.  
  23. class PostFlipBook:
  24.   """Sets up the flipbooks for posts- yearmonths, tags, all posts."""
  25.   def __init__(self, uri="", pretty_name=""):
  26.     self.uri = uri
  27.     self.pretty_name = pretty_name
  28.     self.posts = []
  29.  
  30.   def render(self, fm, options):
  31.     groups = group(self.posts, 10)
  32.     pagenums = range(len(groups))
  33.     pages = zip([None] + pagenums[:-1], pagenums, pagenums[1:] + [None], groups)
  34.     for next_pg_num, current_pg_num, back_pg_num, posts in pages:
  35.       fm.save(options.output_dir + self.page_uri(current_pg_num), str(Template(file="news-template.tmpl",
  36.               searchList=[{"posts" : posts,
  37.                            "pretty_name": self.pretty_name,
  38.                            "forward_url": next_pg_num is not None and self.page_uri(next_pg_num),
  39.                            "forward_text": "Newer Posts&raquo;",
  40.                            "back_url": back_pg_num is not None and self.page_uri(back_pg_num),
  41.                            "back_text": "Older Posts"}])))
  42.  
  43.   def page_uri(self, current_pg_num):
  44.     if current_pg_num == 0:
  45.       return self.uri
  46.     else:
  47.       path, extension = self.uri.rsplit(".", 1)
  48.       return path + "-" + str(current_pg_num) + "." + extension
  49.  
  50. class FlipbookIndex:
  51.   def __init__(self, yearmonth, categories):
  52.     self.yearmonth = yearmonth
  53.     self.categories = categories
  54.  
  55. def group(lst, n):
  56.   return zip(*[lst[i::n] for i in range(n)])
  57.  
  58. def parse_args(argv):
  59.   """Sets up the option parser and parses command line arguments.
  60.  
  61.  Returns:
  62.    options, args: a pair whose first element is an Options object with settings
  63.    taken from the command line, and whose second element is the remaining
  64.    unparsed arguments on the command line.
  65.  """
  66.   op = OptionParser()
  67.   op.add_option("-o", "--output-dir", dest="output_dir",
  68.                 help="Output generated files under DIR",
  69.                 metavar="DIR",
  70.                 default="/Library/Server/Web/Data/Sites/Default/")
  71.   options, args = op.parse_args(argv[1:])
  72.   if not options.output_dir.endswith("/"):
  73.     options.output_dir += "/"
  74.   return options, args
  75.  
  76.  
  77. def main(argv):
  78.   options, args = parse_args(argv)
  79.   fm = file_manager.FileManager()
  80.   ds = datastore.DataStore("database.db")
  81.  
  82.   start_date = datetime.datetime.now()
  83.   end_date = start_date + datetime.timedelta(31)
  84.  
  85.   # NOTE(scottrw): the list() function is necessary because GetEventsInRange
  86.   # returns a generator, which is exhausted by the first template, leaving no
  87.   # events left for the second template!
  88.   events = list(ds.GetEventsInRange(start_date, end_date))
  89.   all_events = list(ds.GetAllEvents())
  90.   all_posts =  list(ds.GetAllPosts())
  91.  
  92.  
  93.   cal_months = {}
  94.   all_workshop_months = {}
  95.   all_event_months = {}
  96.   for event in all_events:
  97.     cal_months.setdefault(event.calendar_title, {}).setdefault(event.yearmonth(), []).append(event)
  98.     all_event_months.setdefault(event.yearmonth(), []).append(event)
  99.  
  100.   all_posts_fb = PostFlipBook("news-videos/news/index.html", "All Posts")
  101.   for post in all_posts:
  102.     all_posts_fb.posts.append(post)
  103.   all_posts_fb.render(fm, options)
  104.  
  105.  
  106.   calendar_urls = [(name, uri(name)) for name in config.calendar_ids.keys()]
  107.   CalendarFlipBook(calendar_title="Upcoming Events", output_base=options.output_dir + "events/calendar/", landing_page_template="calendar-landing-page.tmpl").WriteUpcomingEvents(options, fm, events)
  108.   CalendarFlipBook(calendar_title="Workshop Calendar", output_base="workshops/calendar/", landing_page_template="workshops-landing-page.tmpl").WriteUpcomingEvents(fm, events, calendar_urls)
  109.   WriteEventPages(options, fm, all_events, calendar_urls)
  110.   WriteIndividualCalendars(options, fm, events, cal_months, calendar_urls, start_date, end_date)
  111.   WritePerMonthCalendars(options, fm, all_event_months, calendar_urls)
  112.   WritePerMonthWorkshopCalendars(options, fm, all_event_months, calendar_urls)
  113.   WritePerCalPerMonthCalendars(options, fm, cal_months, calendar_urls)
  114.   WritePostPages(options, fm, all_posts)
  115.  
  116.   #pprint(sorted(fm.files.keys()))
  117.  
  118.   assert fm.HasFile(options.output_dir + "events/calendar/test-shc-calendar.html")
  119.   assert fm.HasFile(options.output_dir + "workshops/calendar/test-workshop-calendar.html")
  120.   assert fm.HasFile(options.output_dir + "events/calendar/2012-01-test-shc-calendar.html")
  121.   assert fm.HasFile(options.output_dir + "events/calendar/2012-03-test-shc-calendar.html")
  122.   assert fm.HasFile(options.output_dir + "events/calendar/2012-01-test-workshop-calendar.html")
  123.   assert fm.HasFile(options.output_dir + "events/calendar/2012-03-test-workshop-calendar.html")
  124.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-9-all-day-event.html")
  125.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-9-all-day-workshop-event.html")
  126.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-10-location-only-workshop-event.html")
  127.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-10-location-only-event.html")
  128.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-11-multi-day-workshop-event.html")
  129.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-11-multi-day-event.html")
  130.   #assert fm.HasFile(options.output_dir + "events/calendar/2012-1-14-event-to-be-changed.html")
  131.   assert fm.HasFile(options.output_dir + "events/calendar/2012-1-14-workshop-event-to-be-changed.html")
  132.   assert fm.HasFile(options.output_dir + "events/calendar/2012-3-29-far-away-shc-event.html")
  133.   assert fm.HasFile(options.output_dir + "events/calendar/2012-3-30-far-away-workshop-event.html")
  134.  
  135.   shc_test_text = fm.GetFile(options.output_dir + "events/calendar/test-shc-calendar.html")
  136.   dom = etree.HTML(shc_test_text)
  137.   MyAssert(dom.xpath('//title')[0].text,'Test SHC Calendar | Stanford Humanities Center')
  138.   assert dom.xpath('//div[@id = "topnext"]')
  139.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-shc-calendar.html")
  140.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].text, u"Mar 2012\xbb")
  141.   assert dom.xpath('//div[@id = "topback"]')
  142.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-shc-calendar.html")
  143.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].text, u"\xabJan 2012")
  144.   assert dom.xpath('//div[@id = "bottomnext"]')
  145.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-shc-calendar.html")
  146.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].text, u"Mar 2012\xbb")
  147.   assert dom.xpath('//div[@id = "bottomback"]')
  148.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-shc-calendar.html")
  149.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].text, u"\xabJan 2012")
  150.  
  151.   workshop_test_text = fm.GetFile(options.output_dir + "workshops/calendar/test-workshop-calendar.html")
  152.   dom = etree.HTML(workshop_test_text)
  153.   MyAssert(dom.xpath('//title')[0].text, 'Test Workshop Calendar | Stanford Humanities Center')
  154.   assert dom.xpath('//div[@id = "topnext"]')
  155.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-workshop-calendar.html")
  156.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].text, u"Mar 2012\xbb")
  157.   assert dom.xpath('//div[@id = "topback"]')
  158.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-workshop-calendar.html")
  159.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].text, u"\xabJan 2012")
  160.   assert dom.xpath('//div[@id = "bottomnext"]')
  161.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-workshop-calendar.html")
  162.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].text, u"Mar 2012\xbb")
  163.   assert dom.xpath('//div[@id = "bottomback"]')
  164.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-workshop-calendar.html")
  165.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].text, u"\xabJan 2012")
  166.  
  167.   jan_shc_text = fm.GetFile(options.output_dir + "events/calendar/2012-01-test-shc-calendar.html")
  168.   dom = etree.HTML(jan_shc_text)
  169.   MyAssert(dom.xpath('//title')[0].text,'Test SHC Calendar Events For January 2012 | Stanford Humanities Center')
  170.   assert dom.xpath('//div[@id = "topnext"]')
  171.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-shc-calendar.html")
  172.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].text, u"Mar 2012\xbb")
  173.   assert not dom.xpath('//div[@id = "topback"]'), "Expected None, found %r" % dom.xpath('//div[@id = "topback"]')
  174.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-shc-calendar.html")
  175.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].text, u"Mar 2012\xbb")
  176.   assert not dom.xpath('//div[@id = "bottomback"]')
  177.  
  178.  
  179.   mar_shc_text = fm.GetFile(options.output_dir + "events/calendar/2012-03-test-shc-calendar.html")
  180.   dom = etree.HTML(mar_shc_text)
  181.   MyAssert(dom.xpath('//title')[0].text,'Test SHC Calendar Events For March 2012 | Stanford Humanities Center')
  182.   assert not dom.xpath('//div[@id = "topnext"]')
  183.   assert dom.xpath('//div[@id = "topback"]')
  184.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-shc-calendar.html")
  185.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].text, u"\xabJan 2012")
  186.   assert not dom.xpath('//div[@id = "bottomnext"]')
  187.   assert dom.xpath('//div[@id = "bottomback"]')
  188.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-shc-calendar.html")
  189.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].text, u"\xabJan 2012")
  190.  
  191.   jan_workshop_text = fm.GetFile(options.output_dir + "events/calendar/2012-01-test-workshop-calendar.html")
  192.   dom = etree.HTML(jan_workshop_text)
  193.   MyAssert(dom.xpath('//title')[0].text,'Test Workshop Calendar Events For January 2012 | Stanford Humanities Center')
  194.   assert dom.xpath('//div[@id = "topnext"]')
  195.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-workshop-calendar.html")
  196.   MyAssert(dom.xpath('//div[@id = "topnext"]/a')[0].text, u"Mar 2012\xbb")
  197.   assert not dom.xpath('//div[@id = "topback"]')
  198.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].get('href'), "../../events/calendar/2012-03-test-workshop-calendar.html")
  199.   MyAssert(dom.xpath('//div[@id = "bottomnext"]/a')[0].text, u"Mar 2012\xbb")
  200.   assert not dom.xpath('//div[@id = "bottomback"]')
  201.  
  202.   mar_workshop_text = fm.GetFile(options.output_dir + "events/calendar/2012-03-test-workshop-calendar.html")
  203.   dom = etree.HTML(mar_workshop_text)
  204.   MyAssert(dom.xpath('//title')[0].text,'Test Workshop Calendar Events For March 2012 | Stanford Humanities Center')
  205.   assert not dom.xpath('//div[@id = "topnext"]')
  206.   assert dom.xpath('//div[@id = "topback"]')
  207.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-workshop-calendar.html")
  208.   MyAssert(dom.xpath('//div[@id = "topback"]/a')[0].text, u"\xabJan 2012")
  209.   assert not dom.xpath('//div[@id = "bottomnext"]')
  210.   assert dom.xpath('//div[@id = "bottomback"]')
  211.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].get('href'), "../../events/calendar/2012-01-test-workshop-calendar.html")
  212.   MyAssert(dom.xpath('//div[@id = "bottomback"]/a')[0].text, u"\xabJan 2012")
  213.  
  214.   #print fm.show_diff()
  215.   fm.commit()
  216.  
  217. def MyAssert(actual, expected):
  218.   assert actual == expected, "Got %r" % actual
  219.  
  220. class CalendarFlipBook:
  221.   def __init__(self, calendar_title="", output_base="", landing_page_template=""):
  222.     self.calendar_title = calendar_title
  223.     self.output_base = output_base
  224.     self.landing_page_template = landing_page_template
  225.  
  226.   def WriteUpcomingEvents(self, options, fm, events, calendar_urls=None):
  227.     fm.save(self.output_base + "index.html",
  228.             str(Template(file=self.landing_page_template,
  229.                          searchList=[{"events": events,
  230.                                       "calendar_title": self.calendar_title,
  231.                                       "calendar_urls": calendar_urls,
  232.                                       "forward_url": events and events[-1].start_time.strftime('%Y-%m.html'),
  233.                                       "forward_text": events and "All events for %s&raquo" % events[-1].start_time.strftime('%b %Y'),
  234.                                       "back_url": events and events[0].start_time.strftime('%Y-%m.html'),
  235.                                       "back_text": events and "All events for %s" % events[0].start_time.strftime('%b %Y')}])))
  236.  
  237. def WriteUpcomingWorkshops(options, fm, events, calendar_urls):
  238.   fm.save(options.output_dir + "workshops/calendar/index.html",
  239.           str(Template(file="workshop-landing-page.tmpl",
  240.                        searchList=[{"events": events,
  241.                                     "calendar_title": "Workshop Calendar",
  242.                                     "calendar_urls": calendar_urls,
  243.                                     "forward_url": events and events[-1].start_time.strftime('%Y-%m.html'),
  244.                                     "forward_text": events and "All events for %s&raquo" % events[-1].start_time.strftime('%b %Y'),
  245.                                     "back_url": events and events[0].start_time.strftime('%Y-%m.html'),
  246.                                     "back_text": events and "All events for %s" % events[0].start_time.strftime('%b %Y')}])))
  247.  
  248. def WriteEventPages(options, fm, all_events, calendar_urls):
  249.   for event in all_events:
  250.     if event.calendar_title in ("Stanford Humanities Center Events", "Co-sponsored Events Held at the Humanities Center", "Test SHC Calendar"):
  251.       tmpl = "shc_event.tmpl"
  252.     else:
  253.       tmpl = "workshop_event.tmpl"
  254.     fm.save(options.output_dir + event.uri(),
  255.             str(Template(file=tmpl,
  256.                          searchList=[{"event": event,
  257.                                       "calendar_title": event.calendar_title,
  258.                                       "calendar_urls": calendar_urls,
  259.                                       "forward_url": None,
  260.                                       "forward_text": None,
  261.                                       "back_url": None,
  262.                                       "back_text": None}])))
  263.  
  264. def WriteIndividualCalendars(options, fm, events, cal_months, calendar_urls, start_date, end_date):
  265.   events_by_calendar = {}
  266.   for cal_id in config.calendar_ids.iterkeys():
  267.     events_by_calendar[cal_id] = []
  268.   for e in events:
  269.     events_by_calendar[e.calendar_title].append(e)
  270.   for calendar_name, calendar_events in events_by_calendar.iteritems():
  271.     if calendar_name in ("Stanford Humanities Center Events", "Co-sponsored Events Held at the Humanities Center", "Test SHC Calendar"):
  272.       tmpl = "calendar-landing-page.tmpl"
  273.     else:
  274.       tmpl = "workshop-landing-page.tmpl"
  275.     if not calendar_events:
  276.       all_events = cal_months.get(calendar_name, None)
  277.       if not all_events:
  278.         forward_url = None
  279.         forward_text = None
  280.         back_url = None
  281.         back_text = None
  282.       else:
  283.         months = all_events.keys()
  284.         months.sort()
  285.         back_index = max(0, min(bisect.bisect_left(months, start_date), len(months) - 1) - 1)
  286.         next_index = min(bisect.bisect_left(months, start_date), len(months) - 1)
  287.         back_date = months[back_index]
  288.         next_date = months[next_index]
  289.         forward_url = "../../" + month_uri(next_date, calendar_name)
  290.         forward_text = next_date.strftime('%b %Y') + "&raquo;"
  291.         back_url = "../../" + month_uri(back_date, calendar_name)
  292.         back_text = back_date.strftime('%b %Y')
  293.     else:
  294.       forward_url = "../../" + month_uri(calendar_events[-1].start_time, calendar_name)
  295.       forward_text = calendar_events[-1].start_time.strftime('%b %Y') + "&raquo;"
  296.       back_url = "../../" + month_uri(calendar_events[0].start_time, calendar_name)
  297.       back_text = calendar_events[0].start_time.strftime('%b %Y')
  298.     fm.save(options.output_dir + uri(calendar_name),
  299.             str(Template(file=tmpl,
  300.                          searchList=[{"events": calendar_events,
  301.                                       "calendar_title": calendar_name,
  302.                                       "calendar_urls": calendar_urls,
  303.                                       "back_url": back_url,
  304.                                       "back_text": back_text,
  305.                                       "forward_url": forward_url,
  306.                                       "forward_text": forward_text}])))
  307.  
  308.  
  309. def WritePerMonthCalendars(options, fm, all_event_months, calendar_urls):
  310.   month_events = sorted(all_event_months.items())
  311.   months = [month for month, events in month_events]
  312.   for (yearmonth, events), back, forward in zip(month_events,
  313.                                                 [None] + months[:-1],
  314.                                                 months[1:] + [None]):
  315.     calendar_title = yearmonth.strftime("Events Calendar for %B %Y")
  316.     #Render a calendar template into the right file
  317.     fm.save(options.output_dir + yearmonth.strftime("events/calendar/%Y-%m.html"),
  318.             str(Template(file="calendar-landing-page.tmpl",
  319.                          searchList=[{"events": events,
  320.                                       "calendar_title": calendar_title,
  321.                                       "back_url": back and back.strftime('%Y-%m.html'),
  322.                                       "back_text": back and back.strftime ('%b %Y'),
  323.                                       "forward_url": forward and forward.strftime('%Y-%m.html'),
  324.                                       "forward_text": forward and forward.strftime('%b %Y') + "&raquo;",
  325.                                       "calendar": calendar_title}])))
  326.  
  327. def WritePerMonthWorkshopCalendars(options, fm, all_event_months, calendar_urls):
  328.   month_events = sorted(all_event_months.items())
  329.   months = [month for month, events in month_events]
  330.   for (yearmonth, events), back, forward in zip(month_events,
  331.                                                 [None] + months[:-1],
  332.                                                 months[1:] + [None]):
  333.     calendar_title = yearmonth.strftime("Workshop Calendar for %B %Y")
  334.     #Render a calendar template into the right file
  335.     fm.save(options.output_dir + yearmonth.strftime("workshops/calendar/%Y-%m.html"),
  336.             str(Template(file="workshop-landing-page.tmpl",
  337.                          searchList=[{"events": events,
  338.                                       "calendar_title": calendar_title,
  339.                                       "calendar_urls": calendar_urls,
  340.                                       "back_url": back and back.strftime('%Y-%m.html'),
  341.                                       "back_text": back and back.strftime ('%b %Y'),
  342.                                       "forward_url": forward and forward.strftime('%Y-%m.html'),
  343.                                       "forward_text": forward and forward.strftime('%b %Y') + "&raquo;",
  344.                                       "calendar": calendar_title}])))
  345.  
  346. def WritePerCalPerMonthCalendars(options, fm, cal_months, calendar_urls):
  347.   for calendar, all_event_months in cal_months.iteritems():
  348.     month_events = sorted(all_event_months.items())
  349.     months = [month for month, events in month_events]
  350.     for (yearmonth, events), back, forward in zip(month_events,
  351.                                                   [None] + months[:-1],
  352.                                                   months[1:] + [None]):
  353.       calendar_title = calendar + " Events For " + yearmonth.strftime("%B %Y")
  354.       #Render a calendar template into the right file
  355.       if calendar in ("Stanford Humanities Center Events", "Co-sponsored Events Held at the Humanities Center", "Test SHC Calendar"):
  356.         tmpl = "calendar-landing-page.tmpl"
  357.       else:
  358.         tmpl = "workshop-landing-page.tmpl"
  359.       fm.save(options.output_dir + month_uri(yearmonth, calendar),
  360.               str(Template(file=tmpl,
  361.                            searchList=[{"events": events,
  362.                                         "calendar_title": calendar_title,
  363.                                         "calendar_urls": calendar_urls,
  364.                                         "back_url": back and "../../" + month_uri(back, calendar),
  365.                                         "back_text": back and back.strftime('%b %Y'),
  366.                                         "forward_url": forward and "../../" + month_uri(forward, calendar),
  367.                                         "forward_text": forward and forward.strftime('%b %Y') + "&raquo;",
  368.                                         "calendar": calendar}])))
  369.  
  370. def month_uri(yearmonth, calendar):
  371.   return yearmonth.strftime("events/calendar/%%Y-%%m-%s.html" % friendly_title(calendar))
  372.  
  373. def uri(calendar_title):
  374.   if calendar_title == "Stanford Humanities Center Events":
  375.     return "events/calendar/%s.html" % (friendly_title(calendar_title))
  376.   elif calendar_title == "Co-sponsored Events Held at the Humanities Center":
  377.     return "events/calendar/%s.html" % (friendly_title(calendar_title))
  378.   elif calendar_title == "Test SHC Calendar":
  379.     return "events/calendar/%s.html" % (friendly_title(calendar_title))
  380.   elif calendar_title == "Test Workshop Calendar":
  381.     return "workshops/calendar/%s.html" % (friendly_title(calendar_title))
  382.   else:
  383.     return "workshops/calendar/%s.html" % (friendly_title(calendar_title))
  384.  
  385.  
  386. def friendly_title(calendar_title):
  387.   title = re.sub(" +", "-", calendar_title.lower())
  388.   title = re.sub("[^-a-z0-9]", "", title)
  389.   return title
  390.  
  391.  
  392. def WritePostPages(options, fm, all_posts):
  393.   for post in all_posts:
  394.     tmpl = "post-template.tmpl"
  395.     fm.save(options.output_dir + post.uri(),
  396.             str(Template(file=tmpl,
  397.                          searchList=[{"post" : post,
  398.                                       "title": post.title,
  399.                                       "published" : post.published,
  400.                                       "content" : post.content,
  401.                                       "categories" : post.categories}])))
  402.  
  403.  
  404. if __name__ == "__main__":
  405.   main(sys.argv)
Add Comment
Please, Sign In to add comment