# Path: pttrack/decorators.py
# def provider_required(func):
#     return user_passes_test(provider_exists, login_url=reverse_lazy('new-provider'))(func)
# 
# def clintype_required(func):
#     return session_passes_test(clintype_set, fail_url=reverse_lazy('choose-clintype'))(func)
# 
# def provider_update_required(func):
#     return user_passes_test(provider_has_updated, login_url=reverse_lazy('provider-update'))(func)


from django.conf.urls import url
from django.views.generic import DetailView
from django.views.generic.base import TemplateView
from django.contrib.auth.decorators import login_required
from .decorators import provider_required, clintype_required, \
    provider_update_required
from . import models
from . import views
    # MISC
    url(r'^about/',
        TemplateView.as_view(template_name='pttrack/about.html'),
        name='about'),
]


def wrap_url(url, no_wrap=[], login_only=[], provider_only=[],
             updated_provider_only=[]):
    '''
    Wrap URL in decorators as appropriate.
    '''
    if url.name in no_wrap:
        # do not wrap at all, fully public
        pass

    elif url.name in login_only:
        url.callback = login_required(url.callback)

    elif url.name in provider_only:
        url.callback = provider_required(url.callback)
        url.callback = login_required(url.callback)

    elif url.name in updated_provider_only:
        url.callback = provider_update_required(url.callback)
        url.callback = provider_required(url.callback)
        url.callback = login_required(url.callback)

    else:  # wrap in everything
        url.callback = clintype_required(url.callback)

# Path: pttrack/decorators.py
# def provider_required(func):
#     return user_passes_test(provider_exists, login_url=reverse_lazy('new-provider'))(func)
# 
# def clintype_required(func):
#     return session_passes_test(clintype_set, fail_url=reverse_lazy('choose-clintype'))(func)
# 
# def provider_update_required(func):
#     return user_passes_test(provider_has_updated, login_url=reverse_lazy('provider-update'))(func)


# Path: pttrack/urls.py
from django.conf.urls import url
from django.views.generic import DetailView
from django.views.generic.base import TemplateView
from django.contrib.auth.decorators import login_required
from .decorators import provider_required, clintype_required, \
    provider_update_required
from . import models
from . import views

    # MISC
    url(r'^about/',
        TemplateView.as_view(template_name='pttrack/about.html'),
        name='about'),
]


def wrap_url(url, no_wrap=[], login_only=[], provider_only=[],
             updated_provider_only=[]):
    '''
    Wrap URL in decorators as appropriate.
    '''
    if url.name in no_wrap:
        # do not wrap at all, fully public
        pass

    elif url.name in login_only:
        url.callback = login_required(url.callback)

    elif url.name in provider_only:
        url.callback = provider_required(url.callback)
        url.callback = login_required(url.callback)

    elif url.name in updated_provider_only:
        url.callback = provider_update_required(url.callback)
        url.callback = provider_required(url.callback)
        url.callback = login_required(url.callback)

    else:  # wrap in everything
        url.callback = clintype_required(url.callback)

        url.callback = provider_update_required(url.callback)