#==============================================================================
# settings.py
#==============================================================================

import os

PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
PROJECT_NAME = os.path.basename(PROJECT_ROOT)


#==============================================================================
# urls.py
#==============================================================================

urlpatterns = patterns('',
    (r'^.+/', 'project.lib.views.default'), # '^.+/' preserves Django's APPEND_SLASH feature
)


#==============================================================================
# project.lib.views.py
#==============================================================================

from django.conf import settings
from django.http import Http404

def default(request):
    split_url = request.path.strip('/').split('/')
    
    project_name    = settings.PROJECT_NAME
    app_name        = split_url[0]
    view_name       = split_url[1]
    
    import_string = '%s.%s.views' % (project_name,app_name)
  
    try:
        module  = __import__(import_string)
        app     = getattr(module, app_name)
        views   = getattr(app, 'views')
        
        return getattr(views, view_name)(request)
    except:
        raise Http404