Skip to main content

A few litle but useful adapters

Project description

Short description of ng.adapter

This package has developed as the library of small adapters for the
different dark purposes.

Adapter mtime

Adapter mtime intdends for getting object modification time. Object
modification time determine on the IPersistent level and this is an exactly
in the most cases, but sometimes we need some of hooks to know object
modification time and adapter mtime helps us in this.

Adapter mtime adapts IPersistent interface to IMTime interface. IMTime interface
has the following fields:

time of the last modification of object

return time as format string, fromat see in man strftime

Adapter path

Adapter path intends for getting path from root object to current, Adapter can adopt
any objects to IPath interface. Interface IPath provide followed fields:

Path from root to current object maked from attribute __name__ of object in between;

Path from root to current object maked from titles object in between. Titles getting from
adapter title (ITitle interface);

Adapter title

Adapter title intends for getting object title (for any object). Adapter can adopt
any objects to ITitle interface. Interface IPath provide followed fields:

Object title

If current object has not title property, property title of object, adopted
ti IZopeDublinCore return instead, If adopt to IZopeDublinCore is not possible,
property __name__ or class name return instead.

Adapter has been wrote in goot component style and it's posible to write adapter
to ITitle for any specific cases.

Adapter nsinterface

Adapter nsinterface define nsinterface namespace to get possibility adopt current
object to any interfacr. Some syntax sample followed::

<tal:block define="path context/++nsinterface++ng.adapter.IPath/path">


It usefaul, basicaly, in debugging purpose.

A few adapters to INameChooser

If any of this adapters will be actvated to some container, object, created in this
container will be accept __name__ from ITitle adapter. To activate adapter interface one of marker interfaces
are to set to container. There are three INameChooser adapter:

This adapter turn on by ng.adapter.interfaces.INameChooserAble. Adapter set __name__ from ITitle
adapter without any changes.

This adapter turn on by ng.adapter.interfaces.INameChooserSafeAble.
Before set as __name__ adapter changing string accepted from ITitle to
discard a few symbols not recommended in URL: '/', '?' and other.

This adapter turn on by ng.adapter.interfaces.INameChooserSafeWithoutSpacesAble.
Before set as __name__ adapter changing string accepted from ITitle to
discard a few symbols not recommended in URL: '/', '?' and other. Adapter replace white-spaces
by '_'symbol also.

Adapter pager

Adapter allow make pagers by list adopted to IPagerSource. Adapter quicly
doing all evaluatiion needed to provede ready results as methods.

Product content adapters from components with interfaces IContainer, IOrderedContainer and
ResultSet (returned by zope.catalog).

Список методов IPager

setPagerParameters(revert=None, orphan=None,size=None)
Set pager parameters:

Show list reverted;

Maximum orphaned items;

One page chunk size;

True, if page before current exist;

Key list from previos pages begins;

URL list of previous pages;

Previous page;

beforeURL = Field()
URL of prefvious page;

Component list showed in current chunk (page);

Key of first item on next page;

URL of next page;

Key list of first items on followed pages;

URL list of nest pages;

True, if next page exist;

Common length of list;

Code Sample::

<tal:block tal:condition="python:len(context) > 0">
<table cellspacing="0" cellpadding="3" bgcolor="#CCDDFF" width="100%"
border="1" bordercolor="black" bordercolordark="#CCDDFF">
<p class="docttl">Вложенные материалы

<tal:block define="pager context/@@pager">
<tal:block define="q python:pager.setPagerParameters(revert=True)"/>

<tr tal:condition="pager/have_before"><td align="left">
<a href="" tal:attributes="href pager/beforeURL"> &lt;&lt;&lt;&lt;&lt;&lt;</a>
<tal:block repeat="item python:zip(range(1,10),pager.beforeURLs)">
[<a href="" tal:attributes="href python:item[1]" tal:content="python:item[0]"/>]

<div tal:repeat="item pager/chunk">
tal:block tal:on-error="structure python:'<tr><td>'+item.__name__+'</td></tr>'"
tal:content="structure item/@@short"/>

<tr tal:condition="pager/have_after"><td align="right">
<tal:block repeat="item python:zip(range(1,10),pager.afterURLs)">
[<a href="" tal:attributes="href python:item[1]" tal:content="python:item[0]"/>]
<a href="" tal:attributes="href pager/afterURL"> &gt;&gt;&gt;&gt;&gt; </a>



Adapter recordsize

Apapter allow get object record size of ZODB. Any object can be adopted to
ng.adapter.recordsize.IRecordSize interface and size can be read from size
attribute. IRecordSize interface contents:

Object record size;

Object size evaluated by means of transformation into filestorage-like

Adapter checktocontain
Adapter define name space **++checktocontain++** to allow check possibility context to contain the class from paramenter.
Usualy namespace used in different adding-like menu::

menu = "profilemenu"
title = "Add Image"
for = "ng.content.article.interfaces.ICommonContainer"
action = "+/AddPhoto.html="
filter = "context/"
permission = "zope.ManageContent"

The parameter **filter** contain code to return True if **** can be contained in **context**

Adapter requestcache
The **requestcache** adapter can adopt **IHTTPRequest** request to IRequestCache interface. IRequestCache provide
method to set cache headers:

Set cache headers to cache during **period** second;

Set cache headers to avoid cacheing;

Adapter provide view **@@requestcache** with methods cache and nocache. Cache headers setted by the view can
be managed by **IRegistry** keys mentioned below:

request_cache_use (True/False)
Allow or deny cache management use. When parameter is False cache headers not set at all;

request_cache_period (int)
Set cache period;

request_cache_use_as_nocache (True/False)

Deny use any cache. When parameter is True cache headers set to deny cache by **nocache** method.

The "toolchanger" tool set
The "**toolchanger**" tool set allow to make rare choice of view
during site navigtion.

Each site component provide a few views allowed unique interaction with the
component. The toolURL is adapter allow to generate URL based on choice maked
user in past. There is simple using sample::

<tal:block tal:repeat="ob context/values">
<a href="" tal:attributes="ob/@@toolURL" tal:content="ob/title"/>

Algorithm of view selection requires unification view names: all views provided
by different components and named equally allow to execute similar
operations. Therefore choice selected by user is preferable choice in subsequent
site navigation, Name of view choosed by user are stored
in URL. Code in sample above check existence of view with the same name for
other object and, if it possible, URL to call it is generated. Default method used
otherwise. Using this idea allow to strong simplify site navigation.

Unification of view names has to enforced during site development.

* Sun Jul 12 2009 Andrey Orlov <> 0.2.1
- Two new adapters to INameChoose added. NameChooseSafe translate title to
name without forbidden URL symbols ("/", "?" and other),
NameChooserSafeWithoutSpace - to name without forbidden symbols and

* Wed Feb 11 2009 Andrey Orlov <> 0.2.0
- Adapter ICheckSublocation added
- Adapter IBreadCrumb added
- Adapter IPager behaviour changed on setPagerParameters
- Some debug information excluded

* Mon Oct 20 2008 Andrey Orlov <> 0.1.10
- Toolset "toolchanger" added
- Adapter RequestCache added

* Tue Sep 23 2008 Andrey Orlov <> 0.1.9
- Namespace ++checktocontain++ added

* Tue Feb 19 2008 Andrey Orlov <> 0.1.8
- NullSublocations adapter added
- AdaptiveURL adapter added
- Fault tolerance of ianytitle enchanced and some diagnostics added

* Wed Feb 13 2008 Andrey Orlov <> 0.1.7
- A ranging in ianytitle reverted

* Wed Feb 06 2008 Andrey Orlov <> 0.1.6
- A few bugs fixed in ianytitle, ranging alghorithm enchanced;
- Some logging excluded;
- IRegisry lookup changed in pager;

* Wed Jan 23 2008 Andrey Orlov <> 0.1.5
- added function for format string into mtime adapter

* Mon Jan 21 2008 Andrey Orlov <> 0.1.4
- Registry fixed

* Mon Jan 21 2008 Andrey Orlov <> 0,1,3
- IAnyTitle adapter added

* Tue Jan 15 2008 Andrey Orlov <> 0.1.2
- Recordsize adapter added.

* Sat Jan 5 2008 Andrey Orlov <> 0.1.1
- Some dependencies fixed

* Sun Dec 2 2007 Andrey Orlov <> 0.1.0
- Followed adapters added: namechooser, nsinterface, pager, path,
requestext, title

* Fr Nov 16 2007 Yegor Shershnev <> 0.0.1
- first official release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ng.adapter, version 0.2.1
Filename, size & hash File type Python version Upload date
ng.adapter-0.2.1.tar.gz (35.5 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page