stalker.core.models.FilenameTemplate — Stalker v0.1.1.a9 documentation

### Navigation

- index
- next |
- previous |
- Stalker v0.1.1.a9 documentation »

# stalker.core.models.FilenameTemplate

class `stalker.core.models.` `FilenameTemplate`(target_entity_type=None, path_code=None, file_code=None, output_path_code=None, output_file_code=None, output_is_relative=True, **kwargs)

  Bases: `stalker.core.models.Entity`

  Holds templates for filename conventions.

  FilenameTemplate objects help to specify where to place a file related to its `target_entity_type`.

  The first very important usage of FilenameTemplates is to place asset file `Version`‘s to proper places inside a `Project`‘s `Structure`.

  Secondly, it can be used in the process of injecting files in to the repository. By creating templates for `Links`.

  - 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 ValueErorr will be raised when it is given as and empty string. path_code (str) – A Jinja2 template code which specifies the path of the given item. It is relative to the project root. A typical example could be:
        asset_path_code = "ASSETS/{{asset.code}}/{{task.code}}/"
  - file_code (str) – A Jinja2 template code which specifies the file name of the given item. It is relative to the `path_code`. A typical example could be:
        asset_file_code = "{{asset.code}}_{{version.take}}_{{task.code}}_"\
                          "{{version.version}}_{{user.initials}}"
  Could be set to an empty string or None, the default value is None. output_path_code (str) – A Jinja2 template code specifying where to place the outputs of the applied `target_entity_type`. If it is empty and the `output_is_relative` is True, then the outputs will naturally be in the same place with the `path_code`. If the `output_is_relative` is False then `output_path_code` will be the same code with `path_code`. It can be None, or an empty string, or it can be skipped. output_file_code (str) – A Jinja2 template code specifying what will be the file name of the output. If it is skipped or given as None or as an empty string, it will be the same with the `file_code`. It can be skipped, or can be set to None or an empty string. The default value is None, and this will set the `output_file_code` to the same value with `file_code`. output_is_relative (bool) – A bool value specifying if the `output_path_code` is relative to the `path_code`. The default value is True. Can be skipped, any other than a bool value will be evaluated to a bool value.

  Examples:

  A template for asset versions can be used like this:

      from stalker.core.models import Type, FilenameTemplate, TaskTemplate

      # create a couple of variables
      path_code = "ASSETS/{{asset_type.name}}/{{task_type.code}}"

      file_code =
      "{{asset.name}}_{{take.name}}_{{asset_type.name}}_v{{version.version_number}}"

      output_path_code = "OUTPUT"
      output_file_code = file_code

      # create a type for modeling task
      modeling = Type(
          name="Modeling",
          code="MODEL",
          description="The modeling step of the asset",
          target_entity_type=Task
      )

      # create a "Character" Type for Asset classes
      character = Type(
          name="Character",
          description="this is the character asset type",
          target_entity_type=Asset
      )

      # now create our FilenameTemplate
      char_template = FilenameTemplate(
          name="Character",
          description="this is the template which explains how to place Character assets",
          target_entity_type="Asset",
          path_code=path_code,
          file_code=file_code,
          output_path_code=output_path_code,
          output_file_code=output_file_code,
          output_is_relative=True,
      )

      # assign this type template to the structure of the project with id=101
      myProject = query(Project).filter_by(id=101).first()

      # append the type template to the structures' templates
      myProject.structure.templates.append(char_template)

      # commit everything to the database
      session.commit()

  Now with the code above, whenever a new `Version` created for a Character asset, Stalker will automatically place the related file to a certain folder and with a certain file name defined by the template. For example the above template should render something like below for Windows:

      |- M:\\PROJECTS  --> {{repository.path}}
       |- PRENSESIN_UYKUSU  --> {{project.code}}
        |- ASSETS  --> "ASSETS"
         |- Character  --> {{asset_type.name}}
          |- Olum  --> {{asset.name}}
           |- MODEL  --> {{task_type.code}}
            |- Olum_MAIN_MODEL_v001.ma --> {{asset.name}}_{{take.name}}_{{asset_type.name}}_v{{version.version_number}}

  And one of the best side is you can create a version from Linux, Windows or OSX all the paths will be correctly handled by Stalker.

  `__init__`(target_entity_type=None, path_code=None, file_code=None, output_path_code=None, output_file_code=None, output_is_relative=True, **kwargs)

  Methods

  `__init__`(**kwargs[, target_entity_type, ...]) |

  Attributes

  `code` | The code name of this object.
  `created_by` | The `User` who has created this object.
  `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.
  `file_code` | this is the property that helps you assign values to
  `name` | Name of this object
  `nice_name` | Nice name of this object.
  `notes` | All the notes about this entity.
  `output_file_code` | The output_file_code of this FilenameTemplate object.
  `output_is_relative` |
  `output_path_code` | The output_path_code of this FilenameTemplate object.
  `path_code` | this is the property that helps you assign values to
  `tags` | A list of tags attached to this object.
  `target_entity_type` | the target entity type this FilenameTemplate object should
  `type` | The type of the object.
  `updated_by` | The `User` who has updated this object.

  `code`

    The code name of this object.

    It accepts string or unicode values and any other kind of objects will be converted to string. In any update to the name attribute the code also will be updated. If the code is not initialized or given as None, it will be set to the uppercase version of the nice_name attribute. Setting the code attribute to None will reset it to the default value. The default value is the upper case form of the nice_name.

  `created_by`

    The `User` who has created this object.

  `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.

  `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.

    There is also the `code` attribute which is simply the upper case form of `nice_name` if it is not defined differently (i.e set to another value).

  `notes`

    All the notes about this entity.

    It is a list of `Note` objects or an empty list, None will be converted to an empty list.

  `tags`

    A list of tags attached to this object.

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

  `type`

    The type of the object.

    It is an instance of `Type` with a proper `target_entity_type`.

  `updated_by`

    The `User` who has updated this object.

  `path_code`

    this is the property that helps you assign values to path_code attribute

  `file_code`

    this is the property that helps you assign values to file_code attribute

  `target_entity_type`

    the target entity type this FilenameTemplate object should work on, should be a string value or the class itself

  `output_path_code`

    The output_path_code of this FilenameTemplate object.

    Should be a unicode string. None and empty string is also accepted, but in this case the value is copied from the `path_code` if also the `output_is_relative` is False. If `output_is_relative` is True then it will left as an empty string.

  `output_file_code`

    The output_file_code of this FilenameTemplate object.

    Should be a unicode string. None and empty string is also accepted, but in this case the value is copied from the `file_code` if also the `output_is_relative` is False. If `output_is_relative` is True then it will left as an empty string.

  `output_is_relative`

### Navigation

- index
- next |
- previous |
- Stalker v0.1.1.a9 documentation »