Prepopulate

As of Collective Access version 1.5, Prepopulate automatically prepopulates fields in CollectiveAccess records based on Display Templates and Expressions.

Setup

The core configuration is done in app/conf/prepopulate.conf. There are two settings that control when the prepopulate rules kick in:

  1. On record save, prepopulate_fields_on_save

  2. Each time an editor is opened, prepopulate_fields_on_edit

Both settings are turned off by default. Set one or both of these settings to 1 to enable the feature.

The main part of the configuration is a list of rules under prepopulate_rules. Each rule should have a unique code, e.g. test_rule, in the example block below:

prepopulate_rules = {
     # -------------------
     test_rule = {
             # what types of records does this rule apply to?
             table = ca_objects,
             #restrictToTypes = [artwork],

             # mode determines handling of existing values in target element
             # can be overwrite, or addIfEmpty
             # See the 'target' setting below and http://docs.collectiveaccess.org/wiki/Prepopulate
             mode = addIfEmpty,

             # What's the prepopulate target?
             # This can be an intrinsic field, labels or an attribute.
             #
             # Note that if you want to target a List attribute, you have to
             # provide a valid list item idno or id for that list as value!
             #
             # See http://docs.collectiveaccess.org/wiki/Prepopulate
             target = ca_objects.title_notes,

             # skip this rule if expression returns true
             # available variable names are bundle names
             #skipIfExpression = ^ca_objects.idno =~ /test/,

             # content to prepopulate
             # (this is a display template evaluated against the current record)
             template = ^ca_objects.preferred_labels (^ca_objects.idno),
     },
     # -------------------
}

Prepopulate Rule Settings

Setting Name

Type

Description

Example

table

Valid CollectiveAccess table name

Defines what table this rule applies to

ca_objects

restrictToTypes

Optional list of valid items from the type list for table

Optional type restriction for this rule

[artwork, image]

mode

One of addIfEmpty, overwrite, merge

Determines handling of existing values in target element. addIfEmpty: set relationships only if none exist overwrite: replace relationships merge: add relationships that do not already exist

addIfEmpty

target

A valid bundle specifier for either an instrinsic field, labels, or an attribute

Determines the prepopulate target. Note that if you want to target a List attribute, you have to provide a valid list item idno or id for that list as value

[ca_objects.description]

skipIfExpression

A valid expression

Allows for rule based skipping of the rule. If the expression result is true, the rule is ignored for the current record

^ca_objects.object_status_new!~ /deaccessioned/

template

A valid template

This defines the actual content that is injected into the target element. The display template is evaluated against the current record.

^ca_objects.medium_container.menu ^ca_objects.medium_container.support

context

Parent, children, or related

parent: copy relationships from the parent children: copy relationships from children related: copy relationships from related records (e.g., if table = ca_objects, and target = ca_entities, copy all entity relationships from related objects)

Parent

restrictToRelationshipTypes

Valid relationship type

For use with context (above). Use this setting to only copy relationships with the specified relationship type codes

Author

excludeRelationshipTypes

Valid relationship type

For use with context (above). Don’t copy relationships with these specified relationship type codes

Creator

restrictToRelatedTypes

Valid record type

For use with context (above). Only copy relationships pointing to specified types

Artwork

excludeRelatedTypes

Valid record type

For use with context (above). Don’t copy relationships pointing to specified types

Archival

currentOnly

1 or 0

For use with context (above). Only consider current relationships, such as current storage location

0

An example use of “context” configuration:

related_entities = {
 table = ca_objects,

 # add relationships that do not already exist
 mode = merge,

 # copy all entities related to objects related to the target record
 target = ca_entities,
 context = related,

 # copy only those entities related with the relationship type "artist"
 restrictToRelationshipTypes = [artist],

 # don't copy relationships with specified relationship type codes;
 #excludeRelationshipTypes = [],

 # copy only entities that are the type "individual"
 restrictToRelatedTypes = [ind],

 # don't copy relationships pointing to specified types
 #excludeRelatedTypes = [],

 # only consider "current" relationships – Eg. current storage location
 currentOnly = 0,
},

Flowchart

../../_images/prepopulate.jpg