[Checkins] SVN: grokui.admin/branches/fancy-layout/ Now splitting the monolithic views.py into specific files. Redesigning the templates to use the layout

Souheil CHELFOUH souheil at chelfouh.com
Fri Sep 18 06:32:49 EDT 2009


Log message for revision 104294:
  Now splitting the monolithic views.py into specific files. Redesigning the templates to use the layout

Changed:
  U   grokui.admin/branches/fancy-layout/CHANGES.txt
  U   grokui.admin/branches/fancy-layout/buildout.cfg
  U   grokui.admin/branches/fancy-layout/setup.py
  U   grokui.admin/branches/fancy-layout/src/grokui/admin/__init__.py
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/applications.py
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/server.py
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/applications.pt
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/grokadminmacros.pt
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/index.pt
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/rename.pt
  A   grokui.admin/branches/fancy-layout/src/grokui/admin/templates/server.pt
  U   grokui.admin/branches/fancy-layout/src/grokui/admin/tests/apps.py
  U   grokui.admin/branches/fancy-layout/src/grokui/admin/tests/packdatabase.py
  U   grokui.admin/branches/fancy-layout/src/grokui/admin/view.py

-=-
Modified: grokui.admin/branches/fancy-layout/CHANGES.txt
===================================================================
--- grokui.admin/branches/fancy-layout/CHANGES.txt	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/CHANGES.txt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -4,7 +4,9 @@
 0.6 (unreleased)
 ================
 
+* Reflect the changes in grokcore.view 1.12 where View and CodeView become a single View again.
 
+
 0.5 (2009-09-15)
 ================
 

Modified: grokui.admin/branches/fancy-layout/buildout.cfg
===================================================================
--- grokui.admin/branches/fancy-layout/buildout.cfg	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/buildout.cfg	2009-09-18 10:32:49 UTC (rev 104294)
@@ -1,16 +1,24 @@
 [buildout]
 develop = .
-parts = test data zopectl app
+          ../grok
+parts = svn test data zopectl app 
 find-links = http://download.zope.org/distribution/
 # Test also with other configs...
-extends = versions.cfg
+extends = ../grok/versions.cfg
 versions = versions
 
 [data]
 recipe = zc.recipe.filestorage
 
+[svn]
+recipe = infrae.subversion
+as_eggs = True
+urls = svn+ssh://svn.zope.org/repos/main/grokui.base/trunk grokui.base
+
 [versions]
 grokui.admin = 
+grokui.base = 
+megrok.layout = 0.8
 
 [app]
 recipe = zc.zope3recipes>=0.5.3:application
@@ -19,6 +27,7 @@
            xmlns:meta="http://namespaces.zope.org/meta"
            i18n_domain="zope"
            >
+            <include package="grokui.base" />
             <include package="grokui.admin" />
             <include package="zope.app.twisted" />
 
@@ -45,8 +54,7 @@
                  public access -->
             <grant permission="zope.View"
                    principal="zope.Anybody" />
-            <grant permission="grok.View"
-                   principal="zope.Anybody" />
+
             <grant permission="zope.app.dublincore.view"
                    principal="zope.Anybody" />
 

Modified: grokui.admin/branches/fancy-layout/setup.py
===================================================================
--- grokui.admin/branches/fancy-layout/setup.py	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/setup.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -40,6 +40,7 @@
       install_requires=['setuptools',
                         'ZODB3',
                         'grok',
+                        'grokui.base',
 			'grokcore.view',
                         'martian',
                         'z3c.flashmessage',

Modified: grokui.admin/branches/fancy-layout/src/grokui/admin/__init__.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/__init__.py	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/__init__.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -12,4 +12,7 @@
 #
 ##############################################################################
 # a package
-
+import grok
+class Test(grok.Application, grok.Container):
+    """My super application
+    """

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/applications.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/applications.py	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/applications.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,94 @@
+import grok
+from ZODB.broken import Broken
+from zope.traversing.browser import absoluteURL
+from zope.contentprovider.interfaces import IContentProvider
+from zope.component import getMultiAdapter, getAllUtilitiesRegisteredFor
+from grokui.base.layout import AdminView
+from grokui.base.interfaces import IInstallableApplication, \
+                                   IInstalledApplication, \
+                                   IApplicationRepresentation
+
+
+grok.templatedir("templates")
+
+
+class InstalledApplication(object):
+    """
+    """
+    grok.implements(IInstalledApplication)
+    
+    def __init__(self, obj, request):
+        self.__name__ = obj.__name__
+        self.url = absoluteURL(obj, request)
+        self.description = obj.__doc__
+        self.__parent__ = obj.__parent__
+        self.classname = ".".join((obj.__class__.__module__,
+                                   obj.__class__.__name__))
+
+    def __cmp__(self, a, b):
+        return cmp(a.__name__, b.__name__)
+
+
+class BrokenApplication(object):
+    grok.implements(IApplicationRepresentation)
+
+    def __init__(self, name, obj):
+        self.__name__ = name
+        self.classname = ".".join((obj.__class__.__module__,
+                                   obj.__class__.__name__))
+
+    def __cmp__(self, a, b):
+        return cmp(a.__name__, b.__name__)
+
+
+class InstallableApplication(object):
+    """
+    """
+    grok.implements(IInstallableApplication)
+    
+    def __init__(self, klass):
+        self.__name__ = klass.__name__
+        self.classname = ".".join((klass.__module__, klass.__name__))
+        self.description = unicode(klass.__doc__)
+
+    
+class ApplicationInfo(grok.View):
+    grok.name('info')
+    grok.context(IApplicationRepresentation)
+
+    def render(self):
+        info = getMultiAdapter(
+            (self.context, self.request, self),
+            IContentProvider,
+            name='grokui_application_info')
+        info.update()
+        return info.render()
+
+
+class Applications(AdminView):
+    """View for application management.
+    """
+    grok.name('applications')
+    grok.title('Applications')
+    grok.require('grok.ManageApplications')
+
+
+    def update(self):
+        # Available apps...
+        apps = getAllUtilitiesRegisteredFor(grok.interfaces.IApplication)
+        self.installable = (InstallableApplication(x) for x in apps)
+
+        # Installed apps...
+        self.broken = []
+        self.installed = []
+
+        for name, app in self.context.items():
+            is_broken = isinstance(app, Broken)
+            if is_broken:
+                self.broken.append(BrokenApplication(name, app))
+            else:
+                self.installed.append(InstalledApplication(app, self.request))
+
+        self.broken.sort()
+        self.installed.sort()
+        self.has_apps = bool(len(self.installed) + len(self.broken))

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/server.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/server.py	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/server.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,165 @@
+# -*- coding: utf-8 -*-
+
+import grok
+import z3c.flashmessage.interfaces
+
+from grokui.base.layout import AdminView
+from grokui.admin.interfaces import ISecurityNotifier
+from grokui.admin.utilities import getVersion, getURLWithParams
+
+from ZODB.interfaces import IDatabase
+from ZODB.FileStorage.FileStorage import FileStorageError
+
+import zope.component
+from zope.interface import Interface
+from zope.traversing.browser import absoluteURL
+from zope.app.applicationcontrol.interfaces import IServerControl
+from zope.app.applicationcontrol.browser.runtimeinfo import RuntimeInfoView
+from zope.app.applicationcontrol.browser.zodbcontrol import ZODBControlView
+from zope.app.applicationcontrol.applicationcontrol import applicationController
+
+grok.templatedir("templates")
+
+
+class Server(AdminView, ZODBControlView):
+    """Zope3 management screen.
+    """
+    grok.title('Server')
+    grok.require('grok.ManageApplications')
+
+    @property
+    def grok_version(self):
+        return getVersion('grok')
+
+    @property
+    def grokuiadmin_version(self):
+        return getVersion('grokui.admin')
+
+    def root_url(self, name=None):
+        obj = self.context
+        result = ""
+        while obj is not None:
+            if IRootFolder.providedBy(obj):
+                return self.url(obj, name)
+            obj = obj.__parent__
+        raise ValueError("No application nor root element found.")
+
+    @property
+    def security_notifier_url(self):
+        """Get the URL to look up for security warnings.
+        """
+        return self.security_notifier.lookup_url
+    
+    @property
+    def security_notifier(self):
+        """Get a local security notifier.
+
+        The security notifier is installed as a local utility by an
+        event handler in the security module.
+        """
+        site = grok.getSite()
+        site_manager = site.getSiteManager()
+        return site_manager.queryUtility(ISecurityNotifier, default=None)
+    
+    @property
+    def secnotes_enabled(self):
+        if self.security_notifier is None:
+            # Safety belt if installation of notifier failed
+            return False
+        return self.security_notifier.enabled
+
+    @property
+    def secnotes_message(self):
+        if self.security_notifier is None:
+            return u'Security notifier is not installed.'
+        return self.security_notifier.getNotification()
+    
+    @property
+    def server_control(self):
+        return zope.component.queryUtility(IServerControl, '', None)
+
+    @property
+    def runtime_info(self):
+        riv = RuntimeInfoView()
+        riv.context = applicationController
+        return riv.runtimeInfo()
+
+    @property
+    def current_message(self):
+        source = zope.component.getUtility(
+          z3c.flashmessage.interfaces.IMessageSource, name='admin')
+        messages = list(source.list())
+        if messages:
+            return messages[0]
+
+    def updateSecurityNotifier(self, setsecnotes=None, setsecnotesource=None,
+                               secnotesource=None):
+        if self.security_notifier is None:
+            return
+        if setsecnotesource is not None:
+            self.security_notifier.setLookupURL(secnotesource)
+        if setsecnotes is not None:
+            if self.security_notifier.enabled is True:
+                self.security_notifier.disable()
+            else:
+                self.security_notifier.enable()
+        if self.secnotes_enabled is False:
+            return
+        return
+        
+    def update(self, time=None, restart=None, shutdown=None,
+               setsecnotes=None, secnotesource=None, setsecnotesource=None,
+               admin_message=None, submitted=False, dbName="", pack=None,
+               days=0):
+
+        # Packing control
+        if pack is not None:
+            return self.pack(dbName, days)
+
+        # Security notification control
+        self.updateSecurityNotifier(setsecnotes, setsecnotesource,
+                                    secnotesource)
+
+        
+        if not submitted:
+            return
+
+        # Admin message control
+        source = zope.component.getUtility(
+          z3c.flashmessage.interfaces.IMessageSource, name='admin')
+        if admin_message is not None:
+            source.send(admin_message)
+        elif getattr(source, 'current_message', False):
+            source.delete(source.current_message)
+
+        # Restart control
+        if time is not None:
+            try:
+                time = int(time)
+            except:
+                time = 0
+        else:
+            time = 0
+
+        if restart is not None:
+            self.server_control.restart(time)
+        elif shutdown is not None:
+            self.server_control.shutdown(time)
+
+        self.redirect(self.url())
+
+    def pack(self, dbName, days):
+        try:
+            days = int(days)
+        except ValueError:
+            flash('Error: Invalid Number')
+            return
+        db = zope.component.getUtility(IDatabase, name=dbName)
+        print "DB: ", db, days
+        db.pack(days=days)
+        return
+        try:
+            db.pack(days=days)
+            flash('ZODB `%s` successfully packed.' % (dbName))
+        except FileStorageError, err:
+            flash('ERROR packing ZODB `%s`: %s' % (dbName, err))

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/templates/applications.pt
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/templates/applications.pt	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/templates/applications.pt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,78 @@
+<form tal:define="apps context/values"
+      tal:attributes="action string:${context/@@absolute_url}/manageapps">
+
+  <fieldset>
+    <legend>Installed applications</legend>
+
+    <div tal:condition="not: view/installed">
+      <p class="menu-description1">
+	Currently no working applications are installed.
+      </p>
+    </div>
+
+    <div tal:condition="view/installed" 
+	 tal:repeat="app view/installed">
+      <input type="checkbox" 
+	     class="checkbox" 
+	     tal:attributes="value app/__name__;
+			     name string:items" />
+      <a tal:attributes="href app/url">
+	<span tal:replace="app/__name__"/>
+      </a>
+      (<span tal:replace="app/classname"/>)
+    </div>
+
+    <div tal:condition="view/broken">
+      <br/><div class="emph">Broken applications:</div>
+    </div>
+    <div tal:repeat="app view/broken">
+      <input type="checkbox" 
+	     class="checkbox" 
+	     tal:attributes="value app/__name__;
+			     name string:items" />
+      <span tal:content="app/__name__" />
+      (broken type: <span tal:replace="app/classname"/>).
+      This application is broken!
+    </div>
+
+    <p>
+      <input tal:condition="view/has_apps"
+	     class="button" type="submit" name="delete" 
+	     id="form.actions.delete"
+	     value="Delete Selected"/>
+      <input tal:condition="view/installed"
+	     class="button" type="submit" name="rename"
+	     value="Rename"/>
+    </p>
+  </fieldset>
+</form>
+
+<fieldset>	
+  <legend>Add application</legend>
+
+  <div class="menu-box1"
+       tal:repeat="app view/installable">
+    <form action=""
+	  tal:attributes="action string:${context/@@absolute_url}/add;
+			  name app/__name__">
+      <div class="menu-box2">
+	<div class="menu-head1">
+	  <h3 tal:content="app/__name__">Application Name</h3>
+	</div>
+	<div class="menu-description1">
+	  <p tal:replace="structure app/description">
+	    Application description here.
+	  </p>
+	</div>
+	<div tal:replace="app/@@info" />
+	<div class="menu-box3">
+	  <label>Name your new app: <input type="text" name="name"/></label>
+	  <input type="hidden" name="application" value=""
+		 tal:attributes="value app/classname" />
+	  <input class="button" type="submit" name="Add" value="Create"/>
+	</div>
+      </div>
+    </form>
+  </div>
+
+</fieldset>

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/templates/grokadminmacros.pt
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/templates/grokadminmacros.pt	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/templates/grokadminmacros.pt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,100 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+      i18n:domain="zope"
+      metal:define-macro="gaia-page">
+  <head>
+    <title
+      metal:define-slot="title"
+      >grok administration interface</title>
+    <link metal:define-slot="header"
+      rel="stylesheet" type="text/css" href="static/grok.css"
+      tal:on-error="nothing"
+      tal:attributes="href view/static/grok.css" />
+    <metal:block define-slot="extrahead">
+    </metal:block>
+  </head>
+
+  <body>
+    <div tal:condition="not:exists: view/root_url">
+      This template (grokadminmacros.pt in grok.admin) must be called
+      from a view with defined root_url.
+    </div>
+    <div tal:condition="exists: view/root_url">
+      <div id="banner">
+        <a href="/" id="logo">
+          <img alt="Grok" src="images/grok-admin.jpg" height="40"
+            tal:attributes="src view/static/grok-admin.jpg" />
+        </a>
+      </div>
+
+      <div id="logout" metal:define-macro="logged_user">
+	<span tal:condition="view/is_authenticated">
+	  <span i18n:translate="">User:
+	  <span tal:replace="request/principal/title"
+		i18n:name="user_title">User</span>
+	  </span>
+	</span>
+      </div>
+
+      <div id="breadcrumbs">
+        <div id="banner-shadow">
+          &nbsp;
+        </div>
+      </div>
+      <div id="fireplace">
+        <img alt="grok_relax_image" src="images/grok-relax5.gif"
+          tal:attributes="src view/static/grok-relax5.gif" />
+      </div>
+      <div id="menu-links" 
+	   metal:define-slot="menu-links"
+	   tal:define="currview python:view.url()">
+        <span class="menu-link-inactive"
+          tal:define="target string:${view/root_url}/applications">
+          <a href="applications"
+            tal:condition="python: target != currview"
+            tal:attributes="href target"
+            >Applications</a>
+          <span class="emph"
+            tal:condition="python: target == currview">
+            Applications
+          </span>
+        </span>
+        &nbsp;&nbsp;
+        <span class="menu-link-inactive"
+          tal:define="target string:${view/root_url}/server"
+          >
+          <a href="z3index"
+            tal:condition="python: target != currview"
+            tal:attributes="href target"
+            >Server Control</a>
+          <span class="emph"
+            tal:condition="python: target == currview">
+            Server Control
+          </span>
+        </span>
+      </div>
+
+        <div id="content">
+
+          
+
+	  <div id="securitynotifications"
+	       tal:content="structure provider:grokadmin_security"
+	       tal:on-error="nothing" />
+
+          <div metal:define-slot="content">
+
+            <h1>Welcome to Grok!</h1>
+
+            <div>
+              Your friendly and easy way to Zope 3.
+            </div>
+
+          </div>
+          <div>
+            <p id="footer-copyright">&copy; Copyright 2007, The Zope Foundation<br />Design inspired by Sebastian Ware</p>
+          </div>
+        </div>
+
+    </div>
+  </body>
+</html>

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/templates/index.pt
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/templates/index.pt	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/templates/index.pt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,14 @@
+<html metal:use-macro="context/@@grokadminmacros/macros/gaia-page">
+  <div metal:fill-slot="content">
+    <h1></h1>
+    <div class="logo">
+      <a href="context/@@appsindex"
+	 tal:attributes="href string:${context/@@absolute_url}/applications">
+	<img alt="Image of Grok relaxing..."
+	     src="grok-relax4.png"
+	     tal:attributes="src view/static/grok-relax4.png" />
+      </a>
+    </div>
+  </div>
+  <div metal:fill-slot="footer">asda</div>
+</html>

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/templates/rename.pt
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/templates/rename.pt	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/templates/rename.pt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,27 @@
+<html metal:use-macro="context/@@grokadminmacros/macros/gaia-page">
+  <div metal:fill-slot="content">
+
+    <form tal:define="apps context/values"
+	  tal:attributes="action string:${context/@@absolute_url}/@@grokadmin_rename"
+	  method="post">
+      <fieldset>
+	<legend> Rename applications: </legend>
+	<div tal:repeat="app view/apps">
+	  <span tal:replace="app">AppName</span>
+	  <input type="hidden" name="items:list"
+		 tal:attributes="value app"/>
+	  to:
+	  <input type="text" name="new_names:list" 
+		 tal:attributes="value app" />
+	</div>
+	<hr />
+	<div>
+	  <input type="submit" class="button" name="rename"
+		 value="Rename" />
+	  <input type="submit" class="button" name="cancel"
+		 value="Cancel" />
+	</div>
+      </fieldset>
+    </form>
+  </div>
+</html>

Added: grokui.admin/branches/fancy-layout/src/grokui/admin/templates/server.pt
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/templates/server.pt	                        (rev 0)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/templates/server.pt	2009-09-18 10:32:49 UTC (rev 104294)
@@ -0,0 +1,136 @@
+<div>
+    <h1>Manage your Zope 3 instance</h1>
+
+    <fieldset>
+      <legend>Security notifications</legend>
+      <form method="post" action=""
+	    tal:attributes="action
+	    string:${context/@@absolute_url}/server">
+	<div>
+	  Running Grok <span tal:replace="view/grok_version" /> /
+	  grokui.admin <span tal:replace="view/grokuiadmin_version" />
+	</div>
+	<div>&nbsp;</div>
+	<div>
+	  You can be notified if serious security-related issues were
+	  discovered that concern your installation.
+	</div>
+	<div>
+	  Note, that if you enable this, HTTP-lookups of the grok site
+	  will happen to check, whether there are any published
+	  security issues for the installed version of grok.
+	</div>
+	<div>&nbsp;</div>
+	<div>
+	  <label for="secnotesource">URL to lookup:</label>
+	  <input type="text" size="30" name="secnotesource"
+		 tal:attributes="value view/security_notifier_url" />
+	  <input class="button" type="submit" name="setsecnotesource"
+		 value="Set URL" />
+	</div>
+	<div>&nbsp;</div>
+	<div tal:condition="view/secnotes_enabled">
+	  <span class="emph">
+	    Status: Security notifications are enabled
+	  </span>
+	  <input class="button" type="submit" name="setsecnotes"
+		 value="Disable" />
+	</div>
+	<div tal:condition="not: view/secnotes_enabled">
+	  <span class="emph">
+	    Status: Security notifications are disabled
+	  </span>
+	  <input class="button" type="submit" name="setsecnotes"
+		 value="Enable" />
+	</div>
+      </form>
+    </fieldset>
+
+    <form method="post" action=""
+      tal:attributes="action string:${context/@@absolute_url}/server">
+      <fieldset>
+	<p>
+	  <legend>Manage server process</legend>
+	  <span tal:condition="view/server_control">
+	    <input type="submit" name="restart" class="button" value="Restart Zope 3" />
+	    <input type="submit" name="shutdown" class="button" value="Stop Zope 3" />
+	    after <input type="text" name="time" value="0" size="4" /> seconds
+	    <input type="hidden" name="submitted" value="true"/>
+	  </span>
+	  <span tal:condition="not: view/server_control">
+	  You have to start/stop/restart the server process from the cmdline.
+	  </span>
+	</p>
+      </fieldset>
+    </form>
+
+    <fieldset>
+      <legend>Manage your databases</legend>
+      <div tal:condition="not: python: len(view.databases)">
+        <p class="menu-description1">Currently no databases are active.</p>
+      </div>
+      <div tal:condition="python: len(view.databases) or True"
+	   tal:repeat="db view/databases">
+        <form method="post" action=""
+              tal:attributes="action string:${context/@@absolute_url}/server">
+	  <input type="hidden" name="submitted" value="true"/>
+          <input type="hidden" name="dbName" value="" tal:attributes="value db/utilName" />
+          <input type="text" name="days" value="0" size="3" title="Days of history to keep" />
+          <input class="button" type="submit" name="pack" value="Pack" />
+          <span tal:replace="db/dbName" />
+          <span tal:replace="db/size" />
+        </form>
+      </div>
+    </fieldset>
+
+    <form method="post" action=""
+      tal:attributes="action string:${context/@@absolute_url}/server">
+      <fieldset>
+        <legend>Admin message</legend>
+
+        <p>Lets you display an administrative message on all pages.<br />
+
+        <input
+          type="text"
+          name="admin_message"
+          tal:attributes="value view/current_message/message|nothing"
+          />
+
+        <input type="hidden" name="submitted" value="true"/>
+        <input type="submit" name="save_message" class="button" value="Save"/>
+
+	</p>
+      </fieldset>
+      <span class="header">Server process info</span>
+      <div id="server-processes">
+      <dl tal:define="ri view/runtime_info">
+          <dt class="emph">Uptime:</dt>
+          <dd tal:content="ri/Uptime">unknown</dd>
+          <dt class="emph">System platform:</dt>
+          <dd tal:content="ri/SystemPlatform">unknown</dd>
+          <dt class="emph">Zope version:</dt>
+          <dd tal:content="ri/ZopeVersion">unknown</dd>
+          <dt class="emph">Python version:</dt>
+          <dd tal:content="ri/PythonVersion">unknown</dd>
+          <dt class="emph">Command line:</dt>
+          <dd tal:content="ri/CommandLine">unknown</dd>
+          <dt class="emph">Preferred encoding:</dt>
+          <dd tal:content="ri/PreferredEncoding">unknown</dd>
+          <dt class="emph">File system encoding:</dt>
+          <dd tal:content="ri/FileSystemEncoding">unknown</dd>
+          <dt class="emph">Process ID:</dt>
+          <dd tal:content="ri/ProcessId">unknown</dd>
+          <dt class="emph">Python path:</dt>
+          <dd>
+            <ul>
+            <tal:block tal:repeat="path ri/PythonPath">
+              <li tal:content="path">unknown</li>
+            </tal:block>
+            </ul>
+          </dd>
+      </dl>
+      </div>
+
+    </form>
+
+  </div>

Modified: grokui.admin/branches/fancy-layout/src/grokui/admin/tests/apps.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/tests/apps.py	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/tests/apps.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -111,17 +111,13 @@
 """
 
 import grok
-try:
-    from grokcore.view import CodeView as View
-except ImportError:
-    from grok import View
-from grokui.admin.view import GrokCoreViewOrCodeView
 
+
 class MammothManager(grok.Application, grok.Container):
     """A mammoth manager"""
     pass
 
-class Index(View):
 
+class Index(grok.View):
     def render(self):
         return u"Let's manage some mammoths!"

Modified: grokui.admin/branches/fancy-layout/src/grokui/admin/tests/packdatabase.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/tests/packdatabase.py	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/tests/packdatabase.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -66,17 +66,15 @@
 """
 
 import grok
-try:
-    from grokcore.view import CodeView as View
-except ImportError:
-    from grok import View
 
+
 class StuffedMammoth(grok.Application, grok.Container):
     """A stuffed mammoth"""
     stuffing = None
 
-class Index(View):#
 
+class Index(grok.View):#
+
     def update(self, stuffing=None):
         if stuffing is not None:
             self.context.stuffing = stuffing*1000

Modified: grokui.admin/branches/fancy-layout/src/grokui/admin/view.py
===================================================================
--- grokui.admin/branches/fancy-layout/src/grokui/admin/view.py	2009-09-18 10:32:45 UTC (rev 104293)
+++ grokui.admin/branches/fancy-layout/src/grokui/admin/view.py	2009-09-18 10:32:49 UTC (rev 104294)
@@ -25,38 +25,29 @@
 
 import zope.component
 from zope.interface import Interface
+from zope.traversing.browser import absoluteURL
 from zope.app.applicationcontrol.interfaces import IServerControl
 from zope.app.applicationcontrol.applicationcontrol import applicationController
 from zope.app.applicationcontrol.browser.runtimeinfo import RuntimeInfoView
 from zope.app.applicationcontrol.browser.zodbcontrol import ZODBControlView
 from zope.app.folder.interfaces import IRootFolder
-from zope.app.security.interfaces import IUnauthenticatedPrincipal
 from zope.exceptions import DuplicationError
 from ZODB.FileStorage.FileStorage import FileStorageError
+from zope.contentprovider.interfaces import IContentProvider
 
-try:
-    # For grokcore.view >= 1.9 working sets...
-    from grokcore.view import CodeView as GrokCoreViewOrCodeView
-except ImportError:
-    # For grokcore.view < 1.9 working sets...
-    from grok import View as GrokCoreViewOrCodeView
-
-    
+from grokui.base.layout import AdminView
+from grokui.base.interfaces import IInstallableApplication, IInstalledApplication, IApplicationRepresentation
+  
 grok.context(IRootFolder)
+grok.templatedir("templates")
 
 
-def flash(message, type='message'):
-    src = zope.component.getUtility(
-        z3c.flashmessage.interfaces.IMessageSource, name='session'
-        )
-    src.send(message, type)
 
-
 class ManageApplications(grok.Permission):
     grok.name('grok.ManageApplications')
 
 
-class GrokAdminInfoView(GrokCoreViewOrCodeView):
+class GrokAdminInfoView(grok.View):
     """A base to provide machinereadable views.
     """
     grok.name('grokadmin')
@@ -84,11 +75,6 @@
     def grokuiadmin_version(self):
         return getVersion('grokui.admin')
 
-    def is_authenticated(self):
-        """Check, wether we are authenticated.
-        """
-        return not IUnauthenticatedPrincipal.providedBy(self.request.principal)
-
     def root_url(self, name=None):
         obj = self.context
         result = ""
@@ -99,8 +85,7 @@
         raise ValueError("No application nor root element found.")
 
 
-
-class GrokAdminVersion(GrokCoreViewOrCodeView):
+class GrokAdminVersion(grok.View):
     """Display version of a package.
 
     Call this view via http://localhost:8080/@@grokadmin/@@version to
@@ -115,7 +100,7 @@
         return u'%s %s' % (pkg, getVersion(pkg))
 
 
-class GrokAdminSecurityNotes(GrokCoreViewOrCodeView):
+class GrokAdminSecurityNotes(grok.View):
     """Display current security notification.
 
     Call this view via http://localhost:8080/@@grokadmin/@@secnote
@@ -130,7 +115,7 @@
         return notifier.getNotification()
 
 
-class Add(GrokCoreViewOrCodeView):
+class Add(grok.View):
     """Add an application.
     """
 
@@ -155,15 +140,14 @@
             new_app = app()
             grok.notify(grok.ObjectCreatedEvent(new_app))
             self.context[name] = new_app
-            flash(u'Added %s `%s`.' % (application, name))
+            self.flash(u'Added %s `%s`.' % (application, name))
         except DuplicationError:
-            flash(
-                u'Name `%s` already in use. Please choose another name.' % (
-                name,))
+            self.flash(u'Name `%s` already in use. '
+                       u'Please choose another name.' % (name,))
         self.redirect(self.url(self.context))
 
 
-class ManageApps(GrokCoreViewOrCodeView):
+class ManageApps(grok.View):
     """Manage applications (delete, rename).
     """
 
@@ -272,190 +256,3 @@
                              for x in apps)
         # Go to the first page immediately.
         self.redirect(self.url('applications'))
-
-
-class Applications(AdminViewBase):
-    """View for application management.
-    """
-    grok.name('applications')
-    grok.require('grok.ManageApplications')
-
-
-    def update(self):
-        # Available apps...
-        apps = zope.component.getAllUtilitiesRegisteredFor(
-            grok.interfaces.IApplication)
-        self.applications = (
-            {'name': "%s.%s" % (x.__module__, x.__name__),
-             'docurl':("%s.%s" % (x.__module__, x.__name__)).replace('.', '/'),
-             'descr': x.__doc__}
-            for x in apps)
-
-        # Installed apps...
-        inst_apps = [x for x in self.context.values()
-                     if hasattr(x, '__class__') and x.__class__ in apps
-                     and not issubclass(x.__class__, Broken)]
-        inst_apps.sort(lambda x, y: cmp(x.__name__, y.__name__))
-        self.installed_applications = inst_apps
-
-        # Broken apps...
-        broken_apps = [{'obj':y, 'name':x} for x,y in self.context.items()
-                       if isinstance(y, Broken)]
-        broken_apps.sort(lambda x, y: cmp(x['name'], y['name']))
-        self.broken_applications = broken_apps
-
-
-class AdminMessageSource(grok.GlobalUtility):
-
-    grok.name('admin')
-    zope.interface.implements(z3c.flashmessage.interfaces.IMessageSource)
-
-    message = None
-
-    def send(self, message, type='admin'):
-        self.message = z3c.flashmessage.message.PersistentMessage(message,
-                                                                  type)
-
-    def list(self, type=None):
-        if self.message is None:
-            return
-        if type is None or self.message.type == type:
-            yield self.message
-
-    def delete(self, message):
-        if message is self.message:
-            self.message = None
-        else:
-            raise KeyError(message)
-
-
-class GrokAdminMacros(AdminViewBase):
-    """Provides the o-wrap layout.
-    """
-    grok.context(Interface)
-
-
-class Server(AdminViewBase, ZODBControlView):
-    """Zope3 management screen.
-    """
-    grok.require('grok.ManageApplications')
-
-    @property
-    def security_notifier_url(self):
-        """Get the URL to look up for security warnings.
-        """
-        return self.security_notifier.lookup_url
-    
-    @property
-    def security_notifier(self):
-        """Get a local security notifier.
-
-        The security notifier is installed as a local utility by an
-        event handler in the security module.
-        """
-        site = grok.getSite()
-        site_manager = site.getSiteManager()
-        return site_manager.queryUtility(ISecurityNotifier, default=None)
-    
-    @property
-    def secnotes_enabled(self):
-        if self.security_notifier is None:
-            # Safety belt if installation of notifier failed
-            return False
-        return self.security_notifier.enabled
-
-    @property
-    def secnotes_message(self):
-        if self.security_notifier is None:
-            return u'Security notifier is not installed.'
-        return self.security_notifier.getNotification()
-    
-    @property
-    def server_control(self):
-        return zope.component.queryUtility(IServerControl, '', None)
-
-    @property
-    def runtime_info(self):
-        riv = RuntimeInfoView()
-        riv.context = applicationController
-        return riv.runtimeInfo()
-
-    @property
-    def current_message(self):
-        source = zope.component.getUtility(
-          z3c.flashmessage.interfaces.IMessageSource, name='admin')
-        messages = list(source.list())
-        if messages:
-            return messages[0]
-
-    def updateSecurityNotifier(self, setsecnotes=None, setsecnotesource=None,
-                               secnotesource=None):
-        if self.security_notifier is None:
-            return
-        if setsecnotesource is not None:
-            self.security_notifier.setLookupURL(secnotesource)
-        if setsecnotes is not None:
-            if self.security_notifier.enabled is True:
-                self.security_notifier.disable()
-            else:
-                self.security_notifier.enable()
-        if self.secnotes_enabled is False:
-            return
-        return
-        
-    def update(self, time=None, restart=None, shutdown=None,
-               setsecnotes=None, secnotesource=None, setsecnotesource=None,
-               admin_message=None, submitted=False, dbName="", pack=None,
-               days=0):
-
-        # Packing control
-        if pack is not None:
-            return self.pack(dbName, days)
-
-        # Security notification control
-        self.updateSecurityNotifier(setsecnotes, setsecnotesource,
-                                    secnotesource)
-
-        
-        if not submitted:
-            return
-
-        # Admin message control
-        source = zope.component.getUtility(
-          z3c.flashmessage.interfaces.IMessageSource, name='admin')
-        if admin_message is not None:
-            source.send(admin_message)
-        elif getattr(source, 'current_message', False):
-            source.delete(source.current_message)
-
-        # Restart control
-        if time is not None:
-            try:
-                time = int(time)
-            except:
-                time = 0
-        else:
-            time = 0
-
-        if restart is not None:
-            self.server_control.restart(time)
-        elif shutdown is not None:
-            self.server_control.shutdown(time)
-
-        self.redirect(self.url())
-
-    def pack(self, dbName, days):
-        try:
-            days = int(days)
-        except ValueError:
-            flash('Error: Invalid Number')
-            return
-        db = zope.component.getUtility(IDatabase, name=dbName)
-        print "DB: ", db, days
-        db.pack(days=days)
-        return
-        try:
-            db.pack(days=days)
-            flash('ZODB `%s` successfully packed.' % (dbName))
-        except FileStorageError, err:
-            flash('ERROR packing ZODB `%s`: %s' % (dbName, err))



More information about the checkins mailing list