from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from django.conf import settings
from django.conf.urls import url, include
from django.urls import path, re_path
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required, permission_required
from rowers.models import Workout,Rower,FavoriteChart

from rest_framework import routers, serializers, viewsets,permissions
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework.permissions import *
from rowers import views
from django.contrib.auth import views as auth_views
from django.views.generic.base import TemplateView

from rowers.permissions import IsOwnerOrNot,IsOwnerOrReadOnly
from rowers.serializers import (
    WorkoutSerializer,
    RowerSerializer,
    StrokeDataSerializer,
    FavoriteChartSerializer,
    )

from oauth2_provider.views import (
    AuthorizedTokensListView,
    AuthorizedTokenDeleteView,
    )

from oauth2_provider.views.base import (
    RevokeTokenView
    )

class WorkoutViewSet(viewsets.ModelViewSet):
    model = Workout
    #queryset = Workout.objects.all().order_by("-date", "-starttime")
    serializer_class = WorkoutSerializer

    def get_queryset(self):
        try:
            r = Rower.objects.get(user=self.request.user)
            return Workout.objects.filter(user=r).order_by("-date","-starttime")
        except TypeError:
            return []



    permission_classes = (
        #DjangoModelPermissions,
        IsOwnerOrNot,
    )

class RowerViewSet(viewsets.ModelViewSet):
    model = Rower
    serializer_class = RowerSerializer
    #queryset = Rower.objects.all()

    def get_queryset(self):
        try:
            r = Rower.objects.filter(user=self.request.user)
            return r
        except TypeError:
            return []

    permission_classes = (
        IsOwnerOrNot,
        )

    http_method_names = ['get','patch']


class FavoriteChartViewSet(viewsets.ModelViewSet):
    model = FavoriteChart
    serializer_class = FavoriteChartSerializer
    #queryset = FavoriteChart.objects.all()

    def get_queryset(self):
        try:
            r = Rower.objects.filter(user=self.request.user)
            return FavoriteChart.objects.filter(user=r)
        except TypeError:
            return []

    permission_classes = (
        IsOwnerOrNot,
        )

    http_method_names = ['get','put','patch','delete']

class StrokeDataViewSet(viewsets.ModelViewSet):
    serializer_class = StrokeDataSerializer

# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'api/workouts',WorkoutViewSet, 'workout')
router.register(r'api/me',RowerViewSet, 'rower')
router.register(r'api/charts',FavoriteChartViewSet, 'charts')

def permissiondenied_view(request):
    raise PermissionDenied



def filenotfound_view(request):
    return rowers.views.error403_view(request)

def response_error_handler(request, exception=None):
    return HttpResponse('Error handler content', status=403)

def filenotfound_handler(request, exception=None):
    return HttpResponse('Error handler content', status=404)

handler403 = views.error403_view
handler404 = views.error404_view
handler400 = views.error400_view
handler500 = views.error500_view


from oauth2_provider.views import base
#app_name = "rowers"

urlpatterns = [
    re_path(r'^o/authorize/$', base.AuthorizationView.as_view(), name="authorize"),
    re_path(r'^o/token/$', base.TokenView.as_view(), name="token"),
    re_path(r'^', include(router.urls)),
    re_path(r'^api-docs/$', views.schema_view,name='schema_view'),
    re_path(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    re_path(r'^api/workouts/(?P<id>\b[0-9A-Fa-f]+\b)/strokedata/$',views.strokedatajson,name='strokedatajson'),
    re_path(r'^500v/$',views.error500_view,name='error500_view'),
    path('502/', TemplateView.as_view(template_name='502.html'),name='502'),
    path('500/', TemplateView.as_view(template_name='500.html'),name='500'),
    path('404/', TemplateView.as_view(template_name='404.html'),name='404'),
    path('400/', TemplateView.as_view(template_name='400.html'),name='400'),
    path('403/', TemplateView.as_view(template_name='403.html'),name='403'),
#    re_path(r'^imports/$', views.imports_view),
    re_path(r'^exportallworkouts/?/$',views.workouts_summaries_email_view,name='workouts_summaries_email_view'),
    path('failedjobs/',views.failed_queue_view,name='failed_queue_view'),
    path('failedjobs/empty/',views.failed_queue_empty,name='failed_queue_empty'),
    re_path('^failedjobs/(?P<id>\w+.*)/$',views.failed_job_view,name='failed_job_view'),
    re_path(r'^update_empower/$',views.rower_update_empower_view,name='rower_update_empower_view'),
    re_path(r'^agegroupcp/(?P<age>\d+)/$',views.agegroupcpview,name='agegroupcpview'),
    re_path(r'^agegroupcp/(?P<age>\d+)/(?P<normalize>\d+)/$',views.agegroupcpview,name='agegroupcpview'),
    re_path(r'^ajax_agegroup/(?P<age>\d+)/(?P<weightcategory>\w+.*)/(?P<sex>\w+.*)/(?P<userid>\d+)/$',
        views.ajax_agegrouprecords,name='ajax_agegrouprecords'),
    re_path(r'^updatefitness/(?P<mode>\w+.*)/(?P<days>\d+)/$',views.fitness_metric_view,name='fitness_metric_view'),
    re_path(r'^updatefitness/(?P<mode>\w+.*)/$',views.fitness_metric_view,name='fitness_metric_view'),
    re_path(r'^updatefitness/$',views.fitness_metric_view,name='fitness_metric_view'),
    re_path(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)/(?P<distance>\d+)m/$',
        views.agegrouprecordview,name='agegrouprecordview'),
    re_path(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)/(?P<duration>\d+)min/$',
        views.agegrouprecordview,name='agegrouprecordview'),
    re_path(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)/$',
        views.agegrouprecordview,name='agegrouprecordview'),
    re_path(r'^agegrouprecords/$',
        views.agegrouprecordview,name='agegrouprecordview'),
    re_path(r'^list-workouts/ranking/$',views.workouts_view,{'rankingonly':True},
        name='workouts_view'),
#    re_path(r'^list-workouts/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workouts_view,
#        name='workouts_view'),
    re_path(r'^list-workouts/team/(?P<teamid>\d+)/$',views.workouts_view,
        name='workouts_view'),
    re_path(r'^(?P<rowerid>\d+)/list-workouts/$',views.workouts_view,
        name='workouts_view'),
#    re_path(r'^(?P<rowerid>\d+)/list-workouts/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workouts_view,
#        name='workouts_view'),
    re_path(r'^list-workouts/ranking/user/(?P<userid>\d+)/$',views.workouts_view,{'rankingonly':True},
        name='workouts_view'),
    re_path(r'^list-workouts/user/(?P<userid>\d+)/$',views.workouts_view,
        name='workouts_view'),
#    re_path(r'^list-workouts/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',views.workouts_view,
#        name='workouts_view'),
#    re_path(r'^list-workouts/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workouts_view,
#        name='workouts_view'),
    re_path(r'^virtualevents/$',views.virtualevents_view,name='virtualevents_view'),
    re_path(r'^virtualevent/create/$',views.virtualevent_create_view,name='virtualevent_create_view'),
    re_path(r'^virtualevent/createindoor/$',views.indoorvirtualevent_create_view,name='indoorvirtualevent_create_view'),
    re_path(r'^raceregistration/togglenotification/(?P<id>\d+)/$',
        views.virtualevent_toggle_email_view,name='virtualevent_toggle_email_view'),
    re_path(r'^indoorraceregistration/togglenotification/(?P<id>\d+)/$',
        views.indoorvirtualevent_toggle_email_view,name='indoorvirtualevent_toggle_email_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/$',views.virtualevent_view,name='virtualevent_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/ranking$',views.virtualevent_ranking_view,name='virtualevent_ranking_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/edit/$',views.virtualevent_edit_view,name='virtualevent_edit_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/editindoor/$',views.indoorvirtualevent_edit_view,name='indoorvirtualevent_edit_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/register/$',views.virtualevent_register_view,name='virtualevent_register_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/registerindoor/$',views.indoorvirtualevent_register_view,name='indoorvirtualevent_register_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/adddiscipline/$',views.virtualevent_addboat_view,name='virtualevent_addboat_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/withdraw/(?P<recordid>\d+)/$',views.virtualevent_withdraw_view,name='virtualevent_withdraw_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/withdraw/$',views.virtualevent_withdraw_view,name='virtualevent_withdraw_view'),
    re_path(r'^virtualevent/(?P<id>\b[0-9A-Fa-f]+\b)/submit/$',
        views.virtualevent_submit_result_view,name='virtualevent_submit_result_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/submit/(?P<workoutid>\b[0-9A-Fa-f]+\b)/$',
        views.virtualevent_submit_result_view,name='virtualevent_submit_result_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/disqualify/(?P<recordid>\d+)/',
        views.virtualevent_disqualify_view,name='virtualevent_disqualify_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/withdrawresult/(?P<recordid>\d+)/',
        views.virtualevent_withdrawresult_view,name='virtualevent_withdrawresult_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/download/',
        views.virtualevent_results_download_view,name='virtualevent_results_download_view'),
    re_path(r'^list-workouts/$',views.workouts_view,name='workouts_view'),
    re_path(r'^list-courses/$',views.courses_view,name='courses_view'),
    re_path(r'^list-standards/$',views.standards_view,name='standards_view'),
    re_path(r'^courses/upload/$',views.course_upload_view,name='course_upload_view'),
    re_path(r'^standards/upload/$',views.standards_upload_view,name='standards_upload_view'),
    re_path(r'^standards/upload/(?P<id>\d+)/$',views.standards_upload_view,name='standards_upload_view'),
    re_path(r'^workout/addmanual/(?P<raceid>\d+)/$',views.addmanual_view,name='addmanual_view'),
    re_path(r'^workout/addmanual/$',views.addmanual_view,name='addmanual_view'),
    re_path(r'^team-compare-select/workout/(?P<id>\d+)/team/(?P<teamid>\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/team/(?P<teamid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/team/(?P<teamid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/team/(?P<teamid>\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^team-compare-select/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/workout/(?P<id>\b[0-9A-Fa-f]+\b)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/team/(?P<teamid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
    re_path(r'^team-compare-select/$',views.team_comparison_select,name='team_comparison_select'),
#    re_path(r'^workouts-join-select/team/(?P<teamid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workouts_join_select,
#        name='workouts_join_select'),
    re_path(r'^workouts-join/$',views.workouts_join_view,name='workouts_join_view'),
    re_path(r'^workouts-join/user/(?P<userid>\d+)$',views.workouts_join_view,name='workouts_join_view'),
    re_path(r'^workouts-join-select/team/(?P<teamid>\d+)/$',views.workouts_join_select,name='workouts_join_select'),
 #   re_path(r'^workouts-join-select/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workouts_join_select,name='workouts_join_select'),
    re_path(r'^workouts-join-select/$',views.workouts_join_select,name='workouts_join_select'),
    re_path(r'^workouts-join-select/user/(?P<userid>\d+)/$',views.workouts_join_select,name='workouts_join_select'),
    re_path(r'^user-boxplot-select/user/(?P<userid>\d+)/$',views.user_boxplot_select,name='user_boxplot_select'),
    re_path(r'^user-boxplot-select/$',views.user_boxplot_select,name='user_boxplot_select'),
    re_path(r'^user-analysis-select/(?P<function>\w.*)/user/(?P<userid>\d+)/$',views.analysis_new,name='analysis_new'),
    re_path(r'^user-analysis-select/(?P<function>\w.*)/team/(?P<teamid>\d+)/$',views.analysis_new,name='analysis_new'),
    re_path(r'^user-analysis-select/user/(?P<userid>\d+)/$',views.analysis_new,name='analysis_new'),
    re_path(r'^user-analysis-select/team/(?P<teamid>\d+)/$',views.analysis_new,name='analysis_new'),
    re_path(r'^user-analysis-select/(?P<function>\w.*)/$',views.analysis_new,name='analysis_new'),
    re_path(r'^user-analysis-select/$',views.analysis_new,name='analysis_new'),
#    re_path(r'^user-multiflex-select/user/(?P<userid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.user_multiflex_select,name='user_multiflex_select'),
    re_path(r'^user-multiflex-select/user/(?P<userid>\d+)/$',views.user_multiflex_select,name='user_multiflex_select'),
#    re_path(r'^user-multiflex-select/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.user_multiflex_select,name='user_multiflex_select'),
    re_path(r'^user-multiflex-select/$',views.user_multiflex_select,name='user_multiflex_select'),
    re_path(r'^list-jobs/$',views.session_jobs_view,name='session_jobs_view'),
    re_path(r'^jobs-status/$',views.session_jobs_status,name='session_jobs_status'),
    re_path(r'^job-kill/(?P<id>.*)/$',views.kill_async_job),
#    re_path(r'^test-job/(?P<aantal>\d+)/$',views.test_job_view),
#    re_path(r'^test-job2/(?P<aantal>\d+)/$',views.test_job_view2),
    re_path(r'^record-progress/(?P<value>\d+)/(?P<id>.*)/$',views.post_progress,name='post_progress'),
    re_path(r'^record-progress/(?P<id>.*)/$',views.post_progress),
    re_path(r'^record-progress/$',views.post_progress),
    re_path(r'^list-graphs/$',views.graphs_view,name='graphs_view'),
    re_path(r'^list-graphs/user/(?P<userid>\d+)/$',views.graphs_view,name='graphs_view'),
    re_path(r'^fitness-progress/$',views.fitnessmetric_view,name='fitnessmetric_view'),
    re_path(r'^fitness-progress/user/(?P<userid>\d+)/$',views.fitnessmetric_view,name='fitnessmetric_view'),
    re_path(r'^fitness-progress/user/(?P<userid>\d+)/(?P<mode>\w+.*)/$',views.fitnessmetric_view,name='fitnessmetric_view'),
#    re_path(r'^ote-bests/user/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.rankings_view,name='rankings_view'),
    re_path(r'^ote-bests/user/(?P<userid>\d+)/$',views.rankings_view,name='rankings_view'),
#    re_path(r'^ote-bests/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.rankings_view,name='rankings_view'),
    re_path(r'^ote-bests/$',views.rankings_view,name='rankings_view'),
    re_path(r'^(?P<userid>\d+)/ote-bests/$',views.rankings_view,name='rankings_view'),
#    re_path(r'^(?P<theuser>\d+)/ote-bests2/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.rankings_view2,name='rankings_view2'),
    re_path(r'^ote-bests2/user/(?P<userid>\d+)/$',views.rankings_view2,name='rankings_view2'),
#    re_path(r'^ote-bests2/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.rankings_view2,name='rankings_view2'),
    re_path(r'^ote-bests2/$',views.rankings_view2,name='rankings_view2'),
#    re_path(r'^otw-bests/user/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.otwrankings_view,name='otwrankings_view'),
#    re_path(r'^otw-bests/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.otwrankings_view,name='otwrankings_view'),
    re_path(r'^otw-bests/user/(?P<userid>\d+)/$',views.otwrankings_view,name='otwrankings_view'),
    re_path(r'^otw-bests/$',views.otwrankings_view,name='otwrankings_view'),
#    re_path(r'^ote-ranking/user/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.oterankings_view,name='oterankings_view'),
#    re_path(r'^ote-ranking/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.oterankings_view,name='oterankings_view'),
    re_path(r'^ote-ranking/$',views.oterankings_view,name='oterankings_view'),
    re_path(r'^ote-ranking/user/(?P<userid>\d+)/$',views.oterankings_view,name='oterankings_view'),
#    re_path(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<theuser>\d+)/$',views.cum_flex,name='cum_flex'),
#    re_path(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.cum_flex,name='cum_flex'),
    re_path(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/$',views.cum_flex,name='cum_flex'),
    re_path(r'^analysisdata/$',views.analysis_view_data,name='analysis_view_data'),
    re_path(r'^flexall/user/(?P<theuser>\d+)/$',views.cum_flex,name='cum_flex'),
    re_path(r'^flexall/$',views.cum_flex,name='cum_flex'),
    re_path(r'^flexalldata/$',views.cum_flex_data,name='cum_flex_data'),
    re_path(r'^histo/user/(?P<userid>\d+)/$',views.histo,name='histo'),
    re_path(r'^histodata/$',views.histo_data,name='histo_data'),
#    re_path(r'^histo/user/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.histo,name='histo'),
    re_path(r'^histo/$',views.histo,name='histo'),
    re_path(r'^cumstats/user/(?P<userid>\d+)/$',views.cumstats,name='cumstats'),
#    re_path(r'^cumstats/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.cumstats,name='cumstats'),
#    re_path(r'^cumstats/user/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.cumstats,name='cumstats'),
#    re_path(r'^cumstats/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.cumstats,name='cumstats'),
    re_path(r'^cumstats/$',views.cumstats,name='cumstats'),
    re_path(r'^graph/(?P<id>\d+)/$',views.graph_show_view,name='graph_show_view'),
    re_path(r'^graph/(?P<pk>\d+)/delete/$',views.GraphDelete.as_view(),name='graph_delete'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/get-thumbnails/$',views.get_thumbnails,
        name='get_thumbnails'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/otwuseimpeller/$',views.otw_use_impeller,
        name='otw_use_impeller'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/otwusegps/$',views.otw_use_gps,
        name='otw_use_gps'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/toggle-ranking/$',views.workout_toggle_ranking,
        name='workout_toggle_ranking'),
    re_path(r'^workout/upload/team/$',views.team_workout_upload_view,name='team_workout_upload_view'),
    re_path(r'^workout/upload/(?P<raceid>\d+)/$',views.workout_upload_view,name='workout_upload_view'),
    re_path(r'^workout/upload/$',views.workout_upload_view,name='workout_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/histo/$',views.workout_histo_view,
        name='workout_histo_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/task/$',views.workout_test_task_view,name='workout_test_task_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/forcecurve/$',views.workout_forcecurve_view,
        name='workout_forcecurve_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/unsubscribe/$',views.workout_unsubscribe_view,
        name='workout_unsubscribe_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/export/$',views.workout_export_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/comment/$',views.workout_comment_view,
        name='workout_comment_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/emailtcx/$',views.workout_tcxemail_view,
        name='workout_tcxemail_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/emailgpx/$',views.workout_gpxemail_view,
        name='workout_gpxemail_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/emailcsv/$',views.workout_csvemail_view,
        name='workout_csvemail_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/csvtoadmin/$',views.workout_csvtoadmin_view,
        name='workout_csvtoadmin_view'),
#    re_path(r'^ergcpdatatoadmin/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.otecp_toadmin_view,name='otecp_toadmin_view'),
#    re_path(r'^otwcpdatatoadmin/(?P<theuser>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.otwcp_toadmin_view,name='otwcp_toadmin_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/edit/$',views.workout_edit_view,
        name='workout_edit_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/map/$',views.workout_map_view,name='workout_map_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/setprivate/$',views.workout_setprivate_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/updatecp/$',views.workout_update_cp_view,name='workout_update_cp_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/makepublic/$',views.workout_makepublic_view),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/geeky/$',views.workout_geeky_view),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/advanced/$',views.workout_advanced_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/instroke/(?P<metric>\w+.*)/$',views.instroke_chart,name='instroke_chart'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/instroke/$',views.instroke_view,name='instroke_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/stats/$',views.workout_stats_view,name='workout_stats_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/data/$',views.workout_data_view,
        name='workout_data_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/otwsetpower/$',views.workout_otwsetpower_view,name='workout_otwsetpower_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/interactiveotwplot/$',views.workout_otwpowerplot_view,name='workout_otwpowerplot_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/wind/$',views.workout_wind_view,name='workout_wind_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/image/$',views.workout_uploadimage_view,name='workout_uploadimage_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/compare/$',views.virtualevent_compare_view,name='virtualevent_compare_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/mapcompare/$',views.virtualevent_mapcompare_view,
            name='virtualevent_mapcompare_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/image/$',
        views.virtualevent_uploadimage_view,name='virtualevent_uploadimage_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/setimage/(?P<logoid>\d+)/$',
        views.virtualevent_setlogo_view,name='virtualevent_setlog_view'),
    re_path(r'^virtualevent/(?P<id>\d+)/follow/$',
        views.addfollower_view,name='addfollower_view'),
    re_path(r'^logo/(?P<id>\d+)/delete/$',
        views.logo_delete_view,name='logo_delete_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/darkskywind/$',views.workout_downloadwind_view,name='workout_downloadwind_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/metar/(?P<airportcode>\w+)/$',views.workout_downloadmetar_view,name='workout_downloadmetar_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/stream/$',views.workout_stream_view,name='workout_stream_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/crewnerdsummary/$',views.workout_crewnerd_summary_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/editintervals/$',views.workout_summary_edit_view,
        name='workout_summary_edit_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/restore/$',views.workout_summary_restore_view,name='workout_summary_restore_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/split/$',views.workout_split_view,name='workout_split_view'),
#    re_path(r'^workout/(?P<id>\d+)/interactiveplot/$',views.workout_biginteractive_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/view/entry/(?P<raceresult>\d+)/$',views.workout_view,name='workout_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/view/$',views.workout_view,name='workout_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/video/$',views.workout_video_create_view,
            name='workout_video_create_view'),
    re_path(r'^video/(?P<pk>\d+)/delete/$',views.VideoDelete.as_view(),name='video_delete'),
    re_path(r'^video/(?P<id>\w.+)/m/$',views.workout_video_view_mini,
        name='workout_video_view_mini'),
    re_path(r'^video/(?P<id>\w.+)/$',views.workout_video_view,
            name='workout_video_view'),
    re_path(r'^videos/$',views.list_videos,name='list_videos'),
    re_path(r'^videos/user/(?P<userid>\d+)/$',views.list_videos,name='list_videos'),
    re_path(r'^add-video/user/(?P<userid>\d+)/$',views.video_selectworkout,name='video_selectworkout'),
    re_path(r'^add-video/',views.video_selectworkout,name='video_selectworkout'),
#    re_path(r'^workout/(?P<id>\d+)/$',views.workout_view,name='workout_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/$',views.workout_view,name='workout_view'),
    re_path(r'^workout/fusion/(?P<id1>\b[0-9A-Fa-f]+\b)/(?P<id2>\b[0-9A-Fa-f]+\b)/$',views.workout_fusion_view,name='workout_fusion_view'),
    re_path(r'^workout/fusion/(?P<id>\b[0-9A-Fa-f]+\b)/$',views.workout_fusion_list,name='workout_fusion_list'),
#    re_path(r'^workout/fusion/(?P<id>\b[0-9A-Fa-f]+\b)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.workout_fusion_list,name='workout_fusion_list'),
    re_path(r'^help/$',TemplateView.as_view(
        template_name='help.html'),name='help'
        ),
    re_path(r'^physics/$',TemplateView.as_view(template_name='physics.html'),name='physics'),
    re_path(r'^partners/$',TemplateView.as_view(template_name='partners.html'),name='partners'),
    # keeping the old URLs for retrofit
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addtimeplot/$',
        views.workout_add_chart_view,
        {'plotnr':'1'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/adddistanceplot/$',
        views.workout_add_chart_view,
        {'plotnr':'2'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addpiechart/$',
        views.workout_add_chart_view,
        {'plotnr':'3'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/adddistanceplot2/$',
        views.workout_add_chart_view,
        {'plotnr':'7'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addtimeplot2/$',
        views.workout_add_chart_view,
        {'plotnr':'8'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addotwpowerplot/$',
        views.workout_add_chart_view,
        {'plotnr':'9'},name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addpowerpiechart/$',
        views.workout_add_chart_view,
        {'plotnr':'13'},name='workout_add_chart_view'),
    # addstatic is the new URL -> need to update in templates
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addstatic/(?P<plotnr>\d+)/$',
        views.workout_add_chart_view,name='workout_add_chart_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/addstatic/$',views.workout_add_chart_view,name='workout_add_chart_view'),
    re_path(r'^workout/(?P<pk>\b[0-9A-Fa-f]+\b)/delete/$',login_required(
        views.WorkoutDelete.as_view()),
        name='workout_delete'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/delete/$',login_required(
#        views.workout_code_delete_view),name='workout_code_delete'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/smoothenpace/$',views.workout_smoothenpace_view,name='workout_smoothenpace_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/undosmoothenpace/$',views.workout_undo_smoothenpace_view,name='workout_undo_smoothenpace_view'),
    re_path(r'^workout/c2import/$',views.workout_c2import_view,name='workout_c2import_view'),
    re_path(r'^workout/c2list/$',views.workout_c2import_view,name='workout_c2import_view'),
    re_path(r'^workout/c2list/(?P<page>\d+)/$',views.workout_c2import_view,name='workout_c2import_view'),
    re_path(r'^workout/c2list/user/(?P<userid>\d+)/$',views.workout_c2import_view,name='workout_c2import_view'),
    re_path(r'^workout/c2list/(?P<page>\d+)/user/(?P<userid>\d+)/$',views.workout_c2import_view,name='workout_c2import_view'),
    re_path(r'^workout/stravaimport/$',views.workout_stravaimport_view,name='workout_stravaimport_view'),
    re_path(r'^workout/stravaimport/user/(?P<userid>\d+)/$',views.workout_stravaimport_view,name='workout_stravaimport_view'),
    re_path(r'^workout/c2import/all/$',views.workout_getc2workout_all,name='workout_getc2workout_all'),
    re_path(r'^workout/c2import/all/(?P<page>\d+)/$',views.workout_getc2workout_all,name='workout_getc2workout_all'),
    re_path(r'^workout/(?P<source>\w+.*)import/(?P<externalid>\d+)/$',views.workout_getimportview,name='workout_getimportview'),
    re_path(r'^workout/stravaimport/all/$',views.workout_getstravaworkout_all,name='workout_getstravaworkout_all'),
    re_path(r'^workout/stravaimport/next/$',views.workout_getstravaworkout_next,name='workout_getstravaworkout_next'),
    re_path(r'^workout/sporttracksimport/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
    re_path(r'^workout/sporttracksimport/user/(?P<userid>\d+)/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
    re_path(r'^workout/sporttracksimport/all/$',views.workout_getsporttracksworkout_all,name='workout_getsporttracksworkout_all'),
    re_path(r'^workout/polarimport/$',views.workout_polarimport_view,name='workout_polarimport_view'),
    re_path(r'^workout/polarimport/user/(?P<userid>\d+)/',views.workout_polarimport_view,name='workout_polarimport_view'),
    re_path(r'^workout/runkeeperimport/$',views.workout_runkeeperimport_view,name='workout_runkeeperimport_view'),
    re_path(r'^workout/runkeeperimport/user/(?P<userid>\d+)/$',views.workout_runkeeperimport_view,name='workout_runkeeperimport_view'),
    re_path(r'^workout/underarmourimport/user/(?P<userid>\d+)/$',views.workout_underarmourimport_view,name='workout_underarmourimport_view'),
    re_path(r'^workout/underarmourimport/$',views.workout_underarmourimport_view,name='workout_underarmourimport_view'),
#    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/deleteconfirm/$',views.workout_delete_confirm_view),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/c2uploadw/$',views.workout_c2_upload_view,name='workout_c2_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/stravauploadw/$',views.workout_strava_upload_view,name='workout_strava_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/recalcsummary/$',views.workout_recalcsummary_view,name='workout_recalcsummary_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/sporttracksuploadw/$',views.workout_sporttracks_upload_view,name='workout_sporttracks_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/runkeeperuploadw/$',views.workout_runkeeper_upload_view,name='workout_runkeeper_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/underarmouruploadw/$',views.workout_underarmour_upload_view,name='workout_underarmour_upload_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/tpuploadw/$',views.workout_tp_upload_view,name='workout_tp_upload_view'),
    re_path(r'^multi-compare/workout/(?P<id>\b[0-9A-Fa-f]+\b)/user/(?P<userid>\d+)/$',views.multi_compare_view,
        name='multi_compare_view'),
    re_path(r'^multi-compare/workout/(?P<id>\b[0-9A-Fa-f]+\b)/$',views.multi_compare_view,name='multi_compare_view'),
    re_path(r'^multi-compare/$',views.multi_compare_view,name='multi_compare_view'),
    re_path(r'^alerts/user/(?P<userid>\d+)/$',views.alerts_view,name='alerts_view'),
    re_path(r'^alerts/$',views.alerts_view,name='alerts_view'),
    re_path(r'^alerts/(?P<pk>\d+)/delete/$',views.AlertDelete.as_view(),name='alert_delete_view'),
    re_path(r'^alerts/(?P<id>\d+)/edit/user/(?P<userid>\d+)/$',views.alert_edit_view,name='alert_edit_view'),
    re_path(r'^alerts/(?P<id>\d+)/edit/$',views.alert_edit_view,name='alert_edit_view'),
    re_path(r'^alerts/new/user/(?P<userid>\d+)/$',views.alert_create_view, name='alert_create_view'),
    re_path(r'^alerts/new/$',views.alert_create_view, name='alert_create_view'),
    re_path(r'^alerts/(?P<id>\d+)/report/user/(?P<userid>\d+)/$',views.alert_report_view,name='alert_report_view'),
    re_path(r'^alerts/(?P<id>\d+)/report/(?P<nperiod>\d+)/user/(?P<userid>\d+)/$',views.alert_report_view,name='alert_report_view'),
    re_path(r'^alerts/(?P<id>\d+)/report/$',views.alert_report_view,name='alert_report_view'),
    re_path(r'^user-boxplot/user/(?P<userid>\d+)/$',views.boxplot_view,name='boxplot_view'),
    re_path(r'^user-boxplot/$',views.boxplot_view,name='boxplot_view'),
    re_path(r'^user-boxplot-data/$',views.boxplot_view_data,name='boxplot_view_data'),
    re_path(r'^user-multiflex/user/(?P<userid>\d+)/$',views.multiflex_view,name='multiflex_view'),
    re_path(r'^user-multiflex/$',views.multiflex_view,name='multiflex_view'),
    re_path(r'^user-multiflex-data/$',views.multiflex_data,name='multiflex_data'),
    re_path(r'^me/deactivate/$',views.deactivate_user,name='deactivate_user'),
    re_path(r'^me/delete/$',views.remove_user,name='remove_user'),
    re_path(r'^survey/$',views.survey,name='survey'),
    re_path(r'^me/gdpr-optin-confirm/?/$',views.user_gdpr_confirm,name='user_gdpr_confirm'),
    re_path(r'^me/gdpr-optin-confirm/$',views.user_gdpr_confirm,name='user_gdpr_confirm'),
    re_path(r'^me/gdpr-optin/?/$',views.user_gdpr_optin,name='user_gdpr_optin'),
    re_path(r'^me/gdpr-optin/$',views.user_gdpr_optin,name='user_gdpr_optin'),
    re_path(r'^me/teams/$',views.rower_teams_view,name='rower_teams_view'),
    re_path(r'^me/calcdps/$',views.rower_calcdps_view,name='rower_calcdps_view'),
    re_path(r'^me/exportsettings/$',views.rower_exportsettings_view,name='rower_exportsettings_view'),
    re_path(r'^me/exportsettings/user/(?P<userid>\d+)/$',views.rower_exportsettings_view,name='rower_exportsettings_view'),
    re_path(r'^team/(?P<team_id>\d+)/$',views.team_view,name='team_view'),
    re_path(r'^team/(?P<team_id>\d+)/memberstats/$',views.team_members_stats_view,name='team_members_stats_view'),
    re_path(r'^team/(?P<team_id>\d+)/edit/$',views.team_edit_view,name='team_edit_view'),
    re_path(r'^team/(?P<id>\d+)/leaveconfirm/$',views.team_leaveconfirm_view,name='team_leaveconfirm_view'),
    re_path(r'^team/(?P<id>\d+)/leave/$',views.team_leave_view,name='team_leave_view'),
    re_path(r'^team/(?P<team_id>\d+)/deleteconfirm/$',views.team_deleteconfirm_view,name='team_deleteconfirm_view'),
    re_path(r'^team/(?P<teamid>\d+)/requestmembership/(?P<userid>\d+)/$',views.team_requestmembership_view,name='team_requestmembership_view'),
    re_path(r'^me/coachrequest/(?P<id>\d+)/reject/$',views.reject_revoke_coach_request,
        name='reject_revoke_coach_request'),
    re_path(r'^coaches/(?P<id>\d+)/dropconfirm/$',views.coach_drop_athlete_confirm_view,
        name='coach_drop_athlete_confirm_view'),
    re_path(r'^coaches/(?P<id>\d+)/drop/$',views.coach_drop_athlete_view,
        name='coach_drop_athlete_view'),
     re_path(r'^coaches/(?P<id>\d+)/dropcoachconfirm/$',views.athlete_drop_coach_confirm_view,
        name='athlete_drop_coach_confirm_view'),
    re_path(r'^coaches/(?P<id>\d+)/dropcoach/$',views.athlete_drop_coach_view,
        name='athlete_drop_coach_view'),
    re_path(r'^me/coachrequest/(?P<id>\d+)/revoke/$',views.reject_revoke_coach_request,
        name='reject_revoke_coach_request'),
    re_path(r'^me/coachoffer/(?P<id>\d+)/reject/$',views.reject_revoke_coach_offer,
        name='reject_revoke_coach_offer'),
    re_path(r'^me/coachoffer/(?P<id>\d+)/revoke/$',views.reject_revoke_coach_offer,
        name='reject_revoke_coach_offer'),
    re_path(r'^me/coachrequest/(?P<coachid>\d+)/$',views.request_coaching_view,
        name='request_coaching_view'),
    re_path(r'^me/coachoffer/(?P<userid>\d+)/$',views.offer_coaching_view,
        name='offer_coaching_view'),
    re_path(r'^me/coachrequest/(?P<code>\w+.*)/accept/$',views.coach_accept_coachrequest_view,
        name='coach_accept_coachrequest_view'),
    re_path(r'^me/coachoffer/(?P<code>\w+.*)/accept/$',views.rower_accept_coachoffer_view,
        name='rower_accept_coachoffer_view'),
    re_path(r'^team/(?P<team_id>\d+)/delete/$',views.team_delete_view,name='team_delete_view'),
    re_path(r'^team/create/$',views.team_create_view,name='team_create_view'),
    re_path(r'^me/team/(?P<teamid>\d+)/drop/(?P<userid>\d+)/$',views.manager_member_drop_view,name='manager_member_drop_view'),
    re_path(r'^me/invitation/(?P<id>\d+)/reject/$',views.invitation_reject_view,name='invitation_reject_view'),
    re_path(r'^me/invitation/(?P<id>\d+)/revoke/$',views.invitation_revoke_view,name='invitation_revoke_view'),
    re_path(r'^me/invitation/$',views.rower_invitations_view,name='rower_invitations_view'),
    re_path(r'^me/raise500/$',views.raise_500,name='raise_500'),
    re_path(r'^me/invitation/(\w+.*)/$',views.rower_invitations_view,name='rower_invitations_view'),
    re_path(r'^me/request/(?P<id>\d+)/revoke/$',views.request_revoke_view,name='request_revoke_view'),
    re_path(r'^me/request/(?P<id>\d+)/reject/$',views.request_reject_view,name='request_reject_view'),
    re_path(r'^me/request/(\w+.*)/$',views.manager_requests_view,name='manager_requests_view'),
    re_path(r'^me/request/$',views.manager_requests_view,name='manager_requests_view'),
    re_path(r'^me/edit/$',views.rower_edit_view,name='rower_edit_view'),
    re_path(r'^me/edit/user/(?P<userid>\d+)/$',views.rower_edit_view,name='rower_edit_view'),
    re_path(r'^me/preferences/$',views.rower_prefs_view,name='rower_prefs_view'),
    re_path(r'^me/transactions/$',views.transactions_view,name='transactions_view'),
    re_path(r'^me/preferences/user/(?P<userid>\d+)/$',views.rower_prefs_view,name='rower_prefs_view'),
    re_path(r'^me/edit/(.+.*)/$',views.rower_edit_view,name='rower_edit_view'),
    re_path(r'^me/c2authorize/$',views.rower_c2_authorize,name='rower_c2_authorize'),
    re_path(r'^me/polarauthorize/$',views.rower_polar_authorize,name='rower_polar_authorize'),
    re_path(r'^me/revokeapp/(?P<id>\d+)/$',views.rower_revokeapp_view,name='rower_revokeapp_view'),
    re_path(r'^me/stravaauthorize/$',views.rower_strava_authorize,name='rower_strava_authorize'),
    re_path(r'^me/sporttracksauthorize/$',views.rower_sporttracks_authorize,name='rower_sporttracks_authorize'),
    re_path(r'^me/underarmourauthorize/$',views.rower_underarmour_authorize,name='rower_underarmour_authorize'),
    re_path(r'^me/tpauthorize/$',views.rower_tp_authorize,name='rower_tp_authorize'),
    re_path(r'^me/runkeeperauthorize/$',views.rower_runkeeper_authorize,name='rower_runkeeper_authorize'),
    re_path(r'^me/sporttracksrefresh/$',views.rower_sporttracks_token_refresh,name='rower_sporttracks_token_refresh'),
    re_path(r'^me/underarmourrefresh/$',views.rower_underarmour_token_refresh,name='rower_underarmoud_token_refresh'),
    re_path(r'^me/tprefresh/$',views.rower_tp_token_refresh,name='rower_tp_token_refresh'),
    re_path(r'^me/c2refresh/$',views.rower_c2_token_refresh,name='rower_c2_token_refresh'),
    re_path(r'^me/favoritecharts/$',views.rower_favoritecharts_view,name='rower_favoritecharts_view'),
    re_path(r'^me/favoritecharts/user/(?P<userid>\d+)/$',views.rower_favoritecharts_view,name='rower_favoritecharts_view'),
#    re_path(r'^me/workflowconfig/$',views.workout_workflow_config_view),
    re_path(r'^me/workflowconfig2/$',views.workout_workflow_config2_view,name='workout_workflow_config2_view'),
    re_path(r'^me/workflowconfig2/user/(?P<userid>\d+)/$',views.workout_workflow_config2_view,name='workout_workflow_config2_view'),
    re_path(r'^me/workflowdefault/$',views.workflow_default_view,name='workflow_default_view'),
    re_path(r'^email/send/$', views.sendmail,name='sendmail'),
    re_path(r'^email/thankyou/$', TemplateView.as_view(template_name='thankyou.html'), name='thankyou'),
    re_path(r'^email/$', TemplateView.as_view(template_name='email.html'), name='email'),
    re_path(r'^about', TemplateView.as_view(template_name='about_us.html'),name='about'),
    re_path(r'^brochure/$',TemplateView.as_view(template_name='brochure.html'),
        name='brochure'),
    re_path(r'^developers', TemplateView.as_view(template_name='developers.html'),name='about'),
#    re_path(r'^compatibility', TemplateView.as_view(template_name='compatibility.html'),name='about'),
#    re_path(r'^videos', TemplateView.as_view(template_name='videos.html'),name='videos'),
    re_path(r'^analysis/user/(?P<userid>\d+)/$', views.analysis_view,name='analysis'),
    re_path(r'^laboratory/$', views.laboratory_view,name='laboratory_view'),
    re_path(r'^laboratory/user/(?P<userid>\d+)/$', views.laboratory_view,name='laboratory_view'),
    re_path(r'^errormessage/(?P<errormessage>[\w\ ]+.*)/$',views.errormessage_view,name='errormessage_view'),
    re_path(r'^analysis/$', views.analysis_view,name='analysis'),
    re_path(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'),
    re_path(r'^checkout/(?P<planid>\d+)/$',views.payment_confirm_view,name='payment_confirm_view'),
    re_path(r'^upgradecheckout/(?P<planid>\d+)/$',views.upgrade_confirm_view,name='upgrade_confirm_view'),
    re_path(r'^upgradecheckout/(?P<planid>\d+)/$',views.upgrade_confirm_view,name='upgrade_confirm_view'),
    re_path(r'^downgradecheckout/(?P<planid>\d+)/$',views.downgrade_confirm_view,name='downgrade_confirm_view'),
    re_path(r'^billing/$',views.billing_view,name='billing'),
    re_path(r'^upgrade/$',views.upgrade_view,name='upgrade'),
    re_path(r'^downgrade/$',views.downgrade_view,name='downgrade'),
    re_path(r'^paymentcompleted/$',views.payment_completed_view,name='payment_completed_view'),
    re_path(r'^downgradecompleted/$',views.downgrade_completed_view,name='downgrade_completed_view'),
    re_path(r'^paidplans/$',views.paidplans_view,name='paidplans_view'),
    re_path(r'^me/cancelsubscriptions/$',views.plan_stop_view,name='plan_stop_view'),
    re_path(r'^me/cancelsubscription/(?P<id>[\w\ ]+.*)/$',views.plan_tobasic_view,name='plan_tobasic_view'),
    re_path(r'^checkouts/$',views.checkouts_view,name='checkouts'),
    re_path(r'^upgradecheckouts/$',views.upgrade_checkouts_view,name='upgrade_checkouts'),
    re_path(r'^downgradecheckouts/$',views.downgrade_checkouts_view,name='downgrade_checkouts'),
    re_path(r'^planrequired/',views.planrequired_view,name='planrequired_view'),
    re_path(r'^starttrial/$',views.start_trial_view,name='start_trial_view'),
    re_path(r'^startplantrial/$',views.start_plantrial_view,name='start_plantrial_view'),
#    re_path(r'^planmembership', TemplateView.as_view(template_name='planmembership.html'),name='planmembership'),
 #   re_path(r'^paypaltest', TemplateView.as_view(template_name='paypaltest.html'),name='paypaltest'),
    re_path(r'^legal', TemplateView.as_view(template_name='legal.html'),name='legal'),
    re_path(r'^register/$',views.rower_register_view,name='rower_register_view'),
    re_path(r'^coachregister/$',views.freecoach_register_view,name='freecoach_register_view'),
    re_path(r'^register/thankyou/$', TemplateView.as_view(template_name='registerthankyou.html'), name='registerthankyou'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/workflow/$',views.workout_workflow_view,
        name='workout_workflow_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/flexchart/(?P<xparam>[\w\ ]+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)/(?P<plottype>\w+)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/flexchart/(?P<xparam>\w+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)/(?P<plottype>\w+.*)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/flexchart/(?P<xparam>\w+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)/$',views.workout_flexchart3_view,name='workout_flexchart3_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/flexchart/$',views.workout_flexchart3_view,name='workout_flexchart3_view'),
#    re_path(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/(?P<plottype>[\w\ ]+.*)/$',views.workout_comparison_view2),
#    re_path(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/$',views.workout_comparison_view2),
    re_path(r'^test\_callback',views.rower_process_testcallback,name='rower_process_testcallback'),
    re_path(r'^createplan/$',views.rower_create_trainingplan,name='rower_create_trainingplan'),
    re_path(r'^createplan/user/(?P<id>\d+)/$',views.rower_create_trainingplan,name='rower_create_trainingplan'),
    re_path(r'^deleteplan/(?P<pk>\d+)/$',login_required(
        views.TrainingPlanDelete.as_view()),name='trainingplan_delete_view'),
    re_path(r'^deletemicrocycle/(?P<pk>\d+)/$',login_required(
        views.MicroCycleDelete.as_view()),name='microcycle_delete_view'),
    re_path(r'^deletemesocycle/(?P<pk>\d+)/$',login_required(
        views.MesoCycleDelete.as_view()),name='mesocycle_delete_view'),
    re_path(r'^deletemacrocycle/(?P<pk>\d+)/$',login_required(
        views.MacroCycleDelete.as_view()),name='macrocycle_delete_view'),
#    re_path(r'^deleteplan/(?P<id>\d+)/$',views.rower_delete_trainingplan),
    re_path(r'^plan/(?P<id>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/user/(?P<userid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/micro/(?P<thismicroid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/micro/(?P<thismicroid>\d+)/user/(?P<userid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/meso/(?P<thismesoid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/meso/(?P<thismesoid>\d+)/user/(?P<userid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/macro/(?P<thismacroid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/macro/(?P<thismacroid>\d+)/user/(?P<userid>\d+)/$',views.rower_trainingplan_view,
        name='rower_trainingplan_view'),
    re_path(r'^plan/(?P<id>\d+)/execution/$',views.rower_trainingplan_execution_view,
            name='rower_trainingplan_execution_view'),
    re_path(r'^plan/(?P<id>\d+)/execution/user/(?P<userid>\d+)/$',views.rower_trainingplan_execution_view,
            name='rower_trainingplan_execution_view'),
    re_path(r'^macrocycle/(?P<pk>\d+)/$',login_required(
        views.TrainingMacroCycleUpdate.as_view()),
        name='macrocycle_update_view'),
    re_path(r'^mesocycle/(?P<pk>\d+)/$',login_required(
        views.TrainingMesoCycleUpdate.as_view()),
        name='mesocycle_update_view'),
    re_path(r'^macrocycle/(?P<id>\d+)/planbymonths/$',login_required(
        views.planmacrocyclebymonth)),
    re_path(r'^macrocycle/(?P<id>\d+)/planbymonths/user/(?P<userid>\d+)/$',views.planmacrocyclebymonth),
    re_path(r'^mesocycle/(?P<id>\d+)/planbyweeks/$',views.planmesocyclebyweek),
    re_path(r'^mesocycle/(?P<id>\d+)/planbyweeks/user/(?P<userid>\d+)/$',views.planmesocyclebyweek),
    re_path(r'^microcycle/(?P<pk>\d+)/$',login_required(
        views.TrainingMicroCycleUpdate.as_view()),
        name='microcycle_update_view'),
    re_path(r'^deletetarget/(?P<id>\d+)/$',views.rower_delete_trainingtarget,
        name='rower_delete_trainingtarget'),
    re_path(r'^editplan/(?P<pk>\d+)/$',login_required(
        views.TrainingPlanUpdate.as_view()),
        name='trainingplan_update_view'),
    re_path(r'^edittarget/(?P<pk>\d+)/$',login_required(
        views.TrainingTargetUpdate.as_view()),
        name='trainingtarget_update_view'),
    re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/test\_strokedata/$',views.strokedataform),
    re_path(r'^sessions/teamcreate/user/(?P<userid>\d+)/$',views.plannedsession_teamcreate_view,
        name='plannedsession_teamcreate_view'),
    re_path(r'^sessions/teamcreate/team/(?P<teamid>\d+)/user/(?P<userid>\d+)/$',
        views.plannedsession_teamcreate_view,
        name='plannedsession_teamcreate_view'),
    re_path(r'^sessions/teamcreate/$',views.plannedsession_teamcreate_view,
        name='plannedsession_teamcreate_view'),
    re_path(r'^sessions/teamcreate/team/$',
        views.plannedsession_teamcreate_view,
        name='plannedsession_teamcreate_view'),
    re_path(r'^sessions/teamedit/(?P<id>\d+)/$',views.plannedsession_teamedit_view,
        name='plannedsession_teamedit_view'),
    re_path(r'^sessions/teamedit/(?P<id>\d+)/user/(?P<userid>\d+)/$',
        views.plannedsession_teamedit_view,
        name='plannedsession_teamedit_view'),
    re_path(r'^sessions/create/$',views.plannedsession_create_view,
        name='plannedsession_create_view'),
    re_path(r'^sessions/create/user/(?P<userid>\d+)/$',
        views.plannedsession_create_view,
        name='plannedsession_create_view'),
#    re_path(r'^sessions/create/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',
#        views.plannedsession_create_view,
#        name='plannedsession_create_view'),
#    re_path(r'^sessions/create/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',
#        views.plannedsession_create_view,
#        name='plannedsession_create_view'),
    re_path(r'^sessions/multiclone/$',views.plannedsession_multiclone_view,name='plannedsession_multiclone_view'),
    re_path(r'^sessions/multiclone/user/(?P<userid>\d+)/$',
        views.plannedsession_multiclone_view,
        name='plannedsession_multiclone_view'),
    re_path(r'^sessions/multicreate/$',views.plannedsession_multicreate_view,
        name='plannedsession_multicreate_view'),
    re_path(r'^sessions/multicreate/user/(?P<userid>\d+)/extra/(?P<extrasessions>\d+)/$',
        views.plannedsession_multicreate_view,
        name='plannedsession_multicreate_view'),
    re_path(r'^sessions/multicreate/user/(?P<userid>\d+)/$',
        views.plannedsession_multicreate_view,
        name='plannedsession_multicreate_view'),
    re_path(r'^sessions/(?P<id>\d+)/edit/$',views.plannedsession_edit_view),
    re_path(r'^sessions/(?P<id>\d+)/templateedit/',views.plannedsession_templateedit_view),
    re_path(r'^sessions/(?P<id>\d+)/maketemplate/$',views.plannedsession_totemplate_view),
    re_path(r'^sessions/(?P<id>\d+)/compare/$',
        views.plannedsession_compare_view,
        name='plannedsession_compare_view'),
    re_path(r'^sessions/(?P<id>\d+)/compare/user/(?P<userid>\d+)/$',
        views.plannedsession_compare_view,
        name='plannedsession_compare_view'),
    re_path(r'^sessions/(?P<id>\d+)/edit/user/(?P<userid>\d+)/$',views.plannedsession_edit_view),
    re_path(r'^sessions/(?P<id>\d+)/clone/user/(?P<userid>\d+)/$',views.plannedsession_clone_view),
    re_path(r'^sessions/(?P<id>\d+)/clone/team/$',views.plannedsession_teamclone_view),
    re_path(r'^sessions/(?P<id>\d+)/clone/$',views.plannedsession_clone_view),
    re_path(r'^sessions/(?P<psid>\d+)/detach/(?P<id>\b[0-9A-Fa-f]+\b)/user/(?P<userid>\d+)/$',views.plannedsession_detach_view),
    re_path(r'^sessions/(?P<psid>\d+)/detach/(?P<id>\b[0-9A-Fa-f]+\b)/$',views.plannedsession_detach_view),
    re_path(r'^sessions/(?P<id>\d+)/$',views.plannedsession_view,
        name='plannedsession_view'),
    re_path(r'^sessions/(?P<id>\d+)/user/(?P<userid>\d+)/$',views.plannedsession_view,
        name='plannedsession_view'),
    re_path(r'^sessions/(?P<pk>\d+)/deleteconfirm/$',login_required(
        views.PlannedSessionDelete.as_view())),
    re_path(r'^sessions/(?P<pk>\d+)/delete/$',login_required(
        views.PlannedSessionDelete.as_view()),
        name='plannedsession_delete_view'),
    re_path(r'^sessions/manage/session/(?P<initialsession>\d+)/$',
        views.plannedsessions_manage_view,
        name='plannedsessions_manage_view'),
    re_path(r'^sessions/manage/session/(?P<initialsession>\d+)/user/(?P<userid>\d+)/$',
        views.plannedsessions_manage_view,
        name='plannedsessions_manage_view'),
    re_path(r'^sessions/manage/?/$',
        views.plannedsessions_manage_view,
        name='plannedsessions_manage_view'),
    re_path(r'^sessions/manage/user/(?P<userid>\d+)/$',
        views.plannedsessions_manage_view,
        name='plannedsessions_manage_view'),
    re_path(r'^sessions/coach/$',views.plannedsessions_coach_view,
        name='plannedsessions_coach_view'),
    re_path(r'^sessions/coach/user/(?P<userid>\d+)/$',views.plannedsessions_coach_view,
        name='plannedsessions_coach_view'),
    re_path(r'^sessions/coach/sendcalendar/user/(?P<userid>\d+)/$',
            views.plannedsessions_coach_icsemail_view,
        name='plannedsessions_coach_icsemail_view'),
    re_path(r'^sessions/print/?/$',views.plannedsessions_print_view,
        name='plannedsessions_print_view'),
    re_path(r'^sessions/(?P<id>\d+)/comments/user/(?P<userid>\d+)/$',views.plannedsession_comment_view,
        name='plannedsession_comment_view'),
    re_path(r'^sessions/(?P<id>\d+)/comments/$',views.plannedsession_comment_view,
        name='plannedsession_comment_view'),
    re_path(r'^sessions/print/user/(?P<userid>\d+)/$',views.plannedsessions_print_view,
        name='plannedsessions_print_view'),
    re_path(r'^sessions/print/user/(?P<userid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.plannedsessions_print_view,
        name='plannedsessions_print_view'),
    re_path(r'^sessions/sendcalendar/$',views.plannedsessions_icsemail_view,
        name='plannedsessions_coach_icsemail_view'),
    re_path(r'^sessions/sendcalendar/user/(?P<userid>\d+)/$',views.plannedsessions_icsemail_view,
        name='plannedsessions_icsemail_view'),
    re_path(r'^sessions/$',views.plannedsessions_view,
        name='plannedsessions_view'),
    re_path(r'^sessions/user/(?P<userid>\d+)/$',views.plannedsessions_view,
        name='plannedsessions_view'),
#    re_path(r'^sessions/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',
#         views.plannedsessions_view,
#        name='plannedsessions_view'),
#    re_path(r'^sessions/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/user/(?P<userid>\d+)/$',
#         views.plannedsessions_view,
#        name='plannedsessions_view'),
    re_path(r'^courses/(?P<id>\d+)/edit/$',views.course_edit_view,
        name='course_edit_view'),
    re_path(r'^courses/(?P<id>\d+)/delete/$',views.course_delete_view),
    re_path(r'^courses/(?P<id>\d+)/downloadkml/$',views.course_kmldownload_view,
        name='course_kmldownload_view'),
    re_path(r'^courses/(?P<id>\d+)/replace/$',views.course_replace_view,
        name='course_replace_view'),
    re_path(r'^courses/(?P<id>\d+)/$',views.course_view,name='course_view'),
    re_path(r'^standards/(?P<id>\d+)/$',views.standard_view,name='standard_view'),
    re_path(r'^standards/(?P<id>\d+)/download/$',views.standards_download_view,
            name='standards_download_view'),
    re_path(r'^standards/(?P<id>\d+)/deactivate/$',views.standard_deactivate_view,
            name='standard_decativate_view'),
    re_path(r'^courses/(?P<id>\d+)/map/$',views.course_map_view,name='course_map_view'),
    # URLS to be created
    re_path(r'^help/$',TemplateView.as_view(template_name='help.html'), name='help'),
    re_path(r'^workout/api/upload/',views.workout_upload_api,name='workout_upload_api'),
    re_path(r'^access/share/$',views.createShareURL, name="sharedURL"),
    re_path(r'^access/(?P<key>\w+)/$', views.sharedPage, name="sharedPage"),
    re_path(r'^history/user/(?P<userid>\d+)/$',views.history_view,name="history_view"),
    re_path(r'^history/$',views.history_view,name="history_view"),
    re_path(r'^history/user/(?P<userid>\d+)/data/$',views.history_view_data,name="history_view_data"),
    re_path(r'^history/data/$',views.history_view_data,name="history_view_data"),
    ]

if settings.DEBUG:
    urlpatterns += [
	re_path(r'^c2listug/(?P<page>\d+)/$',views.c2listdebug_view),
	re_path(r'^c2listug/$',views.c2listdebug_view),
	]

#urlpatterns = format_suffix_patterns(urlpatterns)
