stalker.models.template.FilenameTemplate

Inheritance diagram of stalker.models.template.FilenameTemplate
class stalker.models.template.FilenameTemplate(target_entity_type=None, path=None, filename=None, **kwargs)[source]

Bases: stalker.models.entity.Entity, stalker.models.mixins.TargetEntityTypeMixin

Holds templates for filename and path conventions.

FilenameTemplate objects help to specify where to place a Version related file.

Although, it is mainly used by Stalker to define Version related file paths and file names to place them in to proper places inside a Project’s Project.structure, the idea behind is open to endless possibilities.

Here is an example:

p1 = Project(name="Test Project") # shortened for this example

# shortened for this example
s1 = Structure(name="Commercial Project Structure")

# this is going to be used by Stalker to decide the :stalker:`.Link`
# :stalker:`.Link.filename` and :stalker:`.Link.path` (which is the way
# Stalker links external files to Version instances)
f1 = FilenameTemplate(
    name="Asset Version Template",
    target_entity_type="Asset",
    path='$REPO{{project.repository.id}}/{{project.code}}/{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}/{%- endfor -%}",
    filename="{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}"
)

s1.templates.append(f1)
p1.structure = s1

# now because we have defined a FilenameTemplate for Assets,
# Stalker is now able to produce a path and a filename for any Version
# related to an asset in this project.
Parameters:
  • target_entity_type (str) –

    The class name that this FilenameTemplate is designed for. You can also pass the class itself. So both of the examples below can work:

    new_filename_template1 = FilenameTemplate(target_entity_type=”Asset”)
    new_filename_template2 = FilenameTemplate(target_entity_type=Asset)
    

    A TypeError will be raised when it is skipped or it is None and a ValueError will be raised when it is given as and empty string.

  • path (str) –

    A Jinja2 template code which specifies the path of the given item. It is relative to the repository root. A typical example could be:

    ’$REPO{{project.repository.id}}/{{project.code}}/{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}/{%- endfor -%}”
    
  • filename (str) –

    A Jinja2 template code which specifies the file name of the given item. It is relative to the FilenameTemplate.path. A typical example could be:

    ’{{version.nice_name}}_v{{“%03d”|format(version.version_number)}}’
    

    Could be set to an empty string or None, the default value is None.

    It can be None, or an empty string, or it can be skipped.

__init__(target_entity_type=None, path=None, filename=None, **kwargs)

Methods

__init__([target_entity_type, path, filename])

Attributes

created_by The User who has created this object.
created_by_id The id of the User who has created this entity.
date_created A datetime.datetime instance showing the creation date and time of this object.
date_updated A datetime.datetime instance showing the update date and time of this object.
description Description of this object.
entity_groups
entity_id
entity_type
filename The template code for the file part of the FilenameTemplate.
filenameTemplate_id
generic_data This attribute can hold any kind of data which exists in SOM.
generic_text This attribute can hold any text.
html_class
html_style
id
metadata
name Name of this object
nice_name Nice name of this object.
notes All the Notess attached to this entity.
path The template code for the path of this FilenameTemplate.
plural_class_name the plural name of this class
query
tags A list of tags attached to this object.
target_entity_type The entity type which this object is valid for.
thumbnail
thumbnail_id
tjp_id returns TaskJuggler compatible id
to_tjp renders a TaskJuggler compliant string used for TaskJuggler
type The type of the object.
type_id The id of the Type of this entity.
updated_by The User who has updated this object.
updated_by_id The id of the User who has updated this entity.
path

The template code for the path of this FilenameTemplate.

filename

The template code for the file part of the FilenameTemplate.

created_by

The User who has created this object.

created_by_id

The id of the User who has created this entity.

date_created

A datetime.datetime instance showing the creation date and time of this object.

date_updated

A datetime.datetime instance showing the update date and time of this object.

description

Description of this object.

generic_data

This attribute can hold any kind of data which exists in SOM.

generic_text

This attribute can hold any text.

name

Name of this object

nice_name

Nice name of this object.

It has the same value with the name (contextually) but with a different format like, all the white spaces replaced by underscores (“_”), all the CamelCase form will be expanded by underscore (_) characters and it is always lower case.

notes

All the Notess attached to this entity.

It is a list of Note instances or an empty list, setting it to None will raise a TypeError.

plural_class_name

the plural name of this class

tags

A list of tags attached to this object.

It is a list of Tag instances which shows the tags of this object

target_entity_type

The entity type which this object is valid for.

Usually it is set to the TargetClass directly.

tjp_id

returns TaskJuggler compatible id

to_tjp

renders a TaskJuggler compliant string used for TaskJuggler integration. Needs to be overridden in inherited classes.

type

The type of the object.

It is a Type instance with a proper Type.target_entity_type.

type_id

The id of the Type of this entity. Mainly used by SQLAlchemy to create a Many-to-One relates between SimpleEntities and Types.

updated_by

The User who has updated this object.

updated_by_id

The id of the User who has updated this entity.