[CalendarServer-changes] [8079] CalendarServer/branches/users/glyph/other-html/twistedcaldav/ directory

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 13 12:10:36 PDT 2011


Revision: 8079
          http://trac.macosforge.org/projects/calendarserver/changeset/8079
Author:   glyph at apple.com
Date:     2011-09-13 12:10:36 -0700 (Tue, 13 Sep 2011)
Log Message:
-----------
pixel-perfect for principal portion at least

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/directory-principal-resource.html
    CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/principal.py

Modified: CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/directory-principal-resource.html
===================================================================
--- CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/directory-principal-resource.html	2011-09-13 19:10:28 UTC (rev 8078)
+++ CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/directory-principal-resource.html	2011-09-13 19:10:36 UTC (rev 8079)
@@ -3,33 +3,34 @@
     <h1>Principal Details</h1>
     <pre><blockquote>Directory Information
 ---------------------
-Directory GUID: <t:slot name="directoryGUID"></t:slot>
-Realm: <t:slot name="realm"></t:slot>
-Hosted-At: <t:slot name="hostedAt"></t:slot>
-Partition: <t:slot name="partition"></t:slot>
-
+Directory GUID: <t:slot name="directoryGUID"/>
+Realm: <t:slot name="realm"/>
+<t:transparent t:render="serversEnabled">Hosted-At: <t:slot name="hostedAt"/>
+Partition: <t:slot name="partition"/></t:transparent>
 Principal Information
 ---------------------
-GUID: <t:slot name="principalGUID"></t:slot>
-Record type: <t:slot name="recordType"></t:slot>
-Short names: <t:slot name="shortNames"></t:slot>
-Security Identities: <t:slot name="securityIDs"></t:slot>
-Full name: <t:slot name="fullName"></t:slot>
-First name: <t:slot name="firstName"></t:slot>
-Last name: <t:slot name="lastName"></t:slot>
+GUID: <t:slot name="principalGUID"/>
+Record type: <t:slot name="recordType"/>
+Short names: <t:slot name="shortNames"/>
+Security Identities: <t:slot name="securityIDs"/>
+Full name: <t:slot name="fullName"/>
+First name: <t:slot name="firstName"/>
+Last name: <t:slot name="lastName"/>
 Email addresses:
-Principal UID: <t:slot name="principalUID"></t:slot>
-Principal URL: <t:slot name="principalURL"></t:slot>
+<t:slot name="emailAddresses" />Principal UID: <t:slot name="principalUID"/>
+Principal URL: <t:slot name="principalURL"/>
 
 Alternate URIs:
-<t:slot name="alternateURIs"></t:slot>
+<t:slot name="alternateURIs"/>
 Group members:
-<t:slot name="groupMembers"></t:slot>)
+<t:slot name="groupMembers"/>
 Group memberships:
-<t:slot name="groupMemberships"></t:slot>Read-write Proxy For:
-<t:slot name="readWriteProxyFor"></t:slot>
+<t:slot name="groupMemberships"/>
+Read-write Proxy For:
+<t:slot name="readWriteProxyFor"/>
 Read-only Proxy For:
-<t:slot name="readOnlyProxyFor"></t:slot><t:transparent
+<t:slot name="readOnlyProxyFor"/>
+<t:transparent
 t:render="extra"><t:transparent t:render="enabledForCalendaring">
 Calendar Homes:
 <t:slot name="calendarHomes" />

Modified: CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/principal.py	2011-09-13 19:10:28 UTC (rev 8078)
+++ CalendarServer/branches/users/glyph/other-html/twistedcaldav/directory/principal.py	2011-09-13 19:10:36 UTC (rev 8079)
@@ -518,6 +518,20 @@
 
 
     @renderer
+    def serversEnabled(self, request, tag):
+        """
+        Renderer for when servers are enabled.
+        """
+        if not config.Servers.Enabled:
+            return ""
+        record = self.resource.record
+        return tag.fillSlots(
+            hostedAt=str(record.serverURI()),
+            partition=str(record.effectivePartitionID()),
+        )
+
+
+    @renderer
     def principal(self, request, tag):
         """
         Top-level renderer in the template.
@@ -526,10 +540,6 @@
         return tag.fillSlots(
             directoryGUID=str(record.service.guid),
             realm=str(record.service.realmName),
-            hostedAt=str(record.serverURI()
-                         if config.Servers.Enabled else ""),
-            partition=str(record.effectivePartitionID()
-                          if config.Servers.Enabled else ""),
             principalGUID=str(record.guid),
             recordType=str(record.recordType),
             shortNames=",".join(record.shortNames),
@@ -537,48 +547,27 @@
             fullName=str(record.fullName),
             firstName=str(record.firstName),
             lastName=str(record.lastName),
+            emailAddresses=formatList(record.emailAddresses),
             principalUID=str(self.resource.principalUID()),
-            principalURL=self.formatLink(self.resource.principalURL()),
-            alternateURIs=self.formatList(
-                self.formatLink(u) for u in self.resource.alternateURIs()
+            principalURL=formatLink(self.resource.principalURL()),
+            alternateURIs=formatList(
+                formatLink(u) for u in self.resource.alternateURIs()
             ),
             groupMembers=self.resource.groupMembers().addCallback(
-                self.formatPrincipals
+                formatPrincipals
             ),
             groupMemberships=self.resource.groupMemberships().addCallback(
-                self.formatPrincipals
+                formatPrincipals
             ),
             readWriteProxyFor=self.resource.proxyFor(True).addCallback(
-                self.formatPrincipals
+                formatPrincipals
             ),
             readOnlyProxyFor=self.resource.proxyFor(False).addCallback(
-                self.formatPrincipals
+                formatPrincipals
             ),
         )
 
 
-    def formatPrincipals(self, principals):
-        """
-        Format a list of principals into some twisted.web.template DOM objects.
-        """
-        return '<Principals Placeholder: ' + str(principals) + '>'
-
-
-    def formatList(self, iterable):
-        """
-        Format a list of stuff as an interable.
-        """
-        return '<List Placeholder: ' + str(iterable) + '>'
-
-
-    def formatLink(self, url):
-        """
-        Convert a URL string into some twisted.web.template DOM objects for
-        rendering as a link to itself.
-        """
-        return tags.a(href=url)(url)
-
-
     @renderer
     def extra(self, request, tag):
         """
@@ -1215,6 +1204,68 @@
     ),
 )
 
+
+def formatPrincipals(principals):
+    """
+    Format a list of principals into some twisted.web.template DOM objects.
+    """
+    def recordKey(principal):
+        try:
+            record = principal.record
+        except AttributeError:
+            try:
+                record = principal.parent.record
+            except:
+                return None
+        return (record.recordType, record.shortNames[0])
+
+    def describe(principal):
+        if hasattr(principal, "record"):
+            return " - %s" % (principal.record.fullName,)
+        else:
+            return ""
+
+    return formatList(
+        tags.a(href=principal.principalURL())(
+            str(principal), describe(principal)
+        )
+        for principal in sorted(principals, key=recordKey)
+    )
+
+
+def formatList(iterable):
+    """
+    Format a list of stuff as an interable.
+    """
+    thereAreAny = False
+    try:
+        item = None
+        for item in iterable:
+            thereAreAny = True
+            yield " -> "
+            if item is None:
+                yield "None"
+            else:
+                yield item
+            yield "\n"
+    except Exception, e:
+        log.err("Exception while rendering: %s" % (e,))
+        Failure().printTraceback()
+        yield "  ** %s **: %s\n" % (e.__class__.__name__, e)
+    if not thereAreAny:
+        yield " '()\n"
+
+
+
+def formatLink(url):
+    """
+    Convert a URL string into some twisted.web.template DOM objects for
+    rendering as a link to itself.
+    """
+    return tags.a(href=url)(url)
+
+
+
 def format_list(items, *args):
     def genlist():
         try:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110913/28794993/attachment-0001.html>


More information about the calendarserver-changes mailing list