Changeset 23
- Timestamp:
- 01/10/07 17:17:55 (5 years ago)
- Files:
-
- trunk/djangoid/microidutils.py (modified) (1 diff)
- trunk/djangoid/openidhandlers.py (modified) (1 diff)
- trunk/djangoid/runtests.py (added)
- trunk/djangoid/templates/users/accept_root.html (modified) (1 diff)
- trunk/djangoid/users/models.py (modified) (2 diffs)
- trunk/djangoid/users/views.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/djangoid/microidutils.py
r22 r23 87 87 88 88 return ret 89 90 def _test():91 import doctest92 doctest.testmod()93 94 if __name__ == "__main__":95 _test()trunk/djangoid/openidhandlers.py
r10 r23 47 47 48 48 def checkYadisRequest(request): 49 """ 50 Checks whether an incoming django.http.HttpRequest is a YADIS request 51 52 >>> class Request: 53 ... def __init__(self, meta = {}): 54 ... self.META = meta 55 ... 56 >>> request = Request() 57 >>> checkYadisRequest(request) 58 False 59 >>> request = Request({"HTTP_ACCEPT": "text/html"}) 60 >>> checkYadisRequest(request) 61 False 62 >>> request = Request({"HTTP_ACCEPT": "application/xrds+xml"}) 63 >>> checkYadisRequest(request) 64 True 65 """ 49 66 if request.META.has_key("HTTP_ACCEPT"): 50 67 ct = request.META["HTTP_ACCEPT"] 51 if ct.startswith("application/xrds+xml"):68 if "application/xrds+xml" in ct: 52 69 return True 53 70 return False trunk/djangoid/templates/users/accept_root.html
r20 r23 6 6 If you press cancel, you will be returned to {{ openid_request.getCancelURL|escape }}.<br /> 7 7 8 <form method="post" action=" .">8 <form method="post" action=""> 9 9 {% if openid_request.trustRootValid %} 10 10 <input type="checkbox" name="remember" checked="yes" value="yes" /> Remember trunk/djangoid/users/models.py
r19 r23 65 65 66 66 def get_name(self): 67 """ 68 Get a (public) representation of the full name of a user 69 70 >>> user = DjangoidUser(djangouser = "test") 71 >>> user.get_name() 72 'test' 73 """ 67 74 f = None 68 75 l = None … … 85 92 return f + " " + l 86 93 94 def get_attributes(self, public = False): 95 attributes = {} 96 for a in UserAttribute.objects.filter(user = self, public = public): 97 attributes[a.attribute.name] = a.value 98 return attributes 99 100 def get_foaf(self): 101 import sha 102 try: 103 from rdflib.Graph import Graph 104 from rdflib import URIRef, Literal, BNode, Namespace, URIRef 105 from rdflib import RDF 106 except ImportError: 107 raise Exception, "Please install RDFLib from http://rdflib.net" 108 109 FOAF_NS = "http://xmlns.com/foaf/0.1/" 110 111 store = Graph() 112 store.bind("foaf", FOAF_NS) 113 FOAF = Namespace(FOAF_NS) 114 115 user = BNode() 116 attributes = self.get_attributes(True) 117 118 store.add((user, RDF.type, FOAF["Person"])) 119 store.add((user, FOAF["name"], Literal(attributes["FIRST_NAME"] + " " + attributes["LAST_NAME"]))) 120 store.add((user, FOAF["family_name"], Literal(attributes["LAST_NAME"]))) 121 store.add((user, FOAF["nick"], Literal(attributes["NICKNAME"]))) 122 store.add((user, FOAF["homepage"], URIRef(attributes["HOMEPAGE_URI"]))) 123 store.add((user, FOAF["mbox_sha1sum"], Literal(sha.new(attributes["EMAIL"]).hexdigest()))) 124 store.add((user, FOAF["jabberID"], Literal(attributes["IM_JID"]))) 125 126 127 return store 128 129 87 130 class Admin: 88 131 pass trunk/djangoid/users/views.py
r19 r23 39 39 40 40 user = DjangoidUser.objects.get(djangouser = uid) 41 user.attributes = {} 42 for a in UserAttribute.objects.filter(user = user, public = True): 43 user.attributes[a.attribute.name] = a.value 41 user.attributes = user.get_attributes(True) 44 42 mid = microid(user.get_user_page(), user.get_user_page()) 45 43 res = render_to_response("users/userpage.html", {"server_url": settings.BASE_URL[:-1] + urlreverse("djangoid.server.views.endpoint"), "user": user, "microid": mid}) … … 68 66 return convertToHttpResponse(r.answer(True)) 69 67 68 def userfoaf(request, uid): 69 user = DjangoidUser.objects.get(djangouser = uid) 70 return HttpResponse(user.get_foaf().serialize(format = "pretty-xml"))
