community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r923283 - in /comdev/nearby_people: nearby/foaf.py nearby/templatetags/emails.py templates/people.html
Date Mon, 15 Mar 2010 15:17:47 GMT
Author: nick
Date: Mon Mar 15 15:17:44 2010
New Revision: 923283

URL: http://svn.apache.org/viewvc?rev=923283&view=rev
Log:
Display people's email address in the popup info box, but in a way that spiders probably won't
grok

Added:
    comdev/nearby_people/nearby/templatetags/emails.py   (with props)
Modified:
    comdev/nearby_people/nearby/foaf.py
    comdev/nearby_people/templates/people.html

Modified: comdev/nearby_people/nearby/foaf.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/nearby/foaf.py?rev=923283&r1=923282&r2=923283&view=diff
==============================================================================
--- comdev/nearby_people/nearby/foaf.py (original)
+++ comdev/nearby_people/nearby/foaf.py Mon Mar 15 15:17:44 2010
@@ -65,31 +65,34 @@ class FOAF(object):
             #print uri
 
             if uri.startswith(PEOPLE_FOAF_NAMESPACE):
-                file = os.path.join(PEOPLE_FOAF_PATH, uri.replace(PEOPLE_FOAF_NAMESPACE,""))
-                self._parse_foaf(file)
+                relfile = uri.replace(PEOPLE_FOAF_NAMESPACE,"")
+                file = os.path.join(PEOPLE_FOAF_PATH, relfile)
+                self._parse_foaf(file, relfile)
             else:
-                usock = urllib.urlopen(uri) 
-                self._parse_foaf(usock)                              
+                usock = urllib.urlopen(uri)
+                self._parse_foaf(usock, uri)
                 usock.close()        
                 
         self.updated_at = datetime.datetime.utcnow()
         
-    def _parse_foaf(self, file):
+    def _parse_foaf(self, data, filename):
         surname = None
         name = None
         uid  = None
         lat  = None
         long = None
+        email = None
         projects = []
         depiction = None
         weblogs = []
             
-        foaf = parse(file)
+        foaf = parse(data)
         surnameN = foaf.getElementsByTagNameNS(NS_FOAF,"family_name")
         nameN = foaf.getElementsByTagNameNS(NS_FOAF,"name")
         longN = foaf.getElementsByTagNameNS(NS_GEO,"long")
         latN  = foaf.getElementsByTagNameNS(NS_GEO,"lat")
         uidN = foaf.getElementsByTagNameNS(NS_FOAF,"Person")
+        emailN = foaf.getElementsByTagNameNS(NS_FOAF,"mbox")
         currentProjectsN = foaf.getElementsByTagNameNS(NS_FOAF,"currentProject")
         depictionN = foaf.getElementsByTagNameNS(NS_FOAF,"depiction")
         weblogsN = foaf.getElementsByTagNameNS(NS_FOAF,"weblog")
@@ -107,6 +110,22 @@ class FOAF(object):
         if depictionN:
             depiction = depictionN[0].getAttribute("rdf:resource")
 
+        # If we got an explicit email, use the first
+        if emailN:
+            attr = emailN[0].getAttribute("rdf:resource")
+            if attr:
+                email = attr.replace("mailto:","")
+            else:
+                email = emailN[0].firstChild.data
+        else:
+            # Did we get their avail ID?
+            if uid:
+                email = "%s@apache.org" % uid
+            else:
+                # If it's not remote, then files are <avail id>.rdf
+                if not filename.startswith("http"):
+                    email = "%s@apache.org" % filename.split(".")[0]
+
         # People are funny about their lat and long
         if lat:
             if lat.endswith("N"):
@@ -146,7 +165,8 @@ class FOAF(object):
         # Finish building up
         if name and surname and uid and lat and long:
             self.people[name] = {
-                "name": name, "surname": surname, "uid":uid, 
+                "name": name, "surname": surname, 
+                "uid":uid, "email": email,
                 "latitude": lat, "longitude": long, "projects": projects,
                 "avatar": depiction, "weblogs": weblogs
             }

Added: comdev/nearby_people/nearby/templatetags/emails.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/nearby/templatetags/emails.py?rev=923283&view=auto
==============================================================================
--- comdev/nearby_people/nearby/templatetags/emails.py (added)
+++ comdev/nearby_people/nearby/templatetags/emails.py Mon Mar 15 15:17:44 2010
@@ -0,0 +1,43 @@
+# ====================================================================
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ====================================================================
+
+from django import template
+from django.template.defaultfilters import stringfilter
+
+from django.utils.html import conditional_escape
+from django.utils.safestring import mark_safe
+
+register = template.Library()
+
+def format_email(email, autoescape):
+   if autoescape:
+      email = conditional_escape(email)
+
+   at = email.find("@")
+   if at > 0:
+      partA = email[0:at]
+      partB = email[(at+1):]
+      email = "%s &#0065;&#0084; %s" % (partA, partB)
+   return mark_safe( email )
+
+
+# As a filter
+@register.filter
+@stringfilter
+def emailformat(value, autoescape=None):
+    return format_email(value, autoescape)
+emailformat.needs_autoescape = True

Propchange: comdev/nearby_people/nearby/templatetags/emails.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: comdev/nearby_people/templates/people.html
URL: http://svn.apache.org/viewvc/comdev/nearby_people/templates/people.html?rev=923283&r1=923282&r2=923283&view=diff
==============================================================================
--- comdev/nearby_people/templates/people.html (original)
+++ comdev/nearby_people/templates/people.html Mon Mar 15 15:17:44 2010
@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load distances %}
+{% load emails %}
 
 {% block title %}People Near You{% endblock %}
 {% block heading %}People Near You{% endblock %}
@@ -40,7 +41,7 @@ $(document).ready(function(){
             {% endfor %}
             marker = createMarker("{{person.name}}",{{person.latitude}},
                          {{person.longitude}},"{{person.link}}", projectNames,
-                         "{{person.avatar}}");
+                         "{{person.avatar}}","{{person.email|emailformat}}");
             map.addOverlay(marker);
             markers["{{person.uid}}"] = marker;
         {% endfor %}
@@ -57,7 +58,7 @@ $(document).ready(function(){
     }
 });
 
-function createMarker(name,lat,lng,link,projects,avatar) {
+function createMarker(name,lat,lng,link,projects,avatar,email) {
 	var point = new GLatLng(lat,lng);
     var options = { title: name }; // appears when cursor hovers over marker
     var marker = new GMarker(point,options);
@@ -71,6 +72,9 @@ function createMarker(name,lat,lng,link,
     	  msg = msg + "<li>" + projects[i] + "</li>";
     	};
       msg = msg + " </ul>";
+      if (email != "None") {
+          msg = msg + "<div>Email: <i>" + email + "</i></div>";
+      }
       msg = msg + " <a href=\"" + link + "\">" +
                   "<small>Info<\/small><\/a>"; 
       marker.openInfoWindowHtml(msg);



Mime
View raw message