summaryrefslogtreecommitdiff
path: root/patchtracker/Templates.py
blob: ea6667ae4ef23b50d00df2692bf16a882840f77b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from patchtracker import Conf
from patchtracker.SourceArchive import ReleaseList

from Cheetah.Template import Template
from Cheetah.Compiler import Compiler
import os, errno
import re

class OurTemplate(Template):
  def __init__(self, file, searchList=None):
    ourSearchList={"conf":Conf, "crumbs":[]}
    if searchList:
      for k,v in searchList.iteritems():
        ourSearchList[k]=v
    self.link = self._link
    Template.__init__(self, file=file, searchList=ourSearchList)

  def _link(self, where, name):
    return str("<a href=\"%s\">%s</a>"%(where,name))

class FrontPageTemplate(OurTemplate):
  def __init__(self, indices):
    tpl = os.sep.join([Conf.template_dir, "frontpage.tmpl"])
    OurTemplate.__init__(self, file=tpl)
    self.indices = indices

class SearchResultsTemplate(OurTemplate):
  def __init__(self, search, searchtype, collection):
    self.pkgs = {}
    self.idx = search
    self.searchtype = searchtype
    self.dists = ReleaseList("debian")
    for idx in collection.indices():
      for name,packagelist in collection.getletter(idx).iteritems():
        self.pkgs[name] = packagelist
    tpl = os.sep.join([Conf.template_dir, "searchresults.tmpl"])
    OurTemplate.__init__(self, file=tpl)

class ErrorTemplate(OurTemplate):
  def __init__(self, msg):
    tpl = os.sep.join([Conf.template_dir, "cgi_error.tmpl"])
    OurTemplate.__init__(self, file=tpl, searchList={'error':msg})