Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Use webut.skin to make ldaptor webui skinnable.
Browse files Browse the repository at this point in the history
This allows embedding it seamlessly in a web site.

git-svn-id: svn+ssh://open.inoi.fi/open-ldaptor/trunk@395 373aa48d-36e5-0310-bb30-ae74d9883905
  • Loading branch information
tv committed Mar 5, 2006
1 parent 8f601f7 commit c687e95
Show file tree
Hide file tree
Showing 29 changed files with 265 additions and 195 deletions.
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Section: admin
Priority: optional
Maintainer: Tommi Virtanen <tv@debian.org>
Standards-Version: 3.6.1
Build-Depends-Indep: python, python2.3-dev, python2.4-dev, cdbs, debhelper (>= 4.1.68), docbook-slides (>= 3.2.0), xsltproc, source-highlight, python-epydoc, dia (>= 0.93-2), python2.3-twisted (>= 2.0), python2.3-nevow (>= 0.6.0), python2.3-pyparsing, python2.3-pyopenssl, python2.3-crypto, python2.4-twisted (>= 2.0), python2.4-nevow (>= 0.6.0), python2.4-pyparsing, python2.4-pyopenssl, python2.4-crypto
Build-Depends-Indep: python, python2.3-dev, python2.4-dev, cdbs, debhelper (>= 4.1.68), docbook-slides (>= 3.2.0), xsltproc, source-highlight, python-epydoc, dia (>= 0.93-2), python2.3-twisted (>= 2.0), python2.3-nevow (>= 0.6.0), python2.3-webut, python2.3-pyparsing, python2.3-pyopenssl, python2.3-crypto, python2.4-twisted (>= 2.0), python2.4-nevow (>= 0.6.0), python2.4-webut, python2.4-pyparsing, python2.4-pyopenssl, python2.4-crypto

Package: ldaptor-utils
Section: admin
Expand Down Expand Up @@ -50,7 +50,7 @@ Description: Command-line LDAP utilities
Package: ldaptor-webui
Section: admin
Architecture: all
Depends: ${python:Depends}, python2.3-nevow (>= 0.6.0), python2.3-ldaptor
Depends: ${python:Depends}, python2.3-nevow (>= 0.6.0), python2.3-webut, python2.3-ldaptor
Description: Web user interface for editing LDAP directories
A web-based user interface to search and edit information in an LDAP
directory.
Expand Down
13 changes: 10 additions & 3 deletions demo-webui-fi.tac
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# -*- python -*-
from zope.interface import implements
from twisted.application import service, internet
from nevow import appserver, inevow
from nevow import appserver, inevow, tags
from ldaptor import config
from ldaptor.apps.webui import main, i18n
from ldaptor.apps.webui import main, i18n, defskin

application = service.Application("ldaptor-webui")
myService = service.IServiceCollection(application)

resource = main.getResource()
class DemoSkin(defskin.DefaultSkin):
def render_content(self, ctx, data):
return tags.invisible[
tags.div(style="float: right; color: lightgray; font-size: 5em;")['demo'],
super(DemoSkin, self).render_content(ctx, data),
]

resource = main.getResource(skinFactory=DemoSkin)

class Wrap(object):
implements(inevow.IResource)
Expand Down
14 changes: 5 additions & 9 deletions ldaptor/apps/webui/add-really.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:nevow="http://nevow.com/ns/nevow/0.1">
xmlns:nevow="http://nevow.com/ns/nevow/0.1"
nevow:render="skin">
<head>
<title nevow:render="i18n">Ldaptor Add Page</title>
<nevow:invisible nevow:render="sequence" nevow:data="css">
<link rel="stylesheet"
nevow:pattern="item"
nevow:render="css_item">
<nevow:attr name="href"><nevow:slot name="url"/></nevow:attr>
</link>
</nevow:invisible>
<title>Title Goes Here</title>
</head>
<body>
<nevow:invisible nevow:pattern="skincontent">
<h1 nevow:render="i18n">Ldaptor Add Page</h1>

<p>
Expand All @@ -35,5 +30,6 @@
</div>

<div nevow:render="form" />
</nevow:invisible>
</body>
</html>
28 changes: 9 additions & 19 deletions ldaptor/apps/webui/add.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from zope.interface import implements
from twisted.internet import defer
from twisted.python import plugin
from webut.skin import iskin

from ldaptor.protocols.ldap import ldapsyntax, distinguishedname
from ldaptor.protocols.ldap import fetchschema
Expand Down Expand Up @@ -332,22 +333,16 @@ def _process2(self, changes, context, rdn, kw):
return d

class ReallyAddPage(rend.Page):
implements(iskin.ISkinnable)

title = _('Ldaptor Add Page')

addSlash = True

docFactory = loaders.xmlfile(
'add-really.xhtml',
templateDir=os.path.split(os.path.abspath(__file__))[0])

def data_css(self, ctx, data):
u = (url.URL.fromContext(ctx).clear().parentdir().parentdir()
.parentdir().parentdir()
.child('form.css'))
return [ u ]

def render_css_item(self, context, data):
context.fillSlots('url', data)
return context.tag

def data_header(self, ctx, data):
u=url.URL.fromContext(ctx)
u=u.parentdir().parentdir().parentdir().clear()
Expand Down Expand Up @@ -468,6 +463,10 @@ def add(self, context, smartObjectClass):
return u.child('smart').child(smartObjectClass)

class AddPage(rend.Page):
implements(iskin.ISkinnable)

title = _('Ldaptor Add Page')

addSlash = True

docFactory = loaders.xmlfile(
Expand All @@ -494,15 +493,6 @@ def getPlugin(self, name):
return plug
raise KeyError, name

def data_css(self, ctx, data):
u = (url.URL.fromContext(ctx).clear().parentdir().parentdir()
.child('form.css'))
return [ u ]

def render_css_item(self, context, data):
context.fillSlots('url', data)
return context.tag

def data_header(self, ctx, data):
u=url.URL.fromContext(ctx)
u=u.parentdir().clear()
Expand Down
14 changes: 5 additions & 9 deletions ldaptor/apps/webui/add.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:nevow="http://nevow.com/ns/nevow/0.1">
xmlns:nevow="http://nevow.com/ns/nevow/0.1"
nevow:render="skin">
<head>
<title nevow:render="i18n">Ldaptor Add Page</title>
<nevow:invisible nevow:render="sequence" nevow:data="css">
<link rel="stylesheet"
nevow:pattern="item"
nevow:render="css_item">
<nevow:attr name="href"><nevow:slot name="url"/></nevow:attr>
</link>
</nevow:invisible>
<title>Title Goes Here</title>
</head>
<body>
<nevow:invisible nevow:pattern="skincontent">
<h1 nevow:render="i18n">Ldaptor Add Page</h1>

<p>
Expand All @@ -29,5 +24,6 @@
<div nevow:render="smartObjectForm" />

<div nevow:render="objectClassForm" />
</nevow:invisible>
</body>
</html>
8 changes: 5 additions & 3 deletions ldaptor/apps/webui/basedn.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:nevow="http://nevow.com/ns/nevow/0.1">
xmlns:nevow="http://nevow.com/ns/nevow/0.1"
nevow:render="skin">
<head>
<title nevow:render="i18n">Ldaptor Web Interface</title>
<link href="form.css" rel="stylesheet" />
<title>Title Goes Here</title>
</head>
<body>
<nevow:invisible nevow:pattern="skincontent">
<h1 nevow:render="i18n">Base DN</h1>

<form name="login"
Expand All @@ -17,5 +18,6 @@
nevow:render="form">
<nevow:invisible>Search form will be here.</nevow:invisible>
</form>
</nevow:invisible>
</body>
</html>
17 changes: 5 additions & 12 deletions ldaptor/apps/webui/change_password.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from zope.interface import implements
from twisted.internet import reactor
from twisted.internet import defer
from webut.skin import iskin
from ldaptor.protocols import pureldap
from ldaptor.protocols.ldap import ldapsyntax, distinguishedname
from ldaptor import generate_password, interfaces
Expand Down Expand Up @@ -322,6 +323,10 @@ def locateConfigurable(self, ctx, name):


class ConfirmChange(ServicePasswordChangeMixin, rend.Page):
implements(iskin.ISkinnable)

title = _('Ldaptor Password Change Page')

addSlash = True

docFactory = loaders.xmlfile(
Expand Down Expand Up @@ -357,18 +362,6 @@ def bind_generateRandom(self, ctx):
servicePasswordAction_20_set = SetServicePassword
servicePasswordAction_30_random = SetRandomServicePassword

def data_css(self, ctx, data):
root = (url.URL.fromContext(ctx).clear()
.parentdir().parentdir().parentdir())
return [
root.child('form.css'),
root.child('ldaptor.css'),
]

def render_css_item(self, ctx, data):
ctx.fillSlots('url', data)
return ctx.tag

def _setPassword(self, ctx, password):
e = getEntry(ctx, self.dn)
d=defer.maybeDeferred(e.setPassword, newPasswd=password)
Expand Down
14 changes: 5 additions & 9 deletions ldaptor/apps/webui/change_password.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:nevow="http://nevow.com/ns/nevow/0.1">
xmlns:nevow="http://nevow.com/ns/nevow/0.1"
nevow:render="skin">
<head>
<title nevow:render="i18n">Ldaptor Password Change Page</title>
<nevow:invisible nevow:render="sequence" nevow:data="css">
<link rel="stylesheet"
nevow:pattern="item"
nevow:render="css_item">
<nevow:attr name="href"><nevow:slot name="url"/></nevow:attr>
</link>
</nevow:invisible>
<title>Title Goes Here</title>
</head>
<body>
<nevow:invisible nevow:pattern="skincontent">
<h1 nevow:render="i18n">Ldaptor Password Change Page</h1>

<p nevow:render="sequence" nevow:data="header"><span
Expand All @@ -41,5 +36,6 @@
<div style="margin-top: 1em;">
<nevow:invisible nevow:render="add" />
</div>
</nevow:invisible>
</body>
</html>
50 changes: 50 additions & 0 deletions ldaptor/apps/webui/defskin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
from zope.interface import implements
from webut.skin import iskin
from nevow import rend, loaders, tags, util, inevow, static
from formless import webform

class DefaultSkin(rend.Page):
implements(iskin.ISkin)

docFactory = loaders.xmlfile(
util.resource_filename('ldaptor.apps.webui', 'skin-default.html'))

stylesheets = [
'form.css',
'ldaptor.css',
]

def locateChild(self, ctx, segments):
if segments[0] == 'form.css':
return webform.defaultCSS, segments[1:]
if segments[0] == 'ldaptor.css':
dirname = os.path.abspath(os.path.dirname(__file__))
return (static.File(os.path.join(dirname, 'ldaptor.css')),
segments[1:])
else:
return None, ()

def render_title(self, ctx, data):
return ctx.tag.clear()[self.original.resource.title]

def render_head(self, ctx, data):
def links(l, path=None):
for filename in l:
href = filename
if path is not None:
href = path.child(href)
yield tags.link(rel="stylesheet",
type="text/css",
href=href)
ctx.tag.clear()
stylesheets = getattr(self, 'stylesheets', None)
if stylesheets is not None:
ctx.tag[links(stylesheets, path=self.original.pathToFiles)]
stylesheets = getattr(self.original.resource, 'stylesheets', None)
if stylesheets is not None:
ctx.tag[links(stylesheets)]
return ctx.tag

def render_content(self, ctx, data):
return self.original.content
7 changes: 5 additions & 2 deletions ldaptor/apps/webui/delete-nodn.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:nevow="http://nevow.com/ns/nevow/0.1">
xmlns:nevow="http://nevow.com/ns/nevow/0.1"
nevow:render="skin">
<head>
<title nevow:render="i18n">Ldaptor Delete Page</title>
<title>Title Goes Here</title>
</head>
<body>
<nevow:invisible nevow:pattern="skincontent">
<h1 nevow:render="i18n">Ldaptor Delete Page</h1>

<p>
Expand All @@ -16,5 +18,6 @@
<nevow:invisible nevow:render="i18n">You need to use the</nevow:invisible>
<a nevow:render="url"><nevow:invisible nevow:render="i18n">search page</nevow:invisible></a>.
</p>
</nevow:invisible>
</body>
</html>
18 changes: 9 additions & 9 deletions ldaptor/apps/webui/delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from zope.interface import implements
from webut.skin import iskin
from ldaptor.protocols.ldap import ldapsyntax, distinguishedname
from ldaptor.apps.webui.uriquote import uriUnquote
from ldaptor.apps.webui.i18n import _
Expand All @@ -14,6 +15,10 @@ def __init__(self, value):
self.value = value

class ConfirmDelete(rend.Page):
implements(iskin.ISkinnable)

title = _('Ldaptor Delete Page')

docFactory = loaders.xmlfile(
'delete.xhtml',
templateDir=os.path.split(os.path.abspath(__file__))[0])
Expand All @@ -34,15 +39,6 @@ def bind_delete(self, ctx):
label=_('Confirm delete')),
action=_('Delete'))

def data_css(self, ctx, data):
u = (url.URL.fromContext(ctx).clear().parentdir().parentdir()
.child('form.css'))
return [ u ]

def render_css_item(self, context, data):
context.fillSlots('url', data)
return context.tag

def delete(self, ctx):
request = inevow.IRequest(ctx)
user = request.getSession().getLoggedInRoot().loggedIn
Expand Down Expand Up @@ -121,6 +117,10 @@ def render_keyvalue_item(self, context, data):
render_i18n = i18n.render()

class GetDN(rend.Page):
implements(iskin.ISkinnable)

title = _('Ldaptor Delete Page')

addSlash = True

docFactory = loaders.xmlfile(
Expand Down
Loading

0 comments on commit c687e95

Please sign in to comment.