# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_action(image, label, *args): 
#     # TODO change to draw_action(image, label, format_url, *url_format_args)
#     url = reduce(lambda a, b: str(a) + str(b), args)
#     # TODO put this in teamplate instead
#     return """
#         <a href="%(url)s" class="action">
#             <img src="%(image)s" alt="%(label)s"> %(label)s
#         </a>
#     """ % { "label" : ACTION_LABELS[label], "image" : image, "url" : url }
# 
# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_comment(*args):
#     return draw_action("/static/famfamfam/comment_add.png", "COMMENT", *args)
# 
# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_edit(*args):
#     return draw_action("/static/famfamfam/pencil.png", "EDIT", *args)
# 
# Path: apps/team/control.py
# def get_team_emails(team, excludes=None):
# def get_teams(account):
# def get_or_404(link):
# def is_member(account, team):
# def create(account, name, country, logo, application):
# def notify_staff_team_created(sender, **kwargs):
# def notify_team_join_request_created(sender, **kwargs):
# def notify_team_join_request_processed(sender, **kwargs):
# def notify_concerned_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_processed(sender, **kwargs):
# def can_replace_logo(account, team):
# def replace_logo(account, team, logo):
# def can_join(account, team):
# def create_join_request(account, team, application):
# def can_process_join_request(account, join_request):
# def process_join_request(account, join_request, response, status):
# def has_remove_request(concerned, team):
# def can_create_remove_request(requester, concerned, team):
# def can_process_remove_request(account, remove_request):
# def create_remove_request(requester, concerned, team, reason):
# def process_remove_request(account, remove_request, response, status):
# def site_link_exists(team, site):
# def can_create_link(account, team, site, profile):
# def can_delete_link(account, team, link):
# def link_create(account, team, site, profile):
# def link_delete(account, team, link):


from django import template
from django.utils.translation import ugettext as _
from apps.common.templatetags.common_tags import draw_action
from apps.common.templatetags.common_tags import draw_comment
from apps.common.templatetags.common_tags import draw_edit
from apps.borrow import control
from apps.team import control as team_control
# -*- coding: utf-8 -*-
# Copyright (c) 2012 Fabian Barkhau <fabian.barkhau@gmail.com>                  
# License: MIT (see LICENSE.TXT file) 





register = template.Library()


@register.simple_tag
def borrow_draw_comment(account, borrow, team):
    if control.can_comment(account, borrow):
        url_prefix = team and "/%s" % team.link or ""
        url = "%s/borrow/comment/%s" % (url_prefix, borrow.id)
        return draw_comment(url)
    return ""


@register.simple_tag
def borrow_draw_edit(account, borrow):
    if control.lender_can_edit(account, borrow):
        return draw_edit("/%s/borrow/edit/%i" % (borrow.team.link, borrow.id))
    elif control.borrower_can_edit(account, borrow):

# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_action(image, label, *args): 
#     # TODO change to draw_action(image, label, format_url, *url_format_args)
#     url = reduce(lambda a, b: str(a) + str(b), args)
#     # TODO put this in teamplate instead
#     return """
#         <a href="%(url)s" class="action">
#             <img src="%(image)s" alt="%(label)s"> %(label)s
#         </a>
#     """ % { "label" : ACTION_LABELS[label], "image" : image, "url" : url }
# 
# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_comment(*args):
#     return draw_action("/static/famfamfam/comment_add.png", "COMMENT", *args)
# 
# Path: apps/common/templatetags/common_tags.py
# @register.simple_tag
# def draw_edit(*args):
#     return draw_action("/static/famfamfam/pencil.png", "EDIT", *args)
# 
# Path: apps/team/control.py
# def get_team_emails(team, excludes=None):
# def get_teams(account):
# def get_or_404(link):
# def is_member(account, team):
# def create(account, name, country, logo, application):
# def notify_staff_team_created(sender, **kwargs):
# def notify_team_join_request_created(sender, **kwargs):
# def notify_team_join_request_processed(sender, **kwargs):
# def notify_concerned_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_created(sender, **kwargs):
# def notify_team_remove_request_processed(sender, **kwargs):
# def can_replace_logo(account, team):
# def replace_logo(account, team, logo):
# def can_join(account, team):
# def create_join_request(account, team, application):
# def can_process_join_request(account, join_request):
# def process_join_request(account, join_request, response, status):
# def has_remove_request(concerned, team):
# def can_create_remove_request(requester, concerned, team):
# def can_process_remove_request(account, remove_request):
# def create_remove_request(requester, concerned, team, reason):
# def process_remove_request(account, remove_request, response, status):
# def site_link_exists(team, site):
# def can_create_link(account, team, site, profile):
# def can_delete_link(account, team, link):
# def link_create(account, team, site, profile):
# def link_delete(account, team, link):


# Path: apps/borrow/templatetags/borrow_tags.py
from django import template
from django.utils.translation import ugettext as _
from apps.common.templatetags.common_tags import draw_action
from apps.common.templatetags.common_tags import draw_comment
from apps.common.templatetags.common_tags import draw_edit
from apps.borrow import control
from apps.team import control as team_control

# -*- coding: utf-8 -*-
# Copyright (c) 2012 Fabian Barkhau <fabian.barkhau@gmail.com>                  
# License: MIT (see LICENSE.TXT file) 





register = template.Library()


@register.simple_tag
def borrow_draw_comment(account, borrow, team):
    if control.can_comment(account, borrow):
        url_prefix = team and "/%s" % team.link or ""
        url = "%s/borrow/comment/%s" % (url_prefix, borrow.id)
        return draw_comment(url)
    return ""


@register.simple_tag
def borrow_draw_edit(account, borrow):
    if control.lender_can_edit(account, borrow):
        return draw_edit("/%s/borrow/edit/%i" % (borrow.team.link, borrow.id))
    elif control.borrower_can_edit(account, borrow):

        return draw_edit("/borrow/edit/%i" % borrow.id)