Prepopulate

From CollectiveAccess Documentation
Jump to: navigation, search

Prepopulate is a new feature for v1.5. It allows you to automatically prepopulate 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 (more on those below) kick in: Either on record save and/or every time you open an editor (prepopulate_fields_on_save and/or prepopulate_fields_on_edit). Both 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. Below is an example block. Each rule should have a unique code, e.g. test_rule in the 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),
	},
	# -------------------
}

Below is a short description for each of the rule settings:

Setting name Type Example Description
table Valid CollectiveAccess table name ca_objects Defines what table this rule applies to
restrictToTypes optional list of valid items from the type list for table [artwork, image] Optional type restriction for this rule
mode One of addIfEmpty, overwrite, merge addIfEmpty Determines handling of existing values in target element. See flowchart below. addIfEmpty: set relationships only if none exist; overwrite: replace relationships; merge: add relationships that do not already exist
target A valid bundle specifier for either a intrinsic field, labels or an attribute [ca_objects.description] 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!
skipIfExpression A valid expression ^ca_objects.object_status_new !~ /deaccessioned/ Allows for rule based skipping of the rule. If the expression result is true, the rule is ignored for the current record.
template A valid template ^ca_objects.medium_container.medium ^ca_objects.medium_container.support This defines the actual content that is injected into the target element. The display template is evaluated against the current record.
context parent, children, or related parent parent = copy relationships from the parent; children = copy relationships from children; related = copy relationships from related records (Eg. if table = ca_objects and target = ca_entities copy all entity relationships from related objects)
restrictToRelationshipTypes Valid relationship type author For use with "context." Use this setting to only copy relationships with the specified relationship type codes
excludeRelationshipTypes Valid relationship type creator For use with "context." Don't copy relationships with these specified relationship type codes
restrictToRelatedTypes Valid record type artwork For use with "context." Only copy relationships pointing to specified types.
restrictToRelatedTypes Valid record type artwork For use with "context." Only copy relationships pointing to specified types.
excludeRelatedTypes Valid record type archival For use with "context." Don't copy relationships pointing to specified types.
currentOnly 1 or 0 0 For use with "context." Only consider "current" relationships – Eg. current storage location

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

Prepopulate.jpg

sphinx

Namespaces

Variants
Actions
Navigation
Tools
User
Personal tools