from django.conf import settings
from django.conf.urls import url, include
from django.contrib.auth.models import User

from models import Workout,Rower,StrokeData,FavoriteChart

from rest_framework import routers, serializers, viewsets,permissions
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework.permissions import *
from . import views
from django.contrib.auth import views as auth_views
from django.views.generic.base import TemplateView
from django.conf.urls import (
    handler400, handler403, handler404, handler500,
    )

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')


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

from oauth2_provider.views import base

urlpatterns = [
#    url(r'^password_change/$',auth_views.password_change),
#    url(r'^password_change_done/$',auth_views.password_change_done),
#    url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
    url(r'^o/authorize/$', base.AuthorizationView.as_view(), name="authorize"),
    url(r'^o/token/$', base.TokenView.as_view(), name="token"),
    url(r'^', include(router.urls)),
    url(r'^api-docs$', views.schema_view),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^api/workouts/(?P<id>\d+)/strokedata$',views.strokedatajson),
    url(r'^500v/$',views.error500_view),
    url(r'^502/$', TemplateView.as_view(template_name='502.html'),name='502'),
    url(r'^500/$', TemplateView.as_view(template_name='500.html'),name='500'),
    url(r'^404/$', TemplateView.as_view(template_name='404.html'),name='404'),
    url(r'^400/$', TemplateView.as_view(template_name='400.html'),name='400'),
    url(r'^403/$', TemplateView.as_view(template_name='403.html'),name='403'),
    url(r'^imports/$', TemplateView.as_view(template_name='imports.html'), name='imports'),
    url(r'^agegroupcp/(?P<age>\d+)$',views.agegroupcpview),
    url(r'^agegroupcp/(?P<age>\d+)/(?P<normalize>\d+)$',views.agegroupcpview),
    url(r'^ajax_agegroup/(?P<age>\d+)/(?P<weightcategory>\w+.*)/(?P<sex>\w+.*)/(?P<userid>\d+)$',
        views.ajax_agegrouprecords),
    url(r'^updatefitness/(?P<mode>\w+.*)/(?P<days>\d+)$',views.fitness_metric_view),
    url(r'^updatefitness/(?P<mode>\w+.*)$',views.fitness_metric_view),
    url(r'^updatefitness$',views.fitness_metric_view),
    url(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)/(?P<distance>\d+)m$',
        views.agegrouprecordview),
    url(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)/(?P<duration>\d+)min$',
        views.agegrouprecordview),
    url(r'^agegrouprecords/(?P<sex>\w+.*)/(?P<weightcategory>\w+.*)$',
        views.agegrouprecordview),
    url(r'^list-workouts/ranking$',views.workouts_view,{'rankingonly':True}),
    url(r'^list-workouts/team/(?P<teamid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
    url(r'^list-workouts/team/(?P<teamid>\d+)/$',views.workouts_view),
    url(r'^(?P<rowerid>\d+)/list-workouts/$',views.workouts_view),
    url(r'^(?P<rowerid>\d+)/list-workouts/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
    url(r'^u/(?P<userid>\d+)/list-workouts/$',views.workouts_view),
    url(r'^u/(?P<userid>\d+)/list-workouts/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
    url(r'^list-workouts/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
    url(r'^list-workouts/$',views.workouts_view),
    url(r'^addmanual/$',views.addmanual_view),
    url(r'^team-compare-select/team/(?P<teamid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.team_comparison_select),
    url(r'^team-compare-select/team/(?P<teamid>\d+)/$',views.team_comparison_select),
    url(r'^team-compare-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.team_comparison_select),
    url(r'^team-compare-select/$',views.team_comparison_select),
    url(r'^workouts-join-select/team/(?P<teamid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_join_select),
    url(r'^workouts-join$',views.workouts_join_view),
    url(r'^workouts-join-select/team/(?P<teamid>\d+)/$',views.workouts_join_select),
    url(r'^workouts-join-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_join_select),
    url(r'^workouts-join-select/$',views.workouts_join_select),
    url(r'^user-boxplot-select/user/(?P<userid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_boxplot_select),
    url(r'^user-boxplot-select/user/(?P<userid>\d+)/$',views.user_boxplot_select),
    url(r'^user-boxplot-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_boxplot_select),
    url(r'^user-boxplot-select/$',views.user_boxplot_select),
    url(r'^user-multiflex-select/user/(?P<userid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_multiflex_select),
    url(r'^user-multiflex-select/user/(?P<userid>\d+)/$',views.user_multiflex_select),
    url(r'^user-multiflex-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_multiflex_select),
    url(r'^user-multiflex-select/$',views.user_multiflex_select),
    url(r'^list-jobs/$',views.session_jobs_view),
    url(r'^jobs-status/$',views.session_jobs_status),
    url(r'^job-kill/(?P<id>.*)$',views.kill_async_job),
    url(r'^test-job/(?P<aantal>\d+)$',views.test_job_view),
    url(r'^test-job2/(?P<aantal>\d+)$',views.test_job_view2),
    url(r'^record-progress/(?P<value>\d+)/(?P<id>.*)$',views.post_progress),
    url(r'^record-progress/(?P<id>.*)$',views.post_progress),
    url(r'^record-progress$',views.post_progress),
    url(r'^list-graphs/$',views.graphs_view),
    url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
    url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
    url(r'^ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
    url(r'^ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
    url(r'^ote-bests/$',views.rankings_view),
    url(r'^(?P<theuser>\d+)/ote-bests/$',views.rankings_view),
    url(r'^(?P<theuser>\d+)/ote-bests2/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view2),
    url(r'^(?P<theuser>\d+)/ote-bests2/(?P<deltadays>\d+)$',views.rankings_view2),
    url(r'^ote-bests2/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view2),
    url(r'^ote-bests2/(?P<deltadays>\d+)$',views.rankings_view2),
    url(r'^ote-bests2/$',views.rankings_view2),
    url(r'^(?P<theuser>\d+)/ote-bests2/$',views.rankings_view2),
    url(r'^(?P<theuser>\d+)/otw-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.otwrankings_view),
    url(r'^(?P<theuser>\d+)/otw-bests/(?P<deltadays>\d+)$',views.otwrankings_view),
    url(r'^otw-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.otwrankings_view),
    url(r'^otw-bests/(?P<deltadays>\d+)$',views.otwrankings_view),
    url(r'^otw-bests/$',views.otwrankings_view),
    url(r'^(?P<theuser>\d+)/ote-ranking/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.oterankings_view),
    url(r'^(?P<theuser>\d+)/ote-ranking/(?P<deltadays>\d+)$',views.oterankings_view),
    url(r'^ote-ranking/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.oterankings_view),
    url(r'^ote-ranking/(?P<deltadays>\d+)$',views.oterankings_view),
    url(r'^ote-ranking/$',views.oterankings_view),
    url(r'^(?P<theuser>\d+)/ote-ranking/$',views.oterankings_view),
    url(r'^(?P<theuser>\d+)/flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cum_flex),
    url(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cum_flex),
    url(r'^flexall/(?P<xparam>\w+.*)/(?P<yparam1>\w+.*)/(?P<yparam2>\w+.*)$',views.cum_flex),
    url(r'^flexall/$',views.cum_flex),

    url(r'^flexalldata/$',views.cum_flex_data),

    url(r'^histo/u/(?P<theuser>\d+)$',views.histo),
    url(r'^flexall/u/(?P<theuser>\d+)$',views.cum_flex),
    url(r'^(?P<theuser>\d+)/histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
    url(r'^(?P<theuser>\d+)/histo/(?P<deltadays>\d+)$',views.histo),
    url(r'^histo/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.histo),
    url(r'^histo/(?P<deltadays>\d+)$',views.histo),
    url(r'^histo/$',views.histo),
    url(r'^cumstats/u/(?P<theuser>\d+)$',views.cumstats),
    url(r'^cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)/p/(?P<plotfield>\w+.*)$',views.cumstats),
    url(r'^(?P<theuser>\d+)/cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)/p/(?P<plotfield>\w+.*)$',views.cumstats),
    url(r'^(?P<theuser>\d+)/cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cumstats),
    url(r'^(?P<theuser>\d+)/cumstats/(?P<deltadays>\d+)$',views.cumstats),
    url(r'^cumstats/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.cumstats),
    url(r'^cumstats/(?P<deltadays>\d+)$',views.cumstats),
    url(r'^cumstats/$',views.cumstats),
    url(r'^histo-all/$',views.histo_all),
    url(r'^(?P<theuser>\d+)/histo-all/$',views.histo_all),
    url(r'^graph/(?P<id>\d+)/$',views.graph_show_view),
    url(r'^graph/(?P<id>\d+)/deleteconfirm$',views.graph_delete_confirm_view),
    url(r'^graph/(?P<id>\d+)/delete$',views.graph_delete_view),
    url(r'^workout/(?P<id>\d+)/get-thumbnails$',views.get_thumbnails),
    url(r'^workout/(?P<id>\d+)/toggle-ranking$',views.workout_toggle_ranking),
    url(r'^workout/(?P<id>\d+)/get-testscript$',views.get_testscript),
    url(r'^workout/upload/team/$',views.team_workout_upload_view),
    url(r'^workout/upload/$',views.workout_upload_view,name='workout_upload_view'),
    url(r'^workout/(?P<id>\d+)/histo$',views.workout_histo_view),
    url(r'^workout/(?P<id>\d+)/task$',views.workout_test_task_view),
    url(r'^workout/(?P<id>\d+)/forcecurve$',views.workout_forcecurve_view),
    url(r'^workout/(?P<id>\d+)/unsubscribe$',views.workout_unsubscribe_view),
    url(r'^workout/(?P<id>\d+)/export$',views.workout_export_view),
    url(r'^workout/(?P<id>\d+)/comment$',views.workout_comment_view),
    url(r'^workout/(?P<id>\d+)/emailtcx$',views.workout_tcxemail_view),
    url(r'^workout/(?P<id>\d+)/emailgpx$',views.workout_gpxemail_view),
    url(r'^workout/(?P<id>\d+)/emailcsv$',views.workout_csvemail_view),
    url(r'^workout/(?P<id>\d+)/csvtoadmin$',views.workout_csvtoadmin_view),
    url(r'^workout/compare/(?P<id>\d+)/$',views.workout_comparison_list),
    url(r'^workout/compare2/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>\w+.*)/$',views.workout_comparison_view),
    url(r'^workout/compare/(?P<id>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\w+.*)$',views.workout_comparison_list),
    url(r'^workout/(?P<id>\d+)/edit$',views.workout_edit_view,
        name='workout_edit_view'),
    url(r'^workout/(?P<id>\d+)/navionics$',views.workout_edit_view_navionics),
    url(r'^workout/(?P<id>\d+)/map$',views.workout_map_view),
    url(r'^workout/(?P<id>\d+)/setprivate$',views.workout_setprivate_view),
    url(r'^workout/(?P<id>\d+)/updatecp$',views.workout_update_cp_view),
    url(r'^workout/(?P<id>\d+)/makepublic$',views.workout_makepublic_view),
    url(r'^workout/(?P<id>\d+)/geeky$',views.workout_geeky_view),
    url(r'^workout/(?P<id>\d+)/advanced$',views.workout_advanced_view),
    url(r'^workout/(?P<id>\d+)/instroke/(?P<metric>\w+.*)$',views.instroke_chart),
    url(r'^workout/(?P<id>\d+)/instroke$',views.instroke_view),
    url(r'^workout/(?P<id>\d+)/stats$',views.workout_stats_view),
    url(r'^workout/(?P<id>\d+)/otwsetpower$',views.workout_otwsetpower_view),
    url(r'^workout/(?P<id>\d+)/interactiveotwplot$',views.workout_otwpowerplot_view),
    url(r'^workout/(?P<id>\d+)/wind$',views.workout_wind_view),
    url(r'^workout/(?P<id>\d+)/image$',views.workout_uploadimage_view),
    url(r'^workout/(?P<id>\d+)/darkskywind$',views.workout_downloadwind_view),
    url(r'^workout/(?P<id>\d+)/metar/(?P<airportcode>\w+)$',views.workout_downloadmetar_view),
    url(r'^workout/(?P<id>\d+)/stream$',views.workout_stream_view),
    url(r'^workout/(?P<id>\d+)/crewnerdsummary$',views.workout_crewnerd_summary_view),
    url(r'^workout/(?P<id>\d+)/editintervals$',views.workout_summary_edit_view),
    url(r'^workout/(?P<id>\d+)/restore$',views.workout_summary_restore_view),
    url(r'^workout/(?P<id>\d+)/split$',views.workout_split_view),
    url(r'^workout/(?P<id>\d+)/interactiveplot$',views.workout_biginteractive_view),
    url(r'^workout/(?P<id>\d+)/view$',views.workout_view),
    url(r'^workout/(?P<id>\d+)$',views.workout_view),
    url(r'^workout/fusion/(?P<id1>\d+)/(?P<id2>\d+)$',views.workout_fusion_view),
    url(r'^workout/fusion/(?P<id>\d+)/$',views.workout_fusion_list),
    url(r'^workout/fusion/(?P<id>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\w+.*)$',views.workout_fusion_list),

    url(r'^physics$',TemplateView.as_view(template_name='physics.html'),name='physics'),
    url(r'^partners$',TemplateView.as_view(template_name='partners.html'),name='partners'),
    url(r'^workout/(?P<id>\d+)/$',views.workout_view),
    # keeping the old URLs for retrofit
    url(r'^workout/(?P<id>\d+)/addtimeplot$',
        views.workout_add_chart_view,
        {'plotnr':'1'}),
    url(r'^workout/(?P<id>\d+)/adddistanceplot$',
        views.workout_add_chart_view,
        {'plotnr':'2'}),
    url(r'^workout/(?P<id>\d+)/addpiechart$',
        views.workout_add_chart_view,
        {'plotnr':'3'}),
    url(r'^workout/(?P<id>\d+)/adddistanceplot2$',
        views.workout_add_chart_view,
        {'plotnr':'7'}),
    url(r'^workout/(?P<id>\d+)/addtimeplot2$',
        views.workout_add_chart_view,
        {'plotnr':'8'}),
    url(r'^workout/(?P<id>\d+)/addotwpowerplot$',
        views.workout_add_chart_view,
        {'plotnr':'9'}),
    url(r'^workout/(?P<id>\d+)/addpowerpiechart$',
        views.workout_add_chart_view,
        {'plotnr':'13'}),
    # addstatic is the new URL -> need to update in templates
    url(r'^workout/(?P<id>\d+)/addstatic/(?P<plotnr>\d+)$',
        views.workout_add_chart_view),
    url(r'^workout/(?P<id>\d+)/addstatic$',views.workout_add_chart_view),
    url(r'^workout/(?P<id>\d+)/delete$',views.workout_delete_view),
    url(r'^workout/(?P<id>\d+)/smoothenpace$',views.workout_smoothenpace_view),
    url(r'^workout/(?P<id>\d+)/undosmoothenpace$',views.workout_undo_smoothenpace_view),
    url(r'^workout/c2import/$',views.workout_c2import_view),
    url(r'^workout/c2list/$',views.workout_c2import_view),
    url(r'^workout/c2list/(?P<page>\d+)$',views.workout_c2import_view),
    url(r'^workout/stravaimport/$',views.workout_stravaimport_view),
    url(r'^workout/c2import/(?P<c2id>\d+)/$',views.workout_getc2workout_view),
    url(r'^workout/c2import/all/$',views.workout_getc2workout_all),
    url(r'^workout/c2import/all/(?P<page>\d+)$',views.workout_getc2workout_all),
    url(r'^workout/stravaimport/(?P<stravaid>\d+)/$',views.workout_getstravaworkout_view),
    url(r'^workout/stravaimport/all/$',views.workout_getstravaworkout_all),
    url(r'^workout/sporttracksimport/$',views.workout_sporttracksimport_view),
    url(r'^workout/sporttracksimport/(?P<sporttracksid>\d+)/$',views.workout_getsporttracksworkout_view),
    url(r'^workout/sporttracksimport/all/$',views.workout_getsporttracksworkout_all),
    url(r'^workout/runkeeperimport/$',views.workout_runkeeperimport_view),
    url(r'^workout/runkeeperimport/(?P<runkeeperid>\d+)/$',views.workout_getrunkeeperworkout_view),
    url(r'^workout/underarmourimport/$',views.workout_underarmourimport_view),
    url(r'^workout/underarmourimport/(?P<underarmourid>\d+)/$',views.workout_getunderarmourworkout_view),
    url(r'^workout/(?P<id>\d+)/deleteconfirm$',views.workout_delete_confirm_view),
    url(r'^workout/(?P<id>\d+)/c2uploadw/$',views.workout_c2_upload_view),
    url(r'^workout/(?P<id>\d+)/stravauploadw/$',views.workout_strava_upload_view),
    url(r'^workout/(?P<id>\d+)/recalcsummary/$',views.workout_recalcsummary_view),
    url(r'^workout/(?P<id>\d+)/sporttracksuploadw/$',views.workout_sporttracks_upload_view),
    url(r'^workout/(?P<id>\d+)/runkeeperuploadw/$',views.workout_runkeeper_upload_view),
    url(r'^workout/(?P<id>\d+)/underarmouruploadw/$',views.workout_underarmour_upload_view),
    url(r'^workout/(?P<id>\d+)/tpuploadw/$',views.workout_tp_upload_view),
    url(r'^multi-compare$',views.multi_compare_view),
    url(r'^user-boxplot/(?P<userid>\d+)$',views.boxplot_view),
    url(r'^user-boxplot/$',views.boxplot_view),
    url(r'^user-boxplot$',views.boxplot_view),
    url(r'^user-boxplot-data$',views.boxplot_view_data),
    url(r'^user-multiflex/(?P<userid>\d+)$',views.multiflex_view),
    url(r'^user-multiflex/$',views.multiflex_view),
    url(r'^user-multiflex$',views.multiflex_view),
    url(r'^user-multiflex-data$',views.multiflex_data),
    url(r'^me/teams/$',views.rower_teams_view),
    url(r'^me/calcdps/$',views.rower_calcdps_view),
    url(r'^me/exportsettings/$',views.rower_exportsettings_view),
    url(r'^team/(?P<id>\d+)/$',views.team_view),
    url(r'^team/(?P<id>\d+)/memberstats$',views.team_members_stats_view),
    url(r'^team/(?P<id>\d+)/edit$',views.team_edit_view),
    url(r'^team/(?P<id>\d+)/leaveconfirm/$',views.team_leaveconfirm_view),
    url(r'^team/(?P<id>\d+)/leave/$',views.team_leave_view),
    url(r'^team/(?P<id>\d+)/deleteconfirm/$',views.team_deleteconfirm_view),
    url(r'^team/(?P<teamid>\d+)/requestmembership/(?P<userid>\d+)$',views.team_requestmembership_view),
    url(r'^team/(?P<id>\d+)/delete/$',views.team_delete_view),
    url(r'^team/create/$',views.team_create_view),
    url(r'^me/team/(?P<teamid>\d+)/drop/(?P<userid>\d+)$',views.manager_member_drop_view),
    url(r'^me/invitation/(?P<id>\d+)/reject$',views.invitation_reject_view),
    url(r'^me/invitation/(?P<id>\d+)/revoke$',views.invitation_revoke_view),
    url(r'^me/invitation/$',views.rower_invitations_view),
    url(r'^me/invitation/(\w+.*)/$',views.rower_invitations_view),
    url(r'^me/request/(?P<id>\d+)/revoke',views.request_revoke_view),
    url(r'^me/request/(?P<id>\d+)/reject',views.request_reject_view),
    url(r'^me/request/(\w+.*)/$',views.manager_requests_view),
    url(r'^me/request/$',views.manager_requests_view),
    url(r'^me/edit/$',views.rower_edit_view),
    url(r'^me/edit/(.+.*)/$',views.rower_edit_view),
    url(r'^me/c2authorize/$',views.rower_c2_authorize),
    url(r'^me/revokeapp/(?P<id>\d+)$',views.rower_revokeapp_view),
    url(r'^me/stravaauthorize/$',views.rower_strava_authorize),
    url(r'^me/sporttracksauthorize/$',views.rower_sporttracks_authorize),
    url(r'^me/underarmourauthorize/$',views.rower_underarmour_authorize),
    url(r'^me/tpauthorize/$',views.rower_tp_authorize),
    url(r'^me/runkeeperauthorize/$',views.rower_runkeeper_authorize),
    url(r'^me/sporttracksrefresh/$',views.rower_sporttracks_token_refresh),
    url(r'^me/underarmourrefresh/$',views.rower_underarmour_token_refresh),
    url(r'^me/tprefresh/$',views.rower_tp_token_refresh),
    url(r'^me/c2refresh/$',views.rower_c2_token_refresh),
    url(r'^me/favoritecharts/$',views.rower_favoritecharts_view),
    url(r'^me/workflowconfig$',views.workout_workflow_config_view),
    url(r'^me/workflowconfig2$',views.workout_workflow_config2_view),
    url(r'^me/workflowdefault$',views.workflow_default_view),
    url(r'^email/send/$', views.sendmail),
    url(r'^email/thankyou/$', TemplateView.as_view(template_name='thankyou.html'), name='thankyou'),
    url(r'^email/$', TemplateView.as_view(template_name='email.html'), name='email'),
    url(r'^about', TemplateView.as_view(template_name='about_us.html'),name='about'),
    url(r'^brochure$',TemplateView.as_view(template_name='brochure.html'),
        name='brochure'),
    url(r'^developers', TemplateView.as_view(template_name='developers.html'),name='about'),
    url(r'^compatibility', TemplateView.as_view(template_name='compatibility.html'),name='about'),
    url(r'^videos', TemplateView.as_view(template_name='videos.html'),name='videos'),
    url(r'^analysis', TemplateView.as_view(template_name='analysis.html'),name='analysis'),
    url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'),
    url(r'^starttrial$',views.start_trial_view),
    url(r'^planmembership', TemplateView.as_view(template_name='planmembership.html'),name='planmembership'),
    url(r'^paypaltest', TemplateView.as_view(template_name='paypaltest.html'),name='paypaltest'),
    url(r'^legal', TemplateView.as_view(template_name='legal.html'),name='legal'),
    url(r'^register$',views.rower_register_view),
    url(r'^register/thankyou/$', TemplateView.as_view(template_name='registerthankyou.html'), name='registerthankyou'),
    url(r'^workout/(?P<id>\d+)/workflow$',views.workout_workflow_view,
        name='workout_workflow_view'),
    url(r'^workout/(?P<id>\d+)/flexchart/(?P<xparam>\w+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)/(?P<plottype>\w+)/$',views.workout_flexchart3_view),
    url(r'^workout/(?P<id>\d+)/flexchart/(?P<xparam>\w+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)/(?P<plottype>\w+.*)$',views.workout_flexchart3_view),
    url(r'^workout/(?P<id>\d+)/flexchart/(?P<xparam>\w+.*)/(?P<yparam1>[\w\ ]+.*)/(?P<yparam2>[\w\ ]+.*)$',views.workout_flexchart3_view),
    url(r'^workout/(?P<id>\d+)/flexchart$',views.workout_flexchart3_view),
    url(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/(?P<plottype>[\w\ ]+.*)$',views.workout_comparison_view2),
    url(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/$',views.workout_comparison_view2),
    url(r'^test\_callback',views.rower_process_testcallback),
    url(r'^workout/(?P<id>\d+)/test\_strokedata$',views.strokedataform),

    url(r'^sessions/teamcreate$',views.plannedsession_teamcreate_view),
    url(r'^sessions/teamcreate/(?P<timeperiod>[\w\ ]+.*)$',
        views.plannedsession_teamcreate_view),
    url(r'^sessions/teamcreate/(?P<timeperiod>[\w\ ]+.*)/team/(?P<teamid>\d+)$',
        views.plannedsession_teamcreate_view),
    url(r'^sessions/teamcreate/team/(?P<teamid>\d+)$',
        views.plannedsession_teamcreate_view),

    url(r'^sessions/teamedit/(?P<sessionid>\d+)$',views.plannedsession_teamedit_view),
    url(r'^sessions/teamedit/(?P<sessionid>\d+)/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_teamedit_view),

    url(r'^sessions/create$',views.plannedsession_create_view),
    url(r'^sessions/create/rower/(?P<rowerid>\d+)$',
        views.plannedsession_create_view),
    url(
        r'^sessions/create/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',
        views.plannedsession_create_view),
    url(r'^sessions/create/(?P<timeperiod>[\w\ ]+.*)$',
        views.plannedsession_create_view),

    url(r'^sessions/(?P<id>\d+)/edit$',views.plannedsession_edit_view),
    url(r'^sessions/(?P<id>\d+)/edit/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_edit_view),
    url(r'^sessions/(?P<id>\d+)/edit/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_edit_view),

    url(r'^sessions/(?P<id>\d+)/clone$',views.plannedsession_clone_view),
    url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_clone_view),
    url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_clone_view),

    url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view),
    url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view),
    url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view),
    url(r'^sessions/manage/session/(?P<initialsession>\d+)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)/session/(?P<initialsession>\d+)$',
        views.plannedsessions_manage_view),

    
    url(r'^sessions/manage/?$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/rower/(?P<rowerid>\d+)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)$',
        views.plannedsessions_manage_view),
    url(r'^sessions/?$',views.plannedsessions_view),
    url(r'^sessions/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
    url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
    url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsessions_view),
    ]

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

#urlpatterns = format_suffix_patterns(urlpatterns)
