Skip to content
Allan Lasser edited this page Oct 13, 2015 · 4 revisions

Completing Tasks

Orphan

Snail Mail

Rejected Email

Stale Agency

Flagged

New Agency

Response

Payment

Crowdfund

Multi-Request

Status Change

Implementing Tasks

Rendering tasks

Tasks are rendered as custom Django template tags. This allows for a greater degree of sophistication and control over their appearance and functionality. It has the added benefit of making them simple, modular, and decoupled from any Django view logic.

In most cases, the easiest place to start when rendering a new task is writing the HTML. Templates for individual tasks are found in muckrock/templates/task. They inherit from a base template, default.html. These templates are used by their respective template tags. Each template tag should use its own template.

Next, create the task's template tag in the muckrock/task/templatetags/task_tags.py file. Each tag has two pieces, a tag and a node (for more information on these pieces, consult the Django documentation). Task tags are registered at the bottom of task_tags.py and simply return a task-specific node. There is a base TaskNode class that should be extended. At minimum, the TaskNode needs the model and template (if these are not provided, basic fallbacks will be used). If the template expects additional context data, that can be provided by extending the get_extra_context method.

Finally, once the tag is registered it should be added to the switch statement in muckrock/templates/lib/task.html. This simple standalone file is used out of convenience, so that any kind of task can be rendered with a simple call of {% include 'lib/task.html' %}.