Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 49.483.002 Times

dolmen.forms.base 1.0 Beta 2

Company: Souheil Chelfouh
Date Added: July 16, 2013  |  Visits: 481

dolmen.forms.base

Report Broken Link
Printer Friendly Version


Product Homepage
Download (35 downloads)



dolmen.forms.base is a package in charge of providing basic functionalities to work with zeam.form Forms.<br />From the form to the field<br /><br />dolmen.forms.base provides few functions dedicated to the task of applying dict datas to object fields and to trigger events in order to inform handlers of the updates<br />Applying values<br /><br />We create our test model:<br /><br />>>> from zope.schema import TextLine, Choice<br />>>> from zope.interface import Interface, implements<br /><br />>>> class ICaveman(Interface):<br />... name = TextLine(title=u'a name')<br />... weapon = Choice(title=u'a weapon',<br />... values=[u'none', u'a club', u'a spear'])<br /><br />>>> class Neanderthal(object):<br />... implements(ICaveman)<br />... def __init__(self):<br />... self.name = u"no name"<br />... self.weapon = u"none"<br /><br />>>> moshe = Neanderthal()<br />>>> moshe.name<br />u'no name'<br />>>> moshe.weapon<br />u'none'<br /><br />We can now use the first function, set_fields_data. It takes the fields list, extracted thanks to the Fields collection, the content and the data dictionnary. The result of this call is a dictionnary, with the interface in which the field is defined and the field identifier as a value:<br /><br />>>> from dolmen.forms.base import Fields, set_fields_data<br /><br />>>> fields = Fields(ICaveman)<br />>>> for field in fields: print field<br /><TextLineSchemaField a name><br /><ChoiceSchemaField a weapon><br /><br />>>> data = {u'name': u'Grok', u'weapon': u'a club'}<br /><br />>>> changes = set_fields_data(fields, moshe, data)<br />>>> print changes<br />{<InterfaceClass __builtin__.ICaveman>: [u'weapon', u'name']}<br /><br />>>> moshe.name<br />u'Grok'<br />>>> moshe.weapon<br />u'a club'<br /><br />Values of the data dict can contain markers, to warn of a possible special case : the value is missing or there are no changes. In these two cases, the value assignation is skipped:<br /><br />>>> from dolmen.forms.base import NO_VALUE, NO_CHANGE<br />>>> data = {u'name': NO_VALUE, u'weapon': NO_CHANGE}<br /><br />>>> changes = set_fields_data(fields, moshe, data)<br />>>> print changes<br />{}<br /><br />Generating changes Attributes for events<br /><br />One advantage of generating a dict of changes is that you can trigger event that are aware of a certain format of changes. The IObjectModifiedEvent, for exemple, uses the changes log to trigger the reindexation of the modified fields. The function notify_changes is dedicated to notifying a given event of the applied changes. It takes the content, the changes dict and an event as arguments. If the event argument is omitted, ObjectModifiedEvent is used by default.<br /><br />We first generate a changes dict:<br /><br />>>> data = {u'name': u'Grok', u'weapon': u'a club'}<br />>>> changes = set_fields_data(fields, moshe, data)<br />>>> print changes<br />{<InterfaceClass __builtin__.ICaveman>: [u'weapon', u'name']}<br /><br />We can now set a logger for the IObjectModifiedEvent, in order to check if the changes are being broadcasted:<br /><br />>>> from zope.component import adapter, provideHandler<br />>>> from zope.lifecycleevent import IObjectModifiedEvent<br /><br />>>> logger = []<br /><br />>>> @adapter(ICaveman, IObjectModifiedEvent)<br />... def changes_broadcasted(content, event):<br />... logger.append(event.descriptions)<br /><br />>>> provideHandler(changes_broadcasted)<br /><br />We can now feed it to the function:<br /><br />>>> from dolmen.forms.base import notify_changes<br />>>> change_log = notify_changes(moshe, changes)<br /><br />The logger must have been trigged. We can check its value:<br /><br />>>> logger<br />[(<zope.lifecycleevent.Attributes object at ...>,)]<br /><br />>>> for attrs in logger[0]:<br />... print attrs.interface, attrs.attributes<br /><InterfaceClass __builtin__.ICaveman> (u'weapon', u'name')<br /><br />Field update event<br /><br />dolmen.forms.base also proposes the definition of a new component that can be used to atomize the updating process of an object: IFieldUpdate.<br /><br />To demonstrate this IFieldUpdate, we are going to implement a simple usecase where we instanciate a content, change a value and notify the IFieldUpdate components. For that, we'll use a basic logger object:<br /><br />>>> logger = []<br /><br />Once this is done, we can define two IFieldUpdate components. We implement them as named adapters. We'll retrieve them thanks to a "getAdapters" call:<br /><br />>>> from zope.interface import implementer<br />>>> from dolmen.forms.base import IFieldUpdate<br /><br />>>> @implementer(IFieldUpdate)<br />... @adapter(TextLine, ICaveman)<br />... def updated_title(field, context):<br />... if field.__name__ == u"name":<br />... logger.append('Name updated on %r with `%s`' %<br />... (context, getattr(context, field.__name__)))<br /><br />>>> @implementer(IFieldUpdate)<br />... @adapter(TextLine, Interface)<br />... def updated_textfield(field, context):<br />... logger.append('A text field has been updated')<br /><br />The components need to be named since they are adapters: we don't want them to override each other. For the example, we want them both. let's register them:<br /><br />>>> from zope.component import provideAdapter<br />>>> provideAdapter(updated_title, name="updatetitle")<br />>>> provideAdapter(updated_textfield, name="updatetext")<br /><br />Now, we develop the small scenarii : we instanciate a Content, add a value for the name attribute and call the adapters:<br /><br />>>> manfred = Neanderthal()<br />>>> manfred.name = u"Manfred the Mighty"<br /><br />>>> from zope.component import getAdapters<br />>>> adapters = getAdapters((ICaveman['name'], manfred), IFieldUpdate)<br />>>> for adapter in adapters:<br />... # We run through the generator<br />... pass<br /><br />>>> for line in logger: print line<br />Name updated on <Neanderthal object at ...> with `Manfred the Mighty`<br />A text field has been updated<br /><br />The form model<br /><br />dolmen.forms.base provides a form baseclass defining several useful methods and overriding some default behavior from zeam.form.<br /><br /> >>> from zope.interface import implementedBy<br /> >>> from dolmen.forms.base import ApplicationForm<br /><br />The provided component, ApplicationForm, inherits from the base zeam.form components and implements some extra methods, allowing it to fit into your application, such as flash, to emit messages to given sources. It's also layout aware:<br /><br />>>> for interface in implementedBy(ApplicationForm):<br />... print interface<br /><InterfaceClass megrok.layout.interfaces.IPage><br /><InterfaceClass zeam.form.base.interfaces.ISimpleForm><br /><InterfaceClass zeam.form.base.interfaces.ISimpleFormCanvas><br /><InterfaceClass zeam.form.base.interfaces.IGrokViewSupport><br /><InterfaceClass zeam.form.base.interfaces.IFormData><br /><InterfaceClass zope.publisher.interfaces.browser.IBrowserPage><br /><InterfaceClass zope.browser.interfaces.IBrowserView><br /><InterfaceClass zope.location.interfaces.ILocation><br /><br />As zeam.form uses Chameleon as a template engine, it is import we are able to compute the current request locale, in order to get the right translation environment:<br /><br />>>> from grokcore.component import Context<br />>>> from zope.publisher.browser import TestRequest<br /><br />>>> item = Context()<br />>>> request = TestRequest()<br /><br />>>> form = ApplicationForm(item, request)<br />>>> print form.i18nLanguage<br />None<br /><br />>>> request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': "en,fr"})<br />>>> form = ApplicationForm(item, request)<br />>>> print form.i18nLanguage<br />en<br /><br />Further more, the ApplicationForm overrides the extractData method from the zeam.form Form in order to compute the interfaces invariants.<br />Declaring the invariants<br /><br /> >>> from zope.schema import Password<br /> >>> from zope.interface import invariant, Interface<br /> >>> from zope.interface.exceptions import Invalid<br /><br /> >>> class IPasswords(Interface):<br /> ... passwd = Password(<br /> ... title=u"Password",<br /> ... description=u"Type the password.",<br /> ... required=True)<br /> ...<br /> ... verify = Password(<br /> ... title=u"Password checking",<br /> ... description=u"Retype the password.",<br /> ... required=True)<br /> ...<br /> ... @invariant<br /> ... def check_pass(data):<br /> ... if data.passwd != data.verify:<br /> ... raise Invalid(u"Mismatching passwords!")<br /><br /> >>> from zeam.form.base import Fields<br /> >>> from grokcore.component import testing<br /><br /> >>> class MyForm(ApplicationForm):<br /> ... ignoreContent = True<br /> ... ignoreRequest = False<br /> ... fields = Fields(IPasswords)<br /><br />Default behavior<br /><br /> >>> form = MyForm(item, request)<br /> >>> form.update()<br /> >>> form.updateForm()<br /> >>> data, errors = form.extractData()<br /><br /> >>> print data<br /> {'passwd': <Marker NO_VALUE>, 'verify': <Marker NO_VALUE>}<br /><br /> >>> for error in errors:<br /> ... print error.title<br /> Missing required value.<br /> Missing required value.<br /> There were errors.<br /><br /> >>> for error in form.formErrors:<br /> ... print error.title<br /> There were errors.<br /><br />Errors computing<br /><br /> >>> post = TestRequest(form = {'form.field.passwd': u'test',<br /> ... 'form.field.verify': u'fail'})<br /> >>> form = MyForm(item, post)<br /> >>> form.update()<br /> >>> form.updateForm()<br /> >>> data, errors = form.extractData()<br /><br /> >>> print data<br /> {'passwd': u'test', 'verify': u'fail'}<br /><br />The returned error is a collection of Error components. Using the form prefix as an identifier, it logically wraps all the errors created by the invariants validation:<br /><br />>>> for error in form.formErrors:<br />... print error.title<br />Mismatching passwords!<br /><br />>>> form.errors.get(form.prefix) == form.formErrors[0]<br />True<br /><br />Mixed Fields<br /><br />There are two types of fields, one from zeam.form.base, the other from zope.schema. They are both useable in a form, separately or mixed:<br /><br />>>> from zeam.form.base import Field<br />>>> from dolmen.forms.base import Fields<br />>>> class MixedForm(ApplicationForm):<br />... ignoreContent = True<br />... ignoreRequest = False<br />... fields = Fields(IPasswords) + Field(u'Name')<br /><br /><br />>>> mixedform = MixedForm(item, post)<br />>>> mixedform.update()<br />>>> [x.title for x in mixedform.fields]<br />[u'Password', u'Password checking', u'Name']<br /><br />>>> mixedform.updateForm()<br />>>> data, errors = mixedform.extractData()<br /><br />>>> print form.formErrors<br />[<Error Mismatching passwords!>]<br /><br />>>> for error in form.formErrors:<br />... print error.title<br />Mismatching passwords!<br /><br />#md5=cd8bdf86bad0b3f19db6738145b3561a

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Adapters Class Components Dolmenformsbase Error Errors Event Field Fields Gtgtgt Import Logger Print Request U039a Weapon Zeamform Zopeinterface
Users rating: 0/10

License: Freeware Size: 10.24 KB
USER REVIEWS
More Reviews or Write Review


DOLMEN.FORMS.BASE RELATED
Libraries  -  XML::Essex::Event 0.01
XML::Essex::Event is a base event class, also used for unknown event types. Stringifies as $event->type . "()" to indicate an event that has no natural way to represented in XML, or for ones that havent been handled yet in Essex. Methods new...
43.01 KB  
Utilities  -  boom 2.6
boom - business open operations manager - is an enterprise-class distributed client-server systems event and fault monitoring solution that helps IT departments to prevent, detect and solve problems on their managed systems, hosts, applications...
352.86 MB  
Libraries  -  Exception::Class::TryCatch 1.10
Exception::Class::TryCatch is a syntactic try/catch sugar for use with Exception::Class. SYNOPSIS use Exception::Class::TryCatch; # simple usage of catch() eval { Exception::Class::Base->throw(error) }; catch my $err and warn $err->error;...
15.36 KB  
Libraries  -  Danga::Socket 1.56
Danga::Socket is an event loop and event-driven async socket base class. SYNOPSIS package My::Socket use Danga::Socket; use base (Danga::Socket); use fields (my_attribute); sub new { my My::Socket $self = shift; $self =...
18.43 KB  
Modules  -  Event Repeat Views 5.x-1.x-dev 1.0
It also allows to only see distinct event repetitions.InstallationUnpack in your modules folder (usually /sites/all/modules/) and enable under Administer > Site Building > Modules. Requirements: - Drupal 5.x - Drupal Event module - Drupal Event...
 
Modules  -  Form Dependencies 5.x-1.x-de
This module allows you to mark form fields to be dependent of another form field. Using #dependency you can provide an array to point to the field that needs a value before the field with setting #dependency will be displayed. The naming of the...
10 KB  
Libraries  -  Class::Meta::Declare 0.04
Class::Meta::Declare is a Perl module deprecated in favor of Class::Meta::Express. SYNOPSIS This was a first attempt at making a saner interface for Class::Meta. It is nicer, but Class::Meta::Express is nicer still. Go use that one. package...
15.36 KB  
Libraries  -  SGMLS 1.03ii
SGMLS is a Perl class for postprocessing the output from the sgmls and nsgmls parsers. SYNOPSIS use SGMLS; my $parse = new SGMLS(STDIN); my $event = $parse->next_event; while ($event) { SWITCH: { ($event->type eq start_element) && do...
93.18 KB  
Miscellaneous  -  All base class initializers get called 1.4
This code can be used in debugging phase to notice errors sooner. It is usually always desirable to visit all base class __init__-methods, but Python does nothing to ensure they will be visited. Set AssertInit as a metaclass in the base class of...
 
Development Tools  -  Page Guard Pro for HTML Tools 1.1
If there is an error on your web page like file not found or failed script, the Page Guard will come in action. It replaces errors and logs them.Features:- Script replaces the nasty looking error pages.- Explain the web error to the visitor in a...
20.48 KB  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
Linux Software  -  EasyEDA PCB Designer for Linux 2.0.0
EasyEDA, a great web based EDA(Electronics Design Automation) tool, online PCB tool, online PCB software for electronics engineers, educators, students, makers and enthusiasts. Theres no need to install any software. Just open EasyEDA in any...
34.4 MB  
Linux Software  -  wpCache® WordPress HTTP Cache 1.9
wpCache® is a high-performance, distributed object, caching system application, generic in nature, but intended for use in speeding up dynamic web applications, by decreasing database load time. wpCache® decreases dramatically the page...
3.51 MB  
Linux Software  -  Polling Autodialer Software 3.4
ICTBroadcast Auto Dialer software has a survey campaign for telephone surveys and polls. This auto dialer software automatically dials a list of numbers and asks them a set of questions that they can respond to, by using their telephone keypad....
488 B  
Linux Software  -  Total Video Converter Mac Free 3.5.5
Total Video Converter Mac Free developed by EffectMatrix Ltd is the official legal version of Total Video Converter which was a globally recognized brand since 2006. Total Video Converter Mac Free is a free but powerful all-in-one video...
17.7 MB  
Linux Software  -  Skeith mod_log_sql Analyzer 2.10beta2
Skeith is a php based front end for analyzing logs for Apache using mod_log_sql.
47.5 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB