summaryrefslogtreecommitdiff
path: root/patchtracker/Templates.py
blob: bb93eaee4c1171bc04ea45a99c5eead99f5e1145 (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
44
45
46
47
48
49
50
51
52
53
54
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 LetterTocTemplate(OurTemplate):
  def __init__(self, letter, collection):
    self.pkgs = collection
    self.idx = letter
    self.dists = ReleaseList("debian")
    sl = {}
    sl['crumbs'] = [("index/"+letter,"index for "+letter)]
    tpl = os.sep.join([Conf.template_dir, "letter_toc.tmpl"])
    OurTemplate.__init__(self, file=tpl, searchList=sl)

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})