# Path: adminfiles/views.py
# def download(request):
#     '''Saves image from URL and returns ID for use with AJAX script'''
#     f = FileUpload()
#     f.title = request.GET['title'] or 'untitled'
#     f.description = request.GET['description']
#     url = urllib.unquote(request.GET['photo'])
#     file_content = urllib.urlopen(url).read()
#     file_name = url.split('/')[-1]
#     f.save_upload_file(file_name, file_content)
#     f.save()
#     return HttpResponse('%s' % (f.id))
# 
# def get_enabled_browsers():
#     """
#     Check the ADMINFILES_BROWSER_VIEWS setting and return a list of
#     instantiated browser views that have the necessary
#     dependencies/configuration to run.
# 
#     """
#     global _enabled_browsers_cache
#     if _enabled_browsers_cache is not None:
#         return _enabled_browsers_cache
#     enabled = []
#     for browser_path in settings.ADMINFILES_BROWSER_VIEWS:
#         try:
#             view_class = import_browser(browser_path)
#         except ImportError:
#             continue
#         if not issubclass(view_class, BaseView):
#             continue
#         browser = view_class
#         try:
#             browser.check()
#         except DisableView:
#             continue
#         enabled.append(browser)
#     _enabled_browsers_cache = enabled
#     return enabled


from django.conf.urls import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from adminfiles.views import download, get_enabled_browsers



urlpatterns = patterns('',
    url(r'download/$', staff_member_required(download),
        name="adminfiles_download")
)

for browser in get_enabled_browsers():
    slug = browser.slug()
    urlpatterns += patterns('',
        url('%s/$' % slug, browser.as_view(),

# Path: adminfiles/views.py
# def download(request):
#     '''Saves image from URL and returns ID for use with AJAX script'''
#     f = FileUpload()
#     f.title = request.GET['title'] or 'untitled'
#     f.description = request.GET['description']
#     url = urllib.unquote(request.GET['photo'])
#     file_content = urllib.urlopen(url).read()
#     file_name = url.split('/')[-1]
#     f.save_upload_file(file_name, file_content)
#     f.save()
#     return HttpResponse('%s' % (f.id))
# 
# def get_enabled_browsers():
#     """
#     Check the ADMINFILES_BROWSER_VIEWS setting and return a list of
#     instantiated browser views that have the necessary
#     dependencies/configuration to run.
# 
#     """
#     global _enabled_browsers_cache
#     if _enabled_browsers_cache is not None:
#         return _enabled_browsers_cache
#     enabled = []
#     for browser_path in settings.ADMINFILES_BROWSER_VIEWS:
#         try:
#             view_class = import_browser(browser_path)
#         except ImportError:
#             continue
#         if not issubclass(view_class, BaseView):
#             continue
#         browser = view_class
#         try:
#             browser.check()
#         except DisableView:
#             continue
#         enabled.append(browser)
#     _enabled_browsers_cache = enabled
#     return enabled


# Path: adminfiles/urls.py
from django.conf.urls import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from adminfiles.views import download, get_enabled_browsers




urlpatterns = patterns('',
    url(r'download/$', staff_member_required(download),
        name="adminfiles_download")
)

for browser in get_enabled_browsers():
    slug = browser.slug()
    urlpatterns += patterns('',
        url('%s/$' % slug, browser.as_view(),

            name='adminfiles_%s' % slug))