# Path: profile/views.py
# @login_required
# def user_logout(request):
#     """ Handles logging a user out
#     """
#     logout(request)
#     url_next = request.GET.get('next', '/')
#     return redirect(url_next)
# 
# Path: auth/views.py
# class CompleteAuthView(SettingsMixin, View):
#     def get(self, request):
#         return HttpResponseNotFound()
# 
#     def post(self, request):
#         req = prepare_django_request(request)
#         auth = OneLogin_Saml2_Auth(req, self.get_settings())
# 
#         auth.process_response()
# 
#         errors = auth.get_errors()
# 
#         if not errors:
#             if auth.is_authenticated:
#                 user = authenticate(request, saml_authentication=auth)
#                 login(self.request, user)
#                 if 'RelayState' in req['post_data'] and OneLogin_Saml2_Utils.get_self_url(req) != req['post_data'][
#                         'RelayState']:
#                     return redirect(auth.redirect_to(req['post_data']['RelayState']))
#                 else:
#                     return redirect('/')
#             else:
#                 raise PermissionDenied()
#         else:
#             if settings.DEBUG:
#                 print(auth.get_last_error_reason())
#             return HttpResponseBadRequest("Erro processing SAML response ".join(errors))
# 
# class InitAuthView(SettingsMixin, View):
#     def get(self, *args, **kwargs):
#         request = prepare_django_request(self.request)
#         auth = OneLogin_Saml2_Auth(request, self.get_settings())
# 
#         return_url = self.request.GET.get('next', settings.LOGIN_REDIRECT_URL)
# 
#         return redirect(auth.login(return_to=return_url))
# 
# class MetadataView(SettingsMixin, View):
#     def get(self, request, *args, **kwargs):
#         req = prepare_django_request(request)
#         auth = OneLogin_Saml2_Auth(req, self.get_settings())
#         saml_settings = auth.get_settings()
#         metadata = saml_settings.get_sp_metadata()
#         errors = saml_settings.validate_metadata(metadata)
# 
#         if len(errors) == 0:
#             return HttpResponse(content=metadata, content_type='text/xml')
#         return HttpResponseServerError(content=', '.join(errors))
# 
# Path: petitions/views.py
# CONFIG = settings.CONFIG
# PETITION_DEFAULT_TITLE = CONFIG['petitions']['default_title']
# PETITION_DEFAULT_BODY = CONFIG['petitions']['default_body']
# def index(request):
# def about(request):
# def committees(request):
# def news(request):
# def maintenance(request):
# def petition(request, petition_id):
# def petition_create(request):
# def petition_redirect(request, petition_id):
# def get_petition(petition_id, user):
# def petition_bots(request, petition_id):
# def edit_title(petition, new_title):
# def edit_description(petition, new_description):
# def add_update(request, petition, description):
# def add_response(request, petition, description):
# def edit_update(request, petition, update_position, description):
# def edit_response(request, petition, description):
# def petition_edit(request, petition_id):
# def petition_sign(request, petition_id):
# def petition_subscribe(request, petition_id):
# def petition_unsubscribe(request, petition_id):
# def petition_publish(user, petition, request):
# def petition_unpublish(request, petition_id):
# def petition_report(request, petition_id):
# def send_update(update):
# def _json_object_hook(d): return namedtuple('X', d.keys())(*d.values())
# def json2obj(data): return json.loads(data, object_hook=_json_object_hook)
# def edit_check(user, petition):
# def filtering_controller(sorted_objects, tag):
# def sorting_controller(key, query=None):
# def all():
# def most_recent():
# def most_signatures():
# def last_signed():
# def search(query):
# def similar_petitions(query):
# def in_progress():
# def responded():
# def archived():


from profile.views import user_logout
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.http import HttpResponseNotFound, HttpResponseServerError
from django.template import loader
from django.template.response import TemplateResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.defaults import page_not_found, server_error
from auth.views import CompleteAuthView, InitAuthView, MetadataView
from petitions import views
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""




def handler500(request):
    context = {'request': request}
    template_name = '500.html'
    return TemplateResponse(request, template_name, context, status=500)


urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^about/', views.about, name='about'),
    url(r'committees/', views.committees, name='committees'),
    url(r'^news/', views.news, name='news'),
    url(r'^admin/login', InitAuthView.as_view(), name='init-auth'),
    url(r'^admin/', admin.site.urls),
    url(r'^acs$', csrf_exempt(CompleteAuthView.as_view()), name='acs'),
    url(r'^saml$', MetadataView.as_view(), name='metadata'),

# Path: profile/views.py
# @login_required
# def user_logout(request):
#     """ Handles logging a user out
#     """
#     logout(request)
#     url_next = request.GET.get('next', '/')
#     return redirect(url_next)
# 
# Path: auth/views.py
# class CompleteAuthView(SettingsMixin, View):
#     def get(self, request):
#         return HttpResponseNotFound()
# 
#     def post(self, request):
#         req = prepare_django_request(request)
#         auth = OneLogin_Saml2_Auth(req, self.get_settings())
# 
#         auth.process_response()
# 
#         errors = auth.get_errors()
# 
#         if not errors:
#             if auth.is_authenticated:
#                 user = authenticate(request, saml_authentication=auth)
#                 login(self.request, user)
#                 if 'RelayState' in req['post_data'] and OneLogin_Saml2_Utils.get_self_url(req) != req['post_data'][
#                         'RelayState']:
#                     return redirect(auth.redirect_to(req['post_data']['RelayState']))
#                 else:
#                     return redirect('/')
#             else:
#                 raise PermissionDenied()
#         else:
#             if settings.DEBUG:
#                 print(auth.get_last_error_reason())
#             return HttpResponseBadRequest("Erro processing SAML response ".join(errors))
# 
# class InitAuthView(SettingsMixin, View):
#     def get(self, *args, **kwargs):
#         request = prepare_django_request(self.request)
#         auth = OneLogin_Saml2_Auth(request, self.get_settings())
# 
#         return_url = self.request.GET.get('next', settings.LOGIN_REDIRECT_URL)
# 
#         return redirect(auth.login(return_to=return_url))
# 
# class MetadataView(SettingsMixin, View):
#     def get(self, request, *args, **kwargs):
#         req = prepare_django_request(request)
#         auth = OneLogin_Saml2_Auth(req, self.get_settings())
#         saml_settings = auth.get_settings()
#         metadata = saml_settings.get_sp_metadata()
#         errors = saml_settings.validate_metadata(metadata)
# 
#         if len(errors) == 0:
#             return HttpResponse(content=metadata, content_type='text/xml')
#         return HttpResponseServerError(content=', '.join(errors))
# 
# Path: petitions/views.py
# CONFIG = settings.CONFIG
# PETITION_DEFAULT_TITLE = CONFIG['petitions']['default_title']
# PETITION_DEFAULT_BODY = CONFIG['petitions']['default_body']
# def index(request):
# def about(request):
# def committees(request):
# def news(request):
# def maintenance(request):
# def petition(request, petition_id):
# def petition_create(request):
# def petition_redirect(request, petition_id):
# def get_petition(petition_id, user):
# def petition_bots(request, petition_id):
# def edit_title(petition, new_title):
# def edit_description(petition, new_description):
# def add_update(request, petition, description):
# def add_response(request, petition, description):
# def edit_update(request, petition, update_position, description):
# def edit_response(request, petition, description):
# def petition_edit(request, petition_id):
# def petition_sign(request, petition_id):
# def petition_subscribe(request, petition_id):
# def petition_unsubscribe(request, petition_id):
# def petition_publish(user, petition, request):
# def petition_unpublish(request, petition_id):
# def petition_report(request, petition_id):
# def send_update(update):
# def _json_object_hook(d): return namedtuple('X', d.keys())(*d.values())
# def json2obj(data): return json.loads(data, object_hook=_json_object_hook)
# def edit_check(user, petition):
# def filtering_controller(sorted_objects, tag):
# def sorting_controller(key, query=None):
# def all():
# def most_recent():
# def most_signatures():
# def last_signed():
# def search(query):
# def similar_petitions(query):
# def in_progress():
# def responded():
# def archived():


# Path: pawprints/urls.py
from profile.views import user_logout
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.http import HttpResponseNotFound, HttpResponseServerError
from django.template import loader
from django.template.response import TemplateResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.defaults import page_not_found, server_error
from auth.views import CompleteAuthView, InitAuthView, MetadataView
from petitions import views

Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""




def handler500(request):
    context = {'request': request}
    template_name = '500.html'
    return TemplateResponse(request, template_name, context, status=500)


urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^about/', views.about, name='about'),
    url(r'committees/', views.committees, name='committees'),
    url(r'^news/', views.news, name='news'),
    url(r'^admin/login', InitAuthView.as_view(), name='init-auth'),
    url(r'^admin/', admin.site.urls),
    url(r'^acs$', csrf_exempt(CompleteAuthView.as_view()), name='acs'),
    url(r'^saml$', MetadataView.as_view(), name='metadata'),

    url(r'^login/', InitAuthView.as_view(), name='init-auth'),