Scott Baker | bb7e84f | 2014-06-16 23:08:43 -0700 | [diff] [blame^] | 1 | #from home import DashboardWelcomeView, DashboardDynamicView |
| 2 | #from tenant import TenantCreateSlice, TenantUpdateSlice, TenantDeleteSliceView, TenantAddOrRemoveSliverView, TenantPickSitesView, TenantViewData |
| 3 | #from simulator import SimulatorView |
| 4 | #from cdn import DashboardSummaryAjaxView, DashboardAddOrRemoveSliverView, DashboardAjaxView |
| 5 | #from analytics import DashboardAnalyticsAjaxView |
| 6 | #from customize import DashboardCustomize |
| 7 | #from interactions import DashboardSliceInteractions |
| 8 | #from test import DashboardUserSiteView |
Scott Baker | c7325a4 | 2014-05-30 16:06:46 -0700 | [diff] [blame] | 9 | |
Scott Baker | bb7e84f | 2014-06-16 23:08:43 -0700 | [diff] [blame^] | 10 | from django.views.generic import View |
| 11 | from django.conf.urls import patterns, url |
| 12 | import os, sys |
| 13 | import inspect |
| 14 | import importlib |
| 15 | |
| 16 | # Find all modules in the current directory that have descendents of the View |
| 17 | # object, and add them as globals to this module. Also, build up a list of urls |
| 18 | # based on the "url" field of the view classes. |
| 19 | |
| 20 | sys_path_save = sys.path |
| 21 | try: |
| 22 | # __import__() and importlib.import_module() both import modules from |
| 23 | # sys.path. So we make sure that the path where we can find the views is |
| 24 | # the first thing in sys.path. |
| 25 | view_dir = os.path.dirname(os.path.abspath(__file__)) |
| 26 | sys.path = [view_dir] + sys.path |
| 27 | view_urls = [] |
| 28 | for fn in os.listdir(view_dir): |
| 29 | pathname = os.path.join(view_dir,fn) |
| 30 | if os.path.isfile(pathname) and fn.endswith(".py") and (fn!="__init__.py"): |
| 31 | #module = imp.load_source(fn[:-3],pathname) |
| 32 | #module = importlib.import_module(fn[:-3]) |
| 33 | module = __import__(fn[:-3]) |
| 34 | for classname in dir(module): |
| 35 | c = getattr(module, classname, None) |
| 36 | |
| 37 | if inspect.isclass(c) and issubclass(c, View) and (classname not in globals()): |
| 38 | globals()[classname] = c |
| 39 | |
| 40 | view_url = getattr(c, "url", None) |
| 41 | if view_url: |
| 42 | view_urls.append( (view_url, classname, c) ) |
| 43 | finally: |
| 44 | sys.path = sys_path_save |