lib/templates.py
author fabien@tzone.org
Sun, 28 Dec 2008 12:24:02 -0500
changeset 58 004a32370ba5
parent 51 7015d65beb3d
child 59 2c5e38748004
permissions -rw-r--r--
Correct some bugs and make keywords edition with the new action mechanic.
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
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     3
from os import environ
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     4
7015d65beb3d [svn r1608] Correct the keywords bugs and some other in folder view, plus mutual
fabien
parents: 47
diff changeset
     5
def get_curl():
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     6
	url = "http"
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     7
	if environ["HTTPS"] == 'on':
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     8
		url += "s"
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
     9
	url += "://" + environ["HTTP_HOST"]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    10
	uri = environ["REQUEST_URI"]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    11
	url += uri[:uri.find('?')]
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    12
	return url
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    13
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    14
class Template:
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    15
	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
    16
		self.tproc = TemplateProcessor()
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    17
		self.tmpl = TemplateManager().prepare(template)
58
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    18
    		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
    19
    		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
    20
    		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
    21
    		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
    22
    		self.set("curl", get_curl())
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    23
		self.set("status", status)
004a32370ba5 Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents: 51
diff changeset
    24
		self.set("status_msg", status_msg)
47
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    25
	def set(self, name, variable):
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    26
		self.tproc.set(name, variable)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    27
	def process(self):
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    28
		return self.tproc.process(self.tmpl)
2781ac85b807 [svn r1604] Implement default_view preferences, which move things around a lot.
fabien
parents:
diff changeset
    29