catalog.trait package

Submodules

catalog.trait.trait module

A Trait module for generating HTML forms and views.

Default Traits can be specified for plain views of properties that don’t have a value assigned to them, yet.

The asOutputElement method is used for displaying trait values. The asInputElement method is used for creating html forms from the trait’s attributes.

class catalog.trait.trait.DateTrait(name, value='2015-12-04')[source]

Bases: catalog.trait.trait.Trait

A Trait for a property that is best represented as a date that includes the year, month and day.

Parameters:
  • inputTemplate (string) – Template for Generating an html ‘date’ input.
  • name (string) – The label or property name.
  • value (string) – The date value associated with the property.
asInputElement(formName, withValue=False)[source]

Render as an HTML date input element.

Provides a calender like functionality or manually inputting the year, month and day.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – A Date Trait always presents a date value, either a default that is today’s date, or one passed in.
Returns:

Formatted HTML table row containing two table data elements. One for the property name as a label and another that contains the Date input set to today’s date or the date passed during the creation of the object.

Return type:

string

asOutputElement()[source]

Refer to asOutputElement()

inputTemplate = '<input type="date" name="{0}" form="{1}" value="{2}">'
isImage()[source]

Does this Trait refer to an Image element?

Returns:A Date input element is not an image, so False.
Return type:Boolean
class catalog.trait.trait.ImageTrait(name, url='')[source]

Bases: catalog.trait.trait.Trait

A Trait that represents an HTML image element.

Parameters:
  • inputType (string) – This will be a ‘text’ input element.
  • inputTemplate (string) – Generate’s an html input of type ‘text’
  • name (string) – The property name for the element. Used to retrieve data from the form in a request.
  • url (string) – The url associated with the image.
asInputElement(formName, withValue=False)[source]

Render the Trait as a text input in as part of an HTML form. Manually enter the URL for an image, as opposed to uploading it.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – A form for a new object will not have any values. But a form that is for editing an existing object will.
Returns:

The formatted output of the combination of the inputTemplate and traitTemplate.

Return type:

string

asOutputElement()[source]

Refer to asOutputElement()

inputTemplate = '<input type="{0}" name="{1}" form="{2}" value="{3}">'
isImage()[source]

Does this Trait refer to an Image element?

Returns:This will be an image element, so True.
Return type:Boolean
outputTemplate = '<img src="{0}" class="img-responsive">'
class catalog.trait.trait.ImageUploadTrait(name)[source]

Bases: catalog.trait.trait.Trait

A Trait that represents an HTML element for uploading a image file.

Note

This could be generalized into just an UploadTrait and apply to files of any type. This Trait is only used for Input. An ImageTrait should be used for outputting an image.

Parameters:
  • inputType (string) – This will be a ‘text’ input element.
  • inputTemplate (string) – Generate’s an html input of type ‘text’
  • name (string) – The property name for the element. Used to retrieve data from the form in a request.
asInputElement(formName, withValue=False)[source]

Render as a file upload element in an HTML form.

Prompts the user to choose a file on their system to upload.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – A form for a new object will not have any values. But a form that is for editing an existing object will.
Returns:

Formatted HTML table row containing two table data elements containing the property name in a button and an empty text element that will hold the file’s name after the user uploads an image file.

Return type:

string

asOutputElement()[source]

An Image Upload element would not be presented as an Image.

Returns:An HTML comment describing the Output Usage for ImageUploadTrait
Return type:string
inputTemplate = '<input type="{0}" name="{1}" form="{2}">'
isImage()[source]

Does this Trait refer to an Image element?

Returns:This is not displayed as an image but as a file upload input, so False.
Return type:Boolean
class catalog.trait.trait.SelectTrait(name, value, options)[source]

Bases: catalog.trait.trait.Trait

A Trait for a property that is best represented by a Select Element with a Dropdown list of different options to choose from.

Parameters:
  • selectTemplate (string) – Generate’s an html ‘select’ input.
  • optionTemplate (string) – A template string that represents one option element contained in a select element.
  • name (string) – The label or property name.
  • value (string) – The string value of the currently selected option.
  • options (list) – A list of strings describing the value for each option displayed in the drop down list of the select element.
asInputElement(formName, withValue=False)[source]

Render as a Select element containing option elements in an HTML form.

Provides an dropdown list of options to choose from return the selected value as part of a form in a Request.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – A form for a new object will not have any values. But a form that is for editing an existing object will.
Returns:

Formatted HTML table row containing two table data elements. One for the property name as a label and another that contains the the Select with a dropdown list of options to choose from.

Return type:

string

asOutputElement()[source]

Refer to asOutputElement()

isImage()[source]

Does this Trait refer to an Image element?

Returns:A Select element is not an image, so False.
Return type:Boolean
optionTemplate = '\n <option value="{0}"{1}>{2}</option>'
selectTemplate = '<select name="{0}" form="{1}">{2}\n </select>'
class catalog.trait.trait.TextAreaTrait(name, value='')[source]

Bases: catalog.trait.trait.Trait

A Trait for a multi-line text property that is rendered as a TextArea HTML element.

Parameters:
  • inputTemplate (string) – Generate’s an html ‘textarea’ input.
  • name (string) – The label or property name.
  • value (string) – The value contained in the textarea.
asInputElement(formName, withValue=False)[source]

Render as a textarea element in an HTML form.

Provides an area for a longer text description of a property.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – True builds a form for creating a new object that will not have any values. False, a form that is for editing an existing object will.
Return string:

HTML that defines a table row containing two table data elements. One for the property name as a label and another that contains the Trait’s value (or nothing) in a textarea HTML element.

asOutputElement()[source]

Refer to asOutputElement()

inputTemplate = '<textarea name="{0}" form="{1}">{2}</textarea>'
isImage()[source]

Does this Trait refer to an Image element?

Returns:A TextArea is not an image, so False.
Return type:Boolean
class catalog.trait.trait.TextTrait(name, value='')[source]

Bases: catalog.trait.trait.Trait

A Trait for a property that can be represented as a Text input or unalterable string value in an html element.

Parameters:
  • inputType (string) – This will be a ‘text’ input element.
  • inputTemplate (string) – Generate’s an html input of type ‘text’
  • name (string) – The property name or label
  • value (string) – The value associated with the property.
asInputElement(formName, withValue=False)[source]

Render the Trait as a text input in as part of an HTML form.

Parameters:
  • formName (string) – The HTML form’s name attribute.
  • withValue (Boolean) – A form for a new object will not have any values. But a form that is for editing an existing object will.
Returns:

The formatted output of the combination of the inputTemplate and traitTemplate.

Return type:

string

asOutputElement()[source]

Refer to asOutputElement()

inputTemplate = '<input type="{0}" name="{1}" form="{2}" value="{3}">'
isImage()[source]

Does this Trait refer to an Image element?

Returns:A text input is not an image, so False.
Return type:Boolean
class catalog.trait.trait.Trait[source]

Bases: object

Abstract Base Class that defines the Interface and a few attributes of all Derived Traits.

Note

When asInputElement is called for a Trait, and the generated HTML Form is processed as part of a Request, then the Trait’s name is used as a key to retrieve it’s value from the Request’s form.

Parameters:
  • inputType (string) – The html input type of the trait.
  • inputTemplate (string) – Input Template used when the trait can receive input.
  • outputTemplate (string) – The output template when the trait is only viewed.
  • traitTemplate (str) – The base template applied to the input or output templates. It represents an HTML table row with two table data elements. One for the Trait’s property name and the other for it’s value.
asInputElement(formName, withValue=False)[source]

Render the Trait as an HTML element as part of a form that receives input.

Parameters:
  • formName (string) – The HTML form’s name attribute. Each trait’s html element is added to a table outside it’s form. This argument binds the Trait’s element to the form.
  • withValue (Boolean) – A form for a new object will not have any values. But a form that is for editing an existing object will.
Returns:

The formatted output of the combination of the inputTemplate and traitTemplate.

Return type:

string

asOutputElement()[source]

Render the Trait as an HTML element as a view that does not receive any input.

Returns:The formatted output of the combination of the outputTemplate and traitTemplate.
Return type:string
inputTemplate = ''
inputType = ''
isImage()[source]

Does this Trait refer to an Image element?

Returns:True if the Trait applies to an Image, otherwise False.
Return type:Boolean
outputTemplate = ''
traitTemplate = '\n <tr class="trait">\n <td>{0}</td>\n <td>\n {1}\n </td>\n </tr>'

Module contents