txcommon — Transifex v0.8.0 documentation

# Transifex v0.8.0 documentation

# `txcommon`

## Decorators

`one_perm_required`(perms, *model_lookups, **kwargs)

  Decorator for views that checks whether an user has a particular permission enabled for an object or a general permission from the django permission system, redirecting to the log-in page if necessary.

  Example:

      # Permissions required for setting stats
      pr_set_stats = (
          ('granular', 'project_permission.maintain'),
          ('general',  'projects.refresh_stats'),
         #(<perm_type>, <perm_name>),
      )

      @one_perm_required_or_403(pr_set_stats,
          (Project, 'slug__contains', 'project_slug'))
      def component_set_stats(request, project_slug, component_slug):
          bla bla bla

  In the example above the decorator checks for the maintain permission for a Project object, taking the project_slug from the view component_set_stats. If the user IS NOT a maintainer of that project, the second and general permission is checked.

  If at least one of the permissions checks in the list returns True, the access for the user is guarantee.

  The permissions are checked in the same order as they are put in the tuple and it is allowed to add how many permissions checks as wanted.

`one_perm_required_or_403`(perms, *args, **kwargs)
  Decorator that wraps the one_perm_required_or_403 decorator and returns a permission denied (403) page instead of redirecting to the login URL.

`perm_required_with_403`(perm)
  Decorator for views that checks whether a user has a particular permissions enabled, rendering a 403 page as necessary.

`user_passes_test_with_403`(test_func, login_url=None)

  Decorator for views that checks that the user passes the given test.

  Users that fail the test will be given a 403 error.

## Template Tags

### Common Tags

class `CounterNode`(initial)
  A template node to count how many times it was called.

class `ResolverNode`

  A small wrapper that adds a convenient resolve method.

  `resolve`(var, context)
    Resolves a variable out of context if it’s not in quotes

`as_rest_title`(value, border=None)

  Return a value as a restructured text header.

  border - Character to be used in the header bottom-border

`counter`(parser, token)

  Return a number increasing its counting each time it’s called. An `initial` value can be passed to identify from which number it should start counting.

  Syntax:

      {% counter %}
      {% counter 20 %}

`form_as_table_rows`(form, id=None)
  Create a form using HTML table rows.

`get_next`(request)
  Return the next path from the request.

`get_top_translators`(parser, token)

  Return a dictionary with the top translators of the system or for a object, when it’s passed by parameter.

  Usage:: get_top_translators <number_of_top_translators> get_top_translators 10

  or

  get_top_translators <number_of_top_translators> <obj> get_top_translators 10 project_foo

`homelink`(text=u'Home')
  Return a link to the homepage.

`in_list`(value, arg)
  Check if a value is present in a list.

`notice_type_user_filter`(noticetype_list)

  Filter a NoticeType list passed by parameter using the NOTICE_TYPES dictionary that says which notice types must be shown to the user.

  It is necessary by now until the upstream project have a model change to be able to do this filtering from the database.

`render_metacount`(list, countable)

  Return meta-style link rendered as superscript to count something.

  For example, with list=[‘a’, ‘b’] and countable=’boxes’ return the HTML for “2 boxes”.

`strip_tags`(value)
  Return the value with HTML tags striped.

`txversion`()
  Return the version of Transifex

### Search Filters

`highlight_tag`(parser, token)
  {% highlight search_terms [ignore_case] [word_boundary] [class_name] [as name] %} ...text... {% endhighlight %}

`hits_tag`(parser, token)
  {% hits search_terms [ignore_case] [word_boundary] [as name] %} ...text... {% endhits %}

`searchexcerpt_tag`(parser, token)
  {% searchexcerpt search_terms [context_words] [ignore_case] [word_boundary] [as name] %} ...text... {% endsearchexcerpt %}

## Views

`user_nudge`
  View for nudging an user

`user_timeline`

  Present a log of the latest actions of a user.

  The view limits the results and uses filters to allow the user to even further refine the set.