#!/usr/bin/env python

"""jmoiron.net's master urls.py

Implicit in my website are the fact that the following flatpages will exist
and that the FlatpageFallbackMiddleware is installed and working properly:
    /about/ -- the classic 'about' page
    /code/ -- my overview of code
    /docs/ -- my overview of various documentation
    /gallery/ *** temporary static page for gallery app ***

If FlatPage objects are not showing up, you might want to check the SITE_ID
in settings.py/local_settings.py.

The following redirects have to be made to keep old links working:
    /rant/?id=#
    /links/
    /images/...
"""

from django.contrib import admin
from django.conf import settings
from django.conf.urls.defaults import include, handler500, handler404

from saudade.common.shortcuts import generics
from saudade.blog.feeds import BlogFeed
from saudade.comments.feeds import CommentFeed, CommentLogFeed
import dselector

feeds = {
    'blog' : BlogFeed,
    'comments' : CommentFeed,
    'comments/log' : CommentLogFeed,
}

admin.autodiscover()

images = '/media/legacy/images/'
media = lambda x: '/media/' + x


parser = dselector.Parser()
urlpatterns = parser.patterns('',
    (r'rss/{url:any}/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
    (r'admin/(.*)!', admin.site.root),
    (r'login/!', 'saudade.common.views.login_view'),
    (r'logout/!', 'saudade.common.views.logout_view'),
    (r'tags/!', include('saudade.tagging.urls')),
    (r'blog/!', include('saudade.blog.urls')),
    (r'todo/!', include('saudade.todo.urls')),
    (r'womfa/!', include('saudade.womfa.urls')),
    (r'linkpost/!', include('saudade.linkpost.urls')),
    (r'comments/!', include('saudade.comments.urls')),
    (r'', 'saudade.stream.views.stream'),
    #(r'', generics.redirect, {'url': '/blog/'}),
    (r'links?/!', generics.redirect, {'url': '/about/'}),
    (r'rant/', 'saudade.blog.views.legacy_blog'),
    (r'images/', generics.redirect, {'url': images}),
    (r'images/{arg:any}/', generics.redirect, {'url': images + '%(arg)s'}),
    (r'misc/argot-demo/!', include('argotdemo.urls')),
    # static stuff
    (r'robots.txt', generics.redirect, {'url': media('robots.txt')}),
    (r'favicon.ico', generics.redirect, {'url': media('favicon.ico')}),
    (r'favicon.gif', generics.redirect, {'url': media('favicon.gif')}),
    (r'favicon.png', generics.redirect, {'url': media('favicon.png')}),
)

if settings.DEBUG:
    urlpatterns += parser.patterns('',
        (r'media/{path:any}', 'django.views.static.serve', {'document_root': './media/'}),
    )


