Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created April 25, 2018 19:38
Show Gist options
  • Select an option

  • Save rg3915/465bd01facddf556494d39c99d1b3691 to your computer and use it in GitHub Desktop.

Select an option

Save rg3915/465bd01facddf556494d39c99d1b3691 to your computer and use it in GitHub Desktop.
Custom TemplateTags

Custom TemplateTags

https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/#assignment-tags

# combo_tags.py
@register.assignment_tag
def cvlist_status(cvlist):
    ''' Retorna True se o cvlist foi processado com erro. '''
    res = cvlist.cv_lists.filter(status=False, resume_text='').first()
    if res:
        return True
    return False
# template.html
<!-- Se resume.status == False e resume_text for vazio,
retornar um icone amarelo -->
<!-- Retorna True se o cvlist foi processado com erro. -->
{% cvlist_status cvlist as status_flag %}
{% if status_flag %}
  <span class="glyphicon glyphicon-info-sign text-new-yellow"></span>
{% else %}
  <span>Falso</span>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment