Skip to content

Package Development

mperice edited this page Nov 13, 2015 · 1 revision

TextFlows packages

TextFlows packages are used to transfer widget descriptions from one installation of TextFlows to another. It is not necessary for a widget to belong to a specific package. It is recommended that you create widgets within packages if you wish to transfer these widgets to the public installation of TextFlows or if you want someone else to use your work without the headache of registering each widget in the administration panel in a particular TextFlows installation.

Creating a package from the package template

To start a new package from a template use the built-in management command like this:

python manage.py new_package_from_template $new_package_name$

Replace $new_package_name$ with a package name. IMPORTANT: Please avoid naming packages after built-in Python or Django components. In particular, this means you should avoid using names like django (which will conflict with Django itself), orange, or test (which conflicts with a built-in Python package).

This command creates a new package based on package_template. It generates new uids for template database objects, renames functions, renames files and registers the package in INSTALLED_APPS. (This command actually adds a line in your settings.py file).

Importing the package data

The template package has a few default widgets. If you wish to see them you will have to import the package first (this will import all objects into your database). Use the import_package command. Please note that the import package command takes a json filename as an input and not the package name.

python manage.py import_package workflows/$new_package_name$/db/package_data.json
python manage.py import_all

New package overview

When you create a package called new_package a new folder will appear in the mothra/workflows folder with the same name as your package.

The following files and folder will be created:

new_package/templates
new_package/templates/interactions
new_package/templates/interactions/new_package_filter_integers.html
new_package/templates/visualizations
new_package/templates/visualizations/new_package_display_integers.html
new_package/library.py
new_package/urls.py
new_package/__init__.pyc
new_package/visualization_views.py
new_package/interaction_views.py
new_package/db
new_package/db/package_data.json
new_package/views.py
new_package/__init__.py
new_package/settings.py
new_package/library.pyc
new_package/static
new_package/static/new_package
new_package/static/new_package/icons
new_package/static/new_package/icons/widget
new_package/static/new_package/icons/widget/construction_work .png
new_package/static/new_package/icons/treeview
new_package/static/new_package/icons/treeview/construction_work .png

Important things you should know:

  • new_package/settings.py should be edited if you wish to add your package to the list of packages that should automatically be imported when the auto_import_packages command is executed (on the live version of TextFlows, this is done on each update). If this option is set to true, please make sure that the AUTO_IMPORT_DB_FILES is a list of json package files.
  • new_package/db/package_data.json contains all the category, abstract widgets, abstract inputs, and outputs for your package. This file can be automatically generated by using the export_package command.
  • static new_package subfolder - there is a subfolder in the static folder with the same name as the package. This is used for widget icons. If you add any other folders here it may clash with other static files, so you are advised to only put icons, css and other files inside the new_package/static/new_package folder.
  • mothra/local_settings.py and mothra/__local_settings.py contain a tuple INSTALLED_APPS_WORKFLOWS_SUB into which you should add an item 'workflows.new_package' so that the code looks somewhat like this:
INSTALLED_APPS_WORKFLOWS_SUB = (
    'workflows.base',
    'workflows.new_package',
    ...

Exporting your custom widgets to the package data file

When you have added or modified an abstract widget you can export it to a package data file.

python manage.py export_package -u workflows/$your_package_name$/db/package_data.json $your_package_name$
python manage.py export_all

The -u switch will assign new UIDs to objects that do not have them set. New widgets normally do not have UIDs set yet.

Clone this wiki locally