[Da-tools-commits] ./da-tools/userdir-ldap-cgi-python r19: adding a email addr check function to libformat.

Robin Wittler real at geek-at-work.org
Thu Jan 29 20:09:39 UTC 2009


------------------------------------------------------------
revno: 19
committer: Robin Wittler <real at geek-at-work.org>
branch nick: userdir-ldap-cgi-python
timestamp: Thu 2009-01-29 21:09:39 +0100
message:
  adding a email addr check function to libformat.
  adding hostlinks to the machines template.
  finishing machine the template.
  TODO: calculating the host fingerprint
modified:
  ud_ldap_ng/lib/libformat.py
  ud_ldap_ng/templates/machine.html
  ud_ldap_ng/templates/machines.html
-------------- next part --------------
=== modified file 'ud_ldap_ng/lib/libformat.py'
--- a/ud_ldap_ng/lib/libformat.py	2009-01-25 18:00:02 +0000
+++ b/ud_ldap_ng/lib/libformat.py	2009-01-29 20:09:39 +0000
@@ -9,12 +9,34 @@
 
 compiled_regex_type = type(re.compile(''))
 re_debian_url_markup = re.compile('^(?:\[\[)(.*?)(?:\|(.*?))?(?:\]\])(.*?)$')
+re_email_regex = re.compile('^.*?@.*?\..*?$')
 
 map_dict = {'*': lambda x: x.replace('*', '', 1),
 			'@': lambda x: x.replace('@', '', 1), 
 			'www.d.o': lambda x: x.replace('www.d.o', 'www.debian.org'), 
 			'~': lambda x: x.replace('~', '', 1)}
 
+
+
+def is_email_addr(txt, email_regex=re_email_regex):
+	'''checks if a string is a 'normal' email addr.
+	I know email addresses could be very complex, but this is
+	just a small check. So dont bother me. ;)
+
+	@param txt				the string to check
+	@type txt				str
+	@param email_regex		the email regex use to check
+	@type email_regex		compiled regex
+	@return					bool
+	'''
+	if not type(email_regex) == compiled_regex_type:
+		raise TypeError('email_regex must be type compiled regex')
+	if email_regex.match(txt):
+		return True
+	else:
+		return False
+
+
 def is_markup_string(txt, markup_regex=re_debian_url_markup):
 	'''checks if a string matches the given markup_regex. If so
 	it returns the found markups as tuple or returns False if not.

=== modified file 'ud_ldap_ng/templates/machine.html'
--- a/ud_ldap_ng/templates/machine.html	2009-01-27 20:43:31 +0000
+++ b/ud_ldap_ng/templates/machine.html	2009-01-29 20:09:39 +0000
@@ -43,37 +43,61 @@
 				</div>
 				-->
 				<div id="text">
+					<%! from ud_ldap_ng.lib.libformat import is_email_addr, is_markup_string, is_public, map_chars %>
 					<% 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
-					
+					%for key in sorted((i for i in host if i != 'hostname')):
+					<%
+						values = host.get(key)
+						len_values = len(values)
+					%>
+					% if len_values <= 1:
+					<li><b>${key.capitalize()}:</b>&nbsp;
+						% for value in values:
+							% if is_email_addr(value):
+								<a href="mailto:${value}">${value}</a></li>
+								<% continue %>
+							% endif
+							<% results = is_markup_string(value) %>
+							% if not results:
+								% if is_public(value):
+									${value}</li>
+								% endif
+							%elif is_public(results[0]):
+								% if not results[1]:
+									<a href="http://${map_chars(results[0])}">${map_chars(results[0])}</a>${results[2]}</li>
+								% else:
+									<a href="http://${map_chars(results[0])}">${results[1]}</a>${results[2]}</li>
+								% endif
+							% endif
+						% endfor
+					% else:
+					<li><b>${key.capitalize()}:</b>&nbsp;<ul>
+						% for value in values:
+							% if is_email_addr(value):
+								<li><a href="mailto:${value}">${value}</a></li>
+								<% continue %>
+							% endif
+							<% results = is_markup_string(value) %>
+							% if not results:
+								% if is_public(value):
+									<li>${value}</li>
+								% endif
+							%elif is_public(results[0]):
+								% if not results[1]:
+									<li><a href="http://${map_chars(results[0])}">${map_chars(results[0])}</a>${results[2]}</li>
+								% else:
+									<li><a href="http://${map_chars(results[0])}">${results[1]}</a>${results[2]}</li>
+								% endif
+							% endif
+						% endfor
+					</li></ul>
+					% endif
+					% endfor
 					</ul>
-
-					<!--HIER SOLL DER TEXT HIN!-->
-
 				</div>
 			</div>
 		</div>

=== modified file 'ud_ldap_ng/templates/machines.html'
--- a/ud_ldap_ng/templates/machines.html	2009-01-26 20:20:36 +0000
+++ b/ud_ldap_ng/templates/machines.html	2009-01-29 20:09:39 +0000
@@ -56,7 +56,7 @@
 						<tr>
 							<td>
 								% for hostname in result.get('hostname', ['Unkown',]):
-								${hostname}
+								<a href="/?host=${result.get('host', hostname.split('.')[0])}">${hostname}</a>
 								% endfor
 							</td>
 							% for key in c.attributes[1:]:



More information about the Da-tools-commits mailing list