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

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

Serving Software Downloads in 976 Categories, Downloaded 31.009.068 Times

dolmen.forms.base 1.0 Beta 2

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


Report Broken Link
Printer Friendly Version

Product Homepage
Download (17 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 />... = u"no name"<br />... self.weapon = u"none"<br /><br />>>> moshe = Neanderthal()<br />>>><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 />>>><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 />>>> = 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
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  
Productivity  -  HcBookingOnline 1.0
The application is for appointment management for Sansiri home care related issue. Feature listed as follow. 1. Appointment calendar. 2. Event management. 3. Internal Home care service request. However the application is for Sansiri...
2.8 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  -  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  -  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  
Libraries  -  Exception::System 0.0601
Exception::System is the exception class for system or library calls. SYNOPSIS # Loaded automatically if used as Exception::Bases argument use Exception::Base Exception::System, Exception::File => { isa => Exception::System }; try...
10.24 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...
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  
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  
Linux Software  -  SLAX 6.0+
Slax is a modern, portable, small and fast Linux operating system with a modular approach and outstanding design. Despite its small size, Slax provides a wide collection of pre-installed software for daily use, including a well organized graphical...
190 KB  
Linux Software  -  GTK+ 2.5
GTK+, which stands for the GIMP Toolkit, is a library for creating graphical user interfaces for the X Window System. It is designed to be small, efficient, and flexible. GTK+ is written in C with a very object-oriented approach. Language bindings...
60 MB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by, it is used to describe information about an application such as the name and...
327.68 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  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB