lib/templates.py
author fabien@tzone.org
Tue, 30 Dec 2008 23:16:05 -0500
changeset 66 a0aa025ee6a2
parent 63 8f246bc7059d
child 69 d79722064d8d
permissions -rw-r--r--
New version with tester.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
     1
from htmltmpl import TemplateManager, TemplateProcessor
51
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     2
from urlparse import urljoin
59
2c5e38748004 Move templates inside their own directory.
fabien@tzone.org
parents: 58
diff changeset
     3
from os import environ, path
63
8f246bc7059d Move template_dir inside config.
Fabien Ninoles <fabien@tzone.org>
parents: 59
diff changeset
     4
from config import template_dir
51
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     5
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     6
def get_curl():
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     7
	url = "http"
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     8
	if environ["HTTPS"] == 'on':
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     9
		url += "s"
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    10
	url += "://" + environ["HTTP_HOST"]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    11
	uri = environ["REQUEST_URI"]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    12
	url += uri[:uri.find('?')]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    13
	return url
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    14
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    15
class Template:
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    16
	def __init__(self, template, prefs, status = "msg", status_msg = ""):
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    17
		self.tproc = TemplateProcessor()
63
8f246bc7059d Move template_dir inside config.
Fabien Ninoles <fabien@tzone.org>
parents: 59
diff changeset
    18
		self.tmpl = TemplateManager().prepare(path.join(template_dir, template))
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    19
    		self.set("remote_user", prefs["fullname"])
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    20
    		self.set("kw_size", prefs['keywords_box'])
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    21
    		self.set("kw_sort", prefs['keywords_sort'])
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    22
    		self.set("kw_reverse", prefs['keywords_reverse'])
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    23
    		self.set("curl", get_curl())
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    24
		self.set("status", status)
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    25
		self.set("status_msg", status_msg)
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    26
	def set(self, name, variable):
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    27
		self.tproc.set(name, variable)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    28
	def process(self):
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    29
		return self.tproc.process(self.tmpl)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    30