import logging

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from google.appengine.ext import ereporter

import views
import search

ereporter.register_logger()
search.autodiscover()

urlpatterns = patterns('',
    (r'^/?$', views.home_handler, {}, "home"),

    (r'^content/(?P<template_id>[^/]+)/?$', views.content_template, {}, "content_template"),
    (r'^content/?$', views.content_handler, {}, "content"),

    (r'^image/(?P<pk>\d+)(\.jpg)?/?$', views.image_download_handler, {}, "download_image"),
    (r'^thumbnail/(?P<pk>.+)/?$', views.thumbnail_download_handler, {}, "download_thumbnail"),
    (r'^preview/(?P<pk>.+)/?$', views.preview_download_handler, {}, "download_preview"),

    # image handling methods
    (r'^api/image/upload/success/(?P<pk>.+)/?$', views.upload_success_handler, {}, "upload_success_handler"),
    (r'^api/image/upload/error/?$', views.upload_error_handler, {}, "upload_error_handler"),
    (r'^api/image/upload/?$', views.image_upload_handler, {}, "image_upload_handler"),
    (r'^api/image/(?P<pk>[^/]+)/public_update/?$', views.image_public_update_handler, {}, "image_public_update_handler"),
    (r'^api/image/(?P<pk>[^/]+)/?$', views.image_handler, {}, "image_handler"),
    (r'^api/images/?$', views.list_images, {}, "list_images"),

    # region handling methods
    (r'^api/regions/?$', views.list_regions, {}, "list_regions"),
    (r'^api/region/(?P<pk>[^/]+)/?$', views.region_handler, {}, "region_handler"),

    # user methods
    (r'^api/current_user/?$', views.current_user, {}, "current_user"),

    #kickstarting the js object
    (r'^api/init/chrono$', views.init_chrono_dataset, {}, "api_init_chrono_dataset"),
    (r'^api/init/map$', views.init_map_dataset, {}, "api_init_map_dataset"),
    (r'^api/init/minimap$', views.init_minimap_dataset, {}, "api_init_minimap_dataset"),
    (r'^api/init$', views.init_dataset, {}, "api_init_dataset"),
    (r'^api/version$', views.api_version, {}, "api_version"),
    (r'^api/get_user_count$', views.get_user_count, {}, "api_get_user_count"),
    
    #redirecting for shares
    (r'^api/redirect/(?P<token>[^/]+)/?$', views.redirect_handler, {}, "api_redirect"),
    (r'^facebook/share/(?P<image_id>[^/]+)/?$', views.facebook_share_handler, {}, "facebook_share_handler"),
)
