Beispiel #1
0
    def has_next(self):
        try:
            self.page.rewind()
        except Exception as detail:
            Log.warning(detail)

        return True if (self.page.count(True) == self.limit) else False
Beispiel #2
0
 def has_next(self):
     try:
         self.page.rewind()
     except Exception as detail:
         Log.warning(detail)
         
     return True if (self.page.count(True) == self.limit) else False
Beispiel #3
0
 def delete_selected(handler,pymongo_collection,feild_name='ids',return_stats=False):
     ids = handler.get_argument(feild_name,[])
     
     if len(ids) == 0: return False
     
     if not return_stats:
         pymongo_collection.remove(
             {'_id':{'$in':ids}
         })
         return True
     else:
         stats = {
             'requested':len(ids),
             'success':0,
             'failed':0
         }
         
         for id in ids:
             try:
                 pymongo_collection.remove({'_id':id},True)
                 stats['success'] += 1
             except Exception, ex:
                 stats['failed'] += 1
                 Log.error(ex.message)
     
         return stats
Beispiel #4
0
 def page(self):
     start = self.page_number * self.limit
     end = start + self.limit
     try:
         return self.collection[start:end]
     except Exception as detail:
         Log.warning(detail)
         return []
Beispiel #5
0
 def page(self):
     start = self.page_number * self.limit
     end = start + self.limit
     try:
         return self.collection[start:end]
     except Exception as detail:
         Log.warning(detail)
         return []
Beispiel #6
0
    def main(self, path):
        #import tornado stuff
        import tornado.web, tornado.httpserver, tornado.ioloop, tornado.options
        from tornado.options import options
        from config import options_setup
        from whirlwind.db.mongo import Mongo

        #parse the app config
        tornado.options.parse_config_file(
            os.path.join(path, 'config/settings.py'))
        #parse the command line args
        tornado.options.parse_command_line()

        #connect to our db using our options set in settings.py
        Mongo.create(host=options.db_host, port=options.db_port)

        #init our url routes
        url_routes = self.init_routes()

        #init a logger
        self.init_logging(options.log)

        #add in any app settings
        settings = {
            "static_path": options.static_path,
            "cookie_secret": options.cookie_secret,
            "login_url": options.login_url,
        }

        #setup the controller action routes
        self.application = tornado.web.Application(url_routes, **settings)

        #instantiate a server instance
        http_server = tornado.httpserver.HTTPServer(self.application)

        #bind server to port
        http_server.listen(options.port)

        #log our start message
        Log.info("Ready and listening")

        #start the server
        tornado.ioloop.IOLoop.instance().start()
Beispiel #7
0
 def main(self):
     #import tornado stuff
     import tornado.web, tornado.httpserver, tornado.ioloop, tornado.options
     from tornado.options import options
     from config import options_setup
     from whirlwind.db.mongo import Mongo
     
     #parse the app config
     tornado.options.parse_config_file(os.path.join(os.path.dirname(__file__),'config/settings.py'))
     #parse the command line args
     tornado.options.parse_command_line()
     
     #connect to our db using our options set in settings.py
     Mongo.create(host=options.db_host, port=options.db_port)
     
     #init our url routes
     url_routes = self.init_routes()
     
     #init a logger
     self.init_logging(options.log)
     
     #add in any app settings 
     settings = {
         "static_path": options.static_path,
         "cookie_secret": options.cookie_secret,
         "login_url": options.login_url,
     }
     
     #setup the controller action routes
     self.application = tornado.web.Application(url_routes,**settings)
     
     #instantiate a server instance
     http_server = tornado.httpserver.HTTPServer(self.application)
     
     #bind server to port
     http_server.listen(options.port)
     
     #log our start message
     Log.info("Ready and listening")
     
     #start the server
     tornado.ioloop.IOLoop.instance().start()
Beispiel #8
0
 def init_logging(self,log):
     if log == 'db':
         Log.create()
     else:
         Log.create('FILE',log)
Beispiel #9
0
 def init_logging(self, log):
     if log == 'db':
         Log.create()
     else:
         Log.create('FILE', log)