Glom Python Documentation¶
This API may be used in Glom field calculations or button scripts. Field
calculations have a glom_1_32.Record
parameter. Button scripts have a
glom_1_32.Record
parameter and a glom_1_32.UI
parameter.
-
class
glom_1_32.
Record
¶ This is the current record of the current table. A
Record
object is passed to field calculations and button scripts, providing access to the values of the fields in that record. TheRecord
object passed to field calculations is read-only.- Field values
Use record[‘field_name’] to get the value of a specified field in the current record. For instance, this concatenates the values of the name_first and name_last fields in the current record.
record['name_first'] + ' ' + record['name_last']
You may also use this syntax to set the value of a field in the current record. This is possible in a button script, but not in a field calculation. For instance, this sets the value of the name_first field in the current record.
record['name_first'] = 'Bob'
- Related Records
- Use the
related
attribute to access related records via a relationship. - Testing for Empty Values
How you test for empty values depends on the type of field.
- Non-Text Fields
Non-text fields may be empty, indicating that the user has not entered any value in the field. For instance, Glom does not assume that an empty value in a numeric field should mean 0. You can test whether a field is empty by using Python’s None. For instance.
if(record['contact_id'] == None): return 'No Contact' else: return record.related['contacts']['name_full']
- Text Fields
For text fields, you should check for zero-length strings. It is not possible in Glom to distinguish between zero-length strings and the absence of any string, because there is no advantage to doing so. For instance:
if(record['name_full'] == ''): return 'No Name' else: return record['name_full']
-
connection
¶ The current database connection for use with the gi.repository.Gda API. This is a
Gda.Connection
object.
Related
records. Use the [‘relationship_name’] notation with this object.
-
table_name
¶ The name of the current table as a string.
-
class
glom_1_32.
Related
¶ This object provides access to related records via its [] syntax, which takes a relationship name and returns a
RelatedRecord
. For instance, this provides the related records for the current record, via theRecord.related
attributerecord.related['location']
-
class
glom_1_32.
RelatedRecord
¶ One or more related records, returned by the [] syntax on a
Related
object, such as theRecord.related
attribute.- Single Related Records
For relationships that specify a single record, you can get the value of a field in that record by using the [] synax, providing a field name. For instance, this is the value of the name field in the table indicated by the location relationship (often called location::name).
record.related['location']['name']
- Multiple Related Records
For relationships that specify multiple records, you can use the aggregate functions to get overall values. For instance, this provides the sum of all total_price values from all of the lines of the current invoice record. See the
RelatedRecord
class for more aggregate functions.record.related['invoice_lines'].sum('total_price')
-
count
()¶ Count all values in the field in the related records.
Parameters: field_name (string) – The name of the field. Returns: The summarized value.
-
max
()¶ Maximum of all values of the field in the related records.
Parameters: field_name (string) – The name of the field. Returns: The summarized value.
-
min
()¶ Minimum of all values of the field in the related records.
Parameters: field_name (string) – The name of the field. Returns: The summarized value.
-
sum
()¶ Add all values of the field in the related records.
Parameters: field_name (string) – The name of the field. Returns: The summarized value.
-
class
glom_1_32.
UI
¶ A collection of methods to programatically change the Glom UI, performing some tasks that might otherwise be done by the user via the mouse and keyboard. A
UI
object is passed to button scripts, allowing them to control the user interface.-
print_layout
()¶ Print the current layout for the current table.
-
print_report
()¶ Print the specified report for the current table.
Parameters: report_name (string) – The name of the report to print.
-
show_table_details
()¶ Navigate to the specified table, showing its details view for the specified record.
Parameters: - table_name (string) – The name of the table to navigate to.
- primary_key_value – The value of the primary key field in the record to navigate to.
-
show_table_list
()¶ Navigate to the specified table, showing its list view.
Parameters: table_name – The name of the table to navigate to. :type table_name: string
-
start_new_record
()¶ Start a new empty record for the current table, offering the empty record in the UI.
-