libindic / Silpa-Flask

SILPA rewritten using Flask Microframework
http://silpa.org.in
17 stars 19 forks source link

More seperation for modules #4

Closed santhoshtr closed 10 years ago

santhoshtr commented 12 years ago

Even though python modules are separated well, still the silpa application knows about them because in templates folder we have templateXYZ.html. Even if a module does not exist, the template exists inside templates folder. I propose further decoupling like this:

Then all modules can be loaded with following (example) code:

def loadModules():
    res = {}
    import os
    # check subfolders
    lst = os.listdir("modules")
    dir = []
    for d in lst:
        s = os.path.abspath("modules") + os.sep + d
        if os.path.isdir(s) and os.path.exists(s + os.sep + "__init__.py"):
            dir.append(d)
    # load the modules
    for d in dir:
        res[d] = __import__("modules." + d, fromlist = ["*"])
    return res

but the silpa.conf configuration for turing off/on the modules can still exist.

Also think about an absolute structure for packaging all these. We will have

Both of the above does not know each other, no dependencies with them. If we define a simple bridge package says python-silpa-spellchecker with dependency to both of them and having setup script to register the python application in silpa - by adding some configuration and template to a predefined system path... I think that makes things easier.

copyninja commented 12 years ago

@santhoshtr By keeping all modules inside modules folder aren't we duplicating the code? I understand about template.html but how about providing getTemplate function but making this way will make it difficult to use Flask because currently whole SILPA is routed from flask routing methods. Do you have any idea for fixing this?

nithinsag commented 11 years ago

@copyninja,I think the Blueprint class from flask can be used to achieve separating the templates from the main app http://flask.pocoo.org/docs/blueprints/ This blogpost illustrates this with an example http://mostovenko.blogspot.in/2012/04/flask-lightweight-and-awesome-adding-ui.html

simple_page = Blueprint('simple_page', __name__, template_folder='templates')

these blueprint instances can be packaged with both the modules and silpa as dependencies. But the routing in silpa-flask will have to rewritten