# Path: djinja/template/base.py
# class Library(object):
#     def __init__(self):
#         self.filters = {}
#         self.extensions = []
#         self.globals = {}
#         self.tests = {}
#     def tag(self, func,name=None):
#         if name==None:
#             name = getattr(func, "_decorated_function", func).__name__
#         self.globals[name] = func
# 
#     def filter(self, func,name=None):
#         if name==None:
#             name = getattr(func, "_decorated_function", func).__name__
#         self.filters[name] = func
# 
#     def extension(self, ext):
#         self.extensions.append(ext)
#     
#     def set(self,*args,**kwargs):
#         for k in kwargs.keys(): #is a object with a name
#             self[k] = kwargs[k]
#         for a in args:
#             self.tag(a) #is a function
#         
#     def inclusion_tag(self,template,func,takes_context=False):
#         if takes_context:
#             import jinja2
#             @jinja2.contextfunction
#             def tag(context,*args,**kwargs):
#                 from django.template.loader import render_to_string
#                 return render_to_string(template, func(dict_from_context(context),*args,**kwargs))
#             
#         else:
#             def tag(*args,**kwargs):
#                 from django.template.loader import render_to_string
#                 return render_to_string(template, func(*args,**kwargs))
#         
#         #raise Exception(getattr(func, "_decorated_function", func))
#         self.tag(tag,name=getattr(func, "_decorated_function", func).__name__) 
#     
#     def __setitem__(self, item, value):
#         self.globals[item] = value
#     
#     def __getitem__(self, item, value): #for reciprocity with __setitem__
#         return globals[item]


from djinja.template.base import Library
from django.utils.importlib import import_module
from django.conf import settings
    from django.core.urlresolvers import reverse, NoReverseMatch
        from django.template import get_library
import jinja2
register = Library()

# def execute (lib,function,*args,**kwargs):
#     l = import_module(lib)
#     #raise Exception(args)
#     f = getattr(l,function)
#     return f(*args,**kwargs)
# register.tag(execute)
# 
# @jinja2.contextfunction
# def execute_context (context,lib,function,*args,**kwargs):
#     l = import_module(lib)
#     #raise Exception(args)
#     context_dict = {}
#     for d in context.keys():
#         context_dict[d] = context.get(d)
#     f = getattr(l,function)
#     return f(context_dict,*args,**kwargs)
# 
# register.tag(execute_context)


def url(view_name, *args, **kwargs):
    try:
        return reverse(view_name, args=args, kwargs=kwargs)
    except NoReverseMatch:
        try:
            project_name = settings.SETTINGS_MODULE.split('.')[0]
            return reverse(project_name + '.' + view_name,
                           args=args, kwargs=kwargs)

# Path: djinja/template/base.py
# class Library(object):
#     def __init__(self):
#         self.filters = {}
#         self.extensions = []
#         self.globals = {}
#         self.tests = {}
#     def tag(self, func,name=None):
#         if name==None:
#             name = getattr(func, "_decorated_function", func).__name__
#         self.globals[name] = func
# 
#     def filter(self, func,name=None):
#         if name==None:
#             name = getattr(func, "_decorated_function", func).__name__
#         self.filters[name] = func
# 
#     def extension(self, ext):
#         self.extensions.append(ext)
#     
#     def set(self,*args,**kwargs):
#         for k in kwargs.keys(): #is a object with a name
#             self[k] = kwargs[k]
#         for a in args:
#             self.tag(a) #is a function
#         
#     def inclusion_tag(self,template,func,takes_context=False):
#         if takes_context:
#             import jinja2
#             @jinja2.contextfunction
#             def tag(context,*args,**kwargs):
#                 from django.template.loader import render_to_string
#                 return render_to_string(template, func(dict_from_context(context),*args,**kwargs))
#             
#         else:
#             def tag(*args,**kwargs):
#                 from django.template.loader import render_to_string
#                 return render_to_string(template, func(*args,**kwargs))
#         
#         #raise Exception(getattr(func, "_decorated_function", func))
#         self.tag(tag,name=getattr(func, "_decorated_function", func).__name__) 
#     
#     def __setitem__(self, item, value):
#         self.globals[item] = value
#     
#     def __getitem__(self, item, value): #for reciprocity with __setitem__
#         return globals[item]


# Path: djinja/template/defaultfunctions.py
from djinja.template.base import Library
from django.utils.importlib import import_module
from django.conf import settings
    from django.core.urlresolvers import reverse, NoReverseMatch
        from django.template import get_library
import jinja2

register = Library()

# def execute (lib,function,*args,**kwargs):
#     l = import_module(lib)
#     #raise Exception(args)
#     f = getattr(l,function)
#     return f(*args,**kwargs)
# register.tag(execute)
# 
# @jinja2.contextfunction
# def execute_context (context,lib,function,*args,**kwargs):
#     l = import_module(lib)
#     #raise Exception(args)
#     context_dict = {}
#     for d in context.keys():
#         context_dict[d] = context.get(d)
#     f = getattr(l,function)
#     return f(context_dict,*args,**kwargs)
# 
# register.tag(execute_context)


def url(view_name, *args, **kwargs):
    try:
        return reverse(view_name, args=args, kwargs=kwargs)
    except NoReverseMatch:
        try:
            project_name = settings.SETTINGS_MODULE.split('.')[0]
            return reverse(project_name + '.' + view_name,
                           args=args, kwargs=kwargs)

        except NoReverseMatch: