from django import template

from applications.models import Score


register = template.Library()

@register.filter
def scored_by_user(value, arg):
    try:
        score = Score.objects.get(application=value, user=arg)
        return True if score.score else False
    except Score.DoesNotExist:
        return False


@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '<a href="?order={}">▼</a>'.format(name)
    else:
        return '<a href="?order=-{}">▲</a>'.format(name)

from django import template


register = template.Library()


@register.filter
def scored_by_user(application, user):
    return application.is_scored_by_user(user)


@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '<a href="?order={}">▼</a>'.format(name)
    else:
        return '<a href="?order=-{}">▲</a>'.format(name)

Make scored_by_user filter call model method
Make scored_by_user filter call model method

Ref #113

  from django import template
- 
- from applications.models import Score
  
  
  register = template.Library()
  
+ 
  @register.filter
- def scored_by_user(value, arg):
+ def scored_by_user(application, user):
+     return application.is_scored_by_user(user)
-     try:
-         score = Score.objects.get(application=value, user=arg)
-         return True if score.score else False
-     except Score.DoesNotExist:
-         return False
  
  
  @register.simple_tag
  def display_sorting_arrow(name, current_order):
      is_reversed = False
      if '-{}'.format(name) == current_order:
          is_reversed = True
  
      if is_reversed:
          return '<a href="?order={}">▼</a>'.format(name)
      else:
          return '<a href="?order=-{}">▲</a>'.format(name)
  
Make scored_by_user filter call model method
## Code Before:
from django import template

from applications.models import Score


register = template.Library()

@register.filter
def scored_by_user(value, arg):
    try:
        score = Score.objects.get(application=value, user=arg)
        return True if score.score else False
    except Score.DoesNotExist:
        return False


@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '<a href="?order={}">▼</a>'.format(name)
    else:
        return '<a href="?order=-{}">▲</a>'.format(name)

## Instruction:
Make scored_by_user filter call model method
## Code After:
from django import template


register = template.Library()


@register.filter
def scored_by_user(application, user):
    return application.is_scored_by_user(user)


@register.simple_tag
def display_sorting_arrow(name, current_order):
    is_reversed = False
    if '-{}'.format(name) == current_order:
        is_reversed = True

    if is_reversed:
        return '<a href="?order={}">▼</a>'.format(name)
    else:
        return '<a href="?order=-{}">▲</a>'.format(name)
