All pastes #1989228 Raw Edit

awilcox

public python v1 · immutable
#1989228 ·published 2010-11-12 16:51 UTC
rendered paste body
def render(template_file = 'index.tmpl', params = None):        search_list = dict()        # get site name - if not defined, use default        try:                site = settings.SITE_NAME        except NameError:                site = 'pyWebStats Engine on {DOMAIN}'        search_list['site'] = site.format(                        VERSION = core.version_string,                        DOMAIN = os.getenv('SERVER_NAME','?')                        )        search_list['vers'] = core.version_string        # get all sites (support vhosts or a set of multiple servers' logs)        years = os.listdir(settings.LOG_DIRECTORY)        sites = list()        for year in years:                # Thank you Elizabeth.                year_list = os.listdir(settings.LOG_DIRECTORY+year)                index = 0                length = len(year_list)                 while index != length:                        if year_list[index] in sites:                                del year_list[index]                                length -= 1                                continue                        sites.append(year_list[index])                        index += 1        # silly fleshy creatures like things in alphabetical order        sites.sort()        search_list['sites'] = sites        # template-specific parameters, if specified        if params is not None:                search_list.update(params)        try:                t = Template(file=settings.TEMPLATE_DIR+template_file, searchList = search_list)        except IOError:                if settings.DEBUG:                        raise WebStatsInternalError('Template {t} is not found'.format(t = template_file))                else:                        return pretty_error("The requested page's template was not found.  Contact the site administrator for assistance.")        return t.respond()