Commit 656f6d60 authored by matjaz's avatar matjaz
Browse files

An approach to achieve full package independence.

The only thing person has to do to add package is to add it to mothra/settings/INSTALLED_APPS.
following files are automatically added with definitions from equal naming modules from packages.
- library.py
- visualization_views.py
- interaction_views.py
- urls.py
parent 67f38203
import sys
from django.shortcuts import render
from decision_support.interaction import *
from latino.interaction_views import *
from workflows import packageLibImporter
def setattr_local(name, value, package):
setattr(sys.modules[__name__], name, value)
packageLibImporter.importAllPackagesLib("interaction_views",setattr_local)
def test_interaction(request,input_dict,output_dict,widget):
return render(request, 'interactions/test_interaction.html',{'widget':widget})
......
from django.conf.urls.defaults import patterns, include, url
urlpatterns_latino = patterns('',
urlpatterns = patterns('',
url(r'^get-adc-index/widget(?P<widget_id>[0-9]+)/nx/Index.html$', 'workflows.latino.views.get_adc_index', name='get adc index'),
url(r'^get-adc-index/widget(?P<widget_id>[0-9]+)/(?P<narrow_doc>n?)x/Index.html$', 'workflows.latino.views.get_adc_index', name='get adc index'),
url(r'^get-adc-index/widget(?P<widget_id>[0-9]+)/(?P<narrow_doc>n?)x/Index(?P<document_id_from>[0-9]+)-(?P<document_id_to>[0-9]+).html$', 'workflows.latino.views.get_adc_index', name='get adc index'),
......
......@@ -2,8 +2,13 @@ from workflows.security import safeOpen
import nlp
import cPickle
import json
import sys
from decision_support.library import *
from latino.library import *
from workflows import packageLibImporter
def setattr_local(name, value, package):
setattr(sys.modules[__name__], name, value)
packageLibImporter.importAllPackagesLib("library",setattr_local)
def test_interaction(input_dict):
return input_dict
......
from mothra.settings import INSTALLED_APPS
appName = 'workflows'
import workflows.library
def getAllInstalledAps():
return [name[len(appName)+1:] for name in INSTALLED_APPS if name.startswith(appName+'.') and len(name)>len(appName)+1]
def importAllPackagesLib(libName, localSetattr):
for pck in getAllInstalledAps():
importPackageLib(pck, libName, localSetattr)
def importPackageLib(packageName, libName, localSetattr):
dynamicImportAllGlobals(appName+"."+packageName + "." + libName, packageName, localSetattr)
def dynamicImportAllGlobals(name, package, localSetattr):
try:
m = __import__(name, globals(), locals(), ['*'])
except:
return
all_names = [name for name in dir(m) if name[0]!='_']
g = globals()
for name in all_names:
#g[name] = m.__dict__.get(name)
#print name
localSetattr(name, m.__dict__.get(name), package)
from django.conf.urls.defaults import patterns, include, url
from latino.urls import urlpatterns_latino
urlpatterns = patterns('',
packageUrls = {}
from workflows import packageLibImporter
def set_package_url(name, value, package):
if name == 'urlpatterns':
packageUrls[package] = value
packageLibImporter.importAllPackagesLib("urls",set_package_url)
urlpatterns = patterns('',)
for pck in packageUrls:
urlpatterns += patterns('',url(r'^'+pck+'/', include(packageUrls[pck])),)
urlpatterns += patterns('',
url(r'^$', 'workflows.views.index', name='the index'),
url(r'^new-workflow/$', 'workflows.views.new_workflow', name='new workflow'),
url(r'^add-widget/$', 'workflows.views.add_widget', name='add widget'),
......@@ -59,6 +69,4 @@ urlpatterns = patterns('',
url(r'^reset-workflow/', 'workflows.views.reset_workflow', name='reset workflow'),
url(r'^export-package/(?P<packages>.+)/$', 'workflows.views.export_package', name='export_package'),
url(r'^latino/', include(urlpatterns_latino)),
)
\ No newline at end of file
import sys
from django.shortcuts import render
from django.http import Http404, HttpResponse
import nlp
from decision_support.visualization import *
from latino.visualization_views import *
from workflows import packageLibImporter
def setattr_local(name, value, package):
setattr(sys.modules[__name__], name, value)
packageLibImporter.importAllPackagesLib("visualization_views",setattr_local)
def odt_to_tab(request,input_dict,output_dict,widget):
import Orange
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment