This is what the setattr
function does:
setattr(g, 'var', 5) # g.var is now 5
The arguments passed to setCustAttr
are exactly the arguments you would pass to setattr
.
def setCustAttr(self, name, value):
setattr(self, name, value)
Why would you want a wrapper around setattr
? You might try to perform some validation:
def setCustAttr(self, name, value):
if name not in ['bar', 'baz']:
raise ValueError("Custom attribute must be 'bar' or 'baz'")
if name == 'bar'
and value < 0:
raise ValueError("'bar' attribute must be non-negative")
if name == 'baz'
and value % 2:
raise ValueError("'baz' attribute must be even")
setattr(self, name, value)
However, this doesn't prevent the user of your class from ignoring your setCustAttr
method and assigning directly to the object:
g = MyClass() g.bar = -5 # Negative bar! g.baz = 3 # Odd baz! g.quux = 2 # Non - bar / baz attribute!
OMBDEFINE CLASS_DEFINITION enables you to create new object definitions in the workspace.,To create a new module definition, use the following command:,Use the command OMBREDEFINE on the workspace object to which you want to add a custom property definition.OMBDEFINE FOLDER_DEFINITION,To create a UDP on the Dimension object, use the following command:
To create a new module definition, use the following command:
OMBDEFINE MODULE CLASS_DEFINITION 'UD_TABLEMODULE'
SET PROPERTIES
(BUSINESS_NAME, PLURAL_NAME) VALUES('Table Module', 'Table Modules')
To create a UDP on the Dimension object, use the following command:
OMBREDEFINE CLASS_DEFINITION 'DIMENSION'
ADD PROPERTY_DEFINITION 'UD_DOCID'
SET PROPERTIES(TYPE, DEFAULT_VALUE)
VALUES('INTEGER', '100')
The following command adds a new property definition for notes for the COLUMN
type. Because columns exist in tables, views, materialized view, external tables and sequences, the following command adds the definition of this property to columns for all of those metadata objects:
OMBREDEFINE CLASS_DEFINITION 'COLUMN'
ADD PROPERTY_DEFINITION 'UD_COL_NOTE'
SET PROPERTIES(TYPE, DEFAULT_VALUE)
VALUES('STRING', 'notes')
To delete a UDP, use a command such as
OMBREDEFINE CLASS_DEFINITION 'TABLE'
DELETE PROPERTY_DEFINITION 'UD_TBL_NOTE'
You can use OMBDESCRIBE
on any class definition to view the attributes for a metadata element. Among other tasks, use OMBDESCRIBE
to list all the property definitions including the UDPs for a given object type. For instance, the following command lists the UDPs for dimensions:
OMBDESCRIBE CLASS_DEFINITION 'DIMENSION'
GET USER_DEFINED PROPERTY_DEFINITIONS
Ensure that you are in single user mode. You can verify this with the command OMBDISPLAYCURRENTMODE
. If you are in multiple user mode, then switch to single user mode by using the command:OMBREDEFINE CLASS_DEFINITION 'VIEW
OMBSWITCHMODE SINGLE_USER_MODE
OMBREDEFINE CLASS_DEFINITION 'VIEW'\
ADD PROPERTY_DEFINITION 'UD_OWNER'
SET PROPERTIES\
(TYPE, DEFAULT_VALUE, BUSINESS_NAME) VALUES\('STRING', 'REP_OWNER', 'Object Owner')
OMBREDEFINE CLASS_DEFINITION 'VIEW'\
ADD PROPERTY_DEFINITION 'UD_FILE'
SET PROPERTIES\
(TYPE, DEFAULT_VALUE) VALUES('FILE', 'C:\\vw.sql')
OMBREDEFINE CLASS_DEFINITION 'VIEW'\
ADD PROPERTY_DEFINITION 'UD_LINK'
SET PROPERTIES\
(TYPE, DEFAULT_VALUE) VALUES('URL', 'http://www.oracle.com')
OMBREDEFINE CLASS_DEFINITION 'VIEW'\
ADD PROPERTY_DEFINITION 'UD_VERSION'
SET PROPERTIES\
(TYPE, DEFAULT_VALUE) VALUES('DATE', '2006-1-7')
First, let's create the form that will display when adding an attribute of this type. If you add type_form.php and a type_form() method to the controller, that method will be run every time an attribute of this type is added or updated, and the form will be rendered at the same time as well.,Now that we're saving the settings properly, let's modify our Type Form so that when we edit attributes of this type, the proper settings are selected. type_form() becomes this:,We'll start out with an empty method. Then let's create this type_form.php template in application/attributes/property_location/type_form.php:,The 'formDisplayMethod' form value will be included in the post when the attribute key is created or updated. Now we need to create an object to store that value, and join the form to the entity in the controller.
First, change the controller to inherit from the default base attribute controller. This:
class Controller extends\ Concrete\ Attribute\ Number\ Controller
becomes this
use Concrete\ Core\ Attribute\ Controller as AttributeController;
class Controller extends AttributeController
Then, let's add the search indexing for an integer into this attribute controller:
protected $searchIndexFieldDefinition = array('type' => 'integer', 'options' => array('default' => 0, 'notnull' => false));
First, let's create the form that will display when adding an attribute of this type. If you add type_form.php
and a type_form()
method to the controller, that method will be run every time an attribute of this type is added or updated, and the form will be rendered at the same time as well.
public
function type_form() {
}
We'll start out with an empty method. Then let's create this type_form.php
template in application/attributes/property_location/type_form.php
:
<fieldset>
<legend><?=t('Location Settings')?></legend>
<div class="form-group">
<label class="control-label" for="formDisplayMethod">Form Display Method</label>
<select class="form-control" name="formDisplayMethod">
<option value="select">Select Menu</option>
<option value="radio_list">Radio Button List</option>
</select>
</div>
</fieldset>
01/25/2022
A custom attribute declaration begins with the System.AttributeUsageAttribute, which defines some of the key characteristics of your attribute class. For example, you can specify whether your attribute can be inherited by other classes or specify which elements the attribute can be applied to. The following code fragment demonstrates how to use the AttributeUsageAttribute.
[AttributeUsage(AttributeTargets::All, Inherited = false, AllowMultiple = true)]
[AttributeUsage(AttributeTargets::All, Inherited = false, AllowMultiple = true)]
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
<AttributeUsage(AttributeTargets.All, Inherited:=False, AllowMultiple:=True)> Public Class SomeClass Inherits Attribute '... End Class
[AttributeUsage(AttributeTargets::Class | AttributeTargets::Method)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Method)> Public Class SomeOtherClass Inherits Attribute '... End Class