[Da-tools-commits] ./da-tools/userdir-ldap-cgi-python r18: Added machine template

Robin Wittler real at geek-at-work.org
Tue Jan 27 20:43:31 UTC 2009


------------------------------------------------------------
revno: 18
committer: Robin Wittler <real at geek-at-work.org>
branch nick: userdir-ldap-cgi-python
timestamp: Tue 2009-01-27 21:43:31 +0100
message:
  Added machine template
  Added a __getitem__ and a next method to the DebianLDAPResult Class.
  For the protocol: mako template engine sucks! Next commits will be with the jinja or genshi template engine.
added:
  ud_ldap_ng/templates/machine.html
modified:
  ud_ldap_ng/controllers/udldapng.py
  ud_ldap_ng/lib/libldap.py
-------------- next part --------------
=== modified file 'ud_ldap_ng/controllers/udldapng.py'
--- a/ud_ldap_ng/controllers/udldapng.py	2009-01-26 22:13:43 +0000
+++ b/ud_ldap_ng/controllers/udldapng.py	2009-01-27 20:43:31 +0000
@@ -18,6 +18,17 @@
 
 class UdldapngController(BaseController):
 	def index(self):
+		if request.params.get('host', None):
+			return self.host(request.params.get('host'))
+		else:
+			return self.hosts()
+
+	def host(self, hostname):
+		con = AnonymousDebianLDAP()
+		c.result = con.getDebianHost(hostname)
+		return render('/machine.html')
+
+	def hosts(self):
 		con = AnonymousDebianLDAP()
 		c.attributes = ['hostname', 'architecture', 'purpose', 'sponsor', 'status']
 		c.sortorders = {u'asc': False, u'dsc': True}

=== modified file 'ud_ldap_ng/lib/libldap.py'
--- a/ud_ldap_ng/lib/libldap.py	2009-01-26 22:13:43 +0000
+++ b/ud_ldap_ng/lib/libldap.py	2009-01-27 20:43:31 +0000
@@ -44,6 +44,8 @@
 			raise TypeError('adjust must be typ bool')
 		cls.__original_results = results
 		cls.__results = cls.alterDNFromResults(results)
+		cls.__next_counter = 0
+		cls.__max_counter = len(cls.__results)
 		if adjust:
 			cls.adjusted = True
 			cls.__results = cls.adjustResults(cls.__results, default_value=default_value)
@@ -188,6 +190,15 @@
 		return iter(cls.__original_results)
 	
 	@classmethod
+	def next(cls):
+		if cls.__next_counter < cls.__max_counter:
+			cls.__next_counter += 1
+			return cls.__getitem__(cls.__next_counter-1)
+		else:
+			raise StopIteration
+
+
+	@classmethod
 	def  __iter__(cls):
 		'''returns the debian ldap result as iterator.
 
@@ -197,6 +208,10 @@
 			yield result
 		#return iter(cls.__results)
 
+	@classmethod
+	def __getitem__(cls, index):
+		return cls.__results[index]
+
 class MyLDAP(object):
 	'''This is a simple wrapper around ldap.
 	There are some Methods added to questioning the ldap for some values.'''
@@ -323,7 +338,7 @@
 		'''
 		if not getattr(self, 'con', None):
 			raise Exception('You must call the "connect" Method before.')
-		if not type(dn) == str:
+		if not type(dn) == str and not type(dn) == unicode:
 			raise TypeError('dn must be type str')
 		if not type(scope) == int:
 			raise TypeError('scope must be type int')

=== added file 'ud_ldap_ng/templates/machine.html'
--- a/ud_ldap_ng/templates/machine.html	1970-01-01 00:00:00 +0000
+++ b/ud_ldap_ng/templates/machine.html	2009-01-27 20:43:31 +0000
@@ -0,0 +1,83 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
+<html>
+	<head>
+		<title>template.html</title>
+		<!-- <link rel="stylesheet" type="text/css" href="/styles" /> -->
+		<meta http-equiv="content-type" content="text/html;charset=ISO-8859-15" />
+		<meta name="author" content="Martin Zobel-Helas" />
+		<meta name="generator" content="Vim" />
+		<meta name="date" content="Fri Jan  9 23:12:55 CET 2009" />
+		<link href="template.css" rel="stylesheet" type="text/css" />
+	</head>
+	<body>
+		<div id="navcontainer">
+			<ul id="navlist">
+				<li><a href="developer/">Developer</a></li>
+				<li><a href="machines/">Machines</a></li>
+				<li id="active"><a href="documentation/" id="current">Documentation</a></li>
+				<li><a href="https://rt.debian.org/">Request Tracker</a></li>
+			</ul>
+		</div>
+		<div id="loginbar">
+			<!--foo-->
+		</div>
+           	<div id="content">
+			<div class="wrapper">
+				<!--
+				<div id="side">
+					<div id="navcontainer">
+						<ul id="navlist_side">
+							Mail:
+							<li><a href="#mail_forwarding">Email Forwarding</a></li>
+							<li><a href="#procmail">procmail</a></li>
+							<li><a href="#mailbox_formats">MailBox formats</a></li>
+						</ul>
+						<ul id="navlist_side">
+							Access:
+							<li><a href="#">Password</a></li>
+							<li><a href="#">SSH-Key</a></li>
+						</ul>
+					</div>
+				</div>
+				-->
+				<div id="text">
+					<% host = c.result.next() %>
+					% for hostname in host.get('hostname', ['Unknown Hostname',]):
+					<h1>Information about ${hostname}</h1>
+					% endfor
+					<ul>
+						%for key in sorted((i for i in host if i != 'hostname')):
+							% if key in ('sponsor', 'purpose'):
+								<li><b>${key.capitalize()}:</b>&nbsp;<ul>
+								<%! from ud_ldap_ng.lib.libformat import is_markup_string, is_public, map_chars %>
+								% for value in host.get(key):
+									<% results = is_markup_string(value) %>
+									% if not results:
+										% if is_public(value):
+											${value}<br/>
+										% endif
+									% elif not results[1]:
+										<a href="http://${map_chars(results[0])}">${map_chars(results[0])}</a>${results[2]}<br/>
+									% else:
+										<a href="http://${map_chars(results[0])}">${results[1]}</a>${results[2]}<br/>
+									% endif
+								% endfor
+							</li><br/></ul>
+							<% continue %>
+							% endif
+							<li><b>${key.capitalize()}:</b>&nbsp;${', '.join(host.get(key))}</li><br/>
+						% endfor
+					
+					</ul>
+
+					<!--HIER SOLL DER TEXT HIN!-->
+
+				</div>
+			</div>
+		</div>
+
+	</body>
+</html>
+



More information about the Da-tools-commits mailing list