from django import template

register = template.Library()

@register.filter(name='governing')
def governing(party, date):
    return party.is_governing(date)


from django import template
from ..models import Party, Statement

register = template.Library()

@register.filter(name='governing')
def governing(obj, date=None):
    if isinstance(obj, Party):
        assert date is not None, "Date must be supplied when 'govern' is called with a Party object"
        return obj.is_governing(date)
    elif isinstance(obj, Statement):
        if obj.member is None:
            if 'ministeri' in obj.speaker_role:
                return True
            else:
                return False
        if date is None:
            date = obj.item.plsess.date
        return obj.member.party.is_governing(date)

Allow governing templatetag to be called with a Statement object
Allow governing templatetag to be called with a Statement object

  from django import template
+ from ..models import Party, Statement
  
  register = template.Library()
  
  @register.filter(name='governing')
- def governing(party, date):
+ def governing(obj, date=None):
+     if isinstance(obj, Party):
+         assert date is not None, "Date must be supplied when 'govern' is called with a Party object"
-     return party.is_governing(date)
+         return obj.is_governing(date)
+     elif isinstance(obj, Statement):
+         if obj.member is None:
+             if 'ministeri' in obj.speaker_role:
+                 return True
+             else:
+                 return False
+         if date is None:
+             date = obj.item.plsess.date
+         return obj.member.party.is_governing(date)
  
- 
Allow governing templatetag to be called with a Statement object
## Code Before:
from django import template

register = template.Library()

@register.filter(name='governing')
def governing(party, date):
    return party.is_governing(date)


## Instruction:
Allow governing templatetag to be called with a Statement object
## Code After:
from django import template
from ..models import Party, Statement

register = template.Library()

@register.filter(name='governing')
def governing(obj, date=None):
    if isinstance(obj, Party):
        assert date is not None, "Date must be supplied when 'govern' is called with a Party object"
        return obj.is_governing(date)
    elif isinstance(obj, Statement):
        if obj.member is None:
            if 'ministeri' in obj.speaker_role:
                return True
            else:
                return False
        if date is None:
            date = obj.item.plsess.date
        return obj.member.party.is_governing(date)
