[CalendarServer-changes] [7962] CalendarServer/branches/users/glyph/imip-and-admin-html/ calendarserver/webadmin/resource.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:51:46 PDT 2011


Revision: 7962
          http://trac.macosforge.org/projects/calendarserver/changeset/7962
Author:   glyph at apple.com
Date:     2011-08-11 21:51:46 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
pull non-HTML-rendering things out of htmlContent in preparation for eliminating it

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/calendarserver/webadmin/resource.py

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/calendarserver/webadmin/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/calendarserver/webadmin/resource.py	2011-08-12 04:51:34 UTC (rev 7961)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/calendarserver/webadmin/resource.py	2011-08-12 04:51:46 UTC (rev 7962)
@@ -445,17 +445,62 @@
                  "<body>\n"
                  "<div style=\"padding-left:10px; padding-right:10px\">\n" % { "title": title, "style": self.directoryStyleSheet() })
 
+
     def footer(self) :
         return ( "\n</div>\n"
                  "</body>\n"
                  "</html>" )
-              
+
+
     @inlineCallbacks
-    def htmlContent(self, directory, request):
+    def htmlContent(self, request):
 
         def queryValue(arg):
             return request.args.get(arg, [""])[0]
 
+        # Read request parameters.
+        resourceId = queryValue("resourceId")
+        resourceSearch = queryValue("resourceSearch")
+        davPropertyName = queryValue("davPropertyName")
+        proxySearch = queryValue("proxySearch")
+
+        # Begin the content
+        content = (
+            "%(header)s\n"
+            "<h2>Resource Management</h2>\n"
+            "%(search)s\n" %
+            {
+                "header": self.header(None),
+                "search": (yield self.searchContent(self.directory,
+                                                    resourceSearch))
+            }
+        )
+
+        # Add details if a resource has been selected.
+        if resourceId:
+            principal = self.getResourceById(request, resourceId)
+            yield self.resourceActions(request, principal)
+            # Add the detailed content
+            content += (yield self.detailContent(
+                self.directory, request, principal, resourceId, davPropertyName,
+                proxySearch)
+            )
+
+        # Add the footer
+        content += self.footer()
+
+        returnValue(content)
+
+
+    @inlineCallbacks
+    def resourceActions(self, request, principal):
+        """
+        Take all actions on the given principal based on the given request.
+        """
+
+        def queryValue(arg):
+            return request.args.get(arg, [""])[0]
+
         def queryValues(arg):
             query = cgi.parse_qs(urlparse.urlparse(request.uri).query, True)
             matches = []
@@ -464,53 +509,33 @@
                     matches.append(key[len(arg):])
             return matches
 
-        # Read request parameters.
-        resourceId = queryValue("resourceId")
-        resourceSearch = queryValue("resourceSearch")
-        davPropertyName = queryValue("davPropertyName")
         autoSchedule = queryValue("autoSchedule")
-        proxySearch = queryValue("proxySearch")
         makeReadProxies = queryValues("mkReadProxy|")
         makeWriteProxies = queryValues("mkWriteProxy|")
         removeProxies = queryValues("rmProxy|")
 
-        # Begin the content
-        content = ("%(header)s\n"
-                   "<h2>Resource Management</h2>\n"
-                   "%(search)s\n" % { "header": self.header(None),
-                                     "search": (yield self.searchContent(directory, resourceSearch)) })
+        # Update the auto-schedule value if specified.
+        if autoSchedule is not None and (autoSchedule == "true" or
+                                         autoSchedule == "false"):
+            if ( principal.record.recordType != "users" and
+                 principal.record.recordType != "groups"):
+                principal.setAutoSchedule(autoSchedule == "true")
 
-        # Add details if a resource has been selected.
-        if resourceId:
-        
-            principal = self.getResourceById(request, resourceId)
-    
-            # Update the auto-schedule value if specified.
-            if autoSchedule is not None and (autoSchedule == "true" or autoSchedule == "false"):
-                if principal.record.recordType != "users" and principal.record.recordType != "groups":
-                    principal.setAutoSchedule(autoSchedule == "true")
+        # Update the proxies if specified.
+        for proxyId in removeProxies:
+            proxy = self.getResourceById(request, proxyId)
+            (yield action_removeProxyPrincipal(principal, proxy,
+                                               proxyTypes=["read", "write"]))
 
-            # Update the proxies if specified.
-            for proxyId in removeProxies:
-                proxy = self.getResourceById(request, proxyId)
-                (yield action_removeProxyPrincipal(principal, proxy, proxyTypes=["read", "write"]))
+        for proxyId in makeReadProxies:
+            proxy = self.getResourceById(request, proxyId)
+            (yield action_addProxyPrincipal(principal, "read", proxy))
 
-            for proxyId in makeReadProxies:
-                proxy = self.getResourceById(request, proxyId)
-                (yield action_addProxyPrincipal(principal, "read", proxy))
+        for proxyId in makeWriteProxies:
+            proxy = self.getResourceById(request, proxyId)
+            (yield action_addProxyPrincipal(principal, "write", proxy))
 
-            for proxyId in makeWriteProxies:
-                proxy = self.getResourceById(request, proxyId)
-                (yield action_addProxyPrincipal(principal, "write", proxy))
-                
-            # Add the detailed content
-            content += (yield self.detailContent(directory, request, principal, resourceId, davPropertyName, proxySearch))
 
-        # Add the footer
-        content += self.footer()
-
-        returnValue(content)
-        
     @inlineCallbacks
     def searchContent(self, directory, resourceSearch):
         
@@ -784,7 +809,7 @@
             return response
 
         # Generate the HTML and return the response when it's ready.
-        htmlContent = self.htmlContent(self.directory, request)
+        htmlContent = self.htmlContent(request)
         htmlContent.addCallback(_defer)
         return htmlContent
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/3cc75815/attachment-0001.html>


More information about the calendarserver-changes mailing list