Example #1
0
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether or not this application provides a full WSGI stack (by
        default, meaning it handles its own exceptions and errors).
        Disable full_stack when this application is "managed" by
        another WSGI middleware.

    ``app_conf``
        The application's local configuration. Normally specified in the
        [app:<name>] section of the Paste ini file (where <name>
        defaults to main).
    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    app = mid.DSMiddleware(app)
    
    #logging.basicConfig()
    #logging.getLogger('sqlalchemy').setLevel(logging.WARNING)
    
    #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
    #logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
    #logging.getLogger('sqlalchemy.orm').setLevel(logging.DEBUG)
    
    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, error_template=error_template,
                           **config['pylons.errorware'])
        
        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)

    # Establish the Registry for this application
    app = RegistryManager(app)

    # Static files
    javascripts_app = StaticJavascripts()
    debug = asbool(config['debug'])
    if debug:
        static_app = StaticURLParser(config['pylons.paths']['static_files'],cache_max_age=0)
    else:
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
    app = Cascade([static_app, javascripts_app, app])
    
    
    return app
Example #2
0
 def command(self):
     conf_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     ini_file = os.path.join(conf_dir, self.options.cfgfile)
     conf = appconfig("config:" + ini_file)
     load_environment(conf.global_conf, conf.local_conf)
     if self.options.classtype:
         create_data_new(self.options.classtype, drop=True)
     else:
         create_data(ini_file)
Example #3
0
def create_data(ini_file):
    """
    Creates initial data
    """
    conf = appconfig("config:" + ini_file)
    load_environment(conf.global_conf, conf.local_conf)
    if "test.ini" in ini_file:
        print "dropping tables for testing:  %s" % ini_file
        meta.metadata.drop_all(bind=config["pylons.g"].sa_engine)
    print "Creating DB Tables if they dont exist"
    meta.metadata.create_all(bind=config["pylons.g"].sa_engine)
    s = meta.DBSession.query(site.Site).get(1)
    key = conf["demisauce.apikey"]
    if not s:
        create_data_new("site")
        s = meta.DBSession.query(site.Site).get(1)

    if s.key != key:
        print "Update %s demisauce.apikey to %s \n" % (ini_file, s.key)

    user = meta.DBSession.query(person.Person).filter_by(site_id=s.id, id=1).first()
    if not user:
        # pwd = raw_input('Enter the Password for admin: ')
        create_data_new("person", True)
        user = person.Person.get(1, 1)

    cmsitem = cms.Cmsitem.get_root(site_id=s.id)
    if not cmsitem:
        cmsitem = cms.Cmsitem(s.id, "root", "root, do not edit")
        cmsitem.item_type = "root"
        from demisauce.fixturedata import cmsitems

        for item in cmsitems:
            cmstemp = cms.Cmsitem(s.id, item["title"], item["content"])
            if "url" in item:
                cmstemp.url = item["url"]
            cmsitem.addChild(cmstemp)
            if "children" in item:
                cmstemp.item_type = "folder"
                for citem in item["children"]:
                    cmstemp2 = cms.Cmsitem(s.id, citem["title"], citem["content"])
                    if "url" in citem:
                        cmstemp2.url = citem["url"]
                    rid = cmstemp.rid and (cmstemp.rid + "/") or ""
                    cmstemp2.rid = ("%s%s" % (rid, cmstemp2.key)).lower()
                    cmstemp.addChild(cmstemp2)

        cmsitem.save()
        print "created items   "

    create_data_new("comment", True)
    create_data_new("poll", True)
    create_data_new("email", True)
    create_data_new("app", True)
    create_data_new("tag", True)
Example #4
0
 def command(self):
     print (
         "new email = %s, new pwd = %s, new host = %s"
         % (self.options.adminpwd, self.options.adminemail, self.options.site)
     )
     conf_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     ini_file = os.path.join(conf_dir, self.options.cfgfile)
     conf = appconfig("config:" + ini_file)
     load_environment(conf.global_conf, conf.local_conf)
     s = meta.DBSession.query(site.Site).filter_by(id=1).first()
     s.email = self.options.adminemail
     s.base_url = self.options.site
     s.save()
     p = meta.DBSession.query(person.Person).filter_by(id=1).first()
     p.set_password(self.options.adminpwd)
     p.email = self.options.adminemail
     p.save()