Пример #1
0
def init_tables():
    StorageDb.connect()
    try:
        MenuItem.create_table(True)

        ChartInfo.create_table(False)
        User.create_table(True)
        MenuItem.create_table(True)
        SimplePageConfig.create_table(True)
        ReportInfo.create_table(True)
        Connection.create_table(True)
        SQLquery.create_table(True)
        ServerConfig.create_table(True)
        
        User.create(login='******', password='******', name='Test User')
        create_menu_item("/admin/" ,'Home', -1, 'SimplePage', 1)
        SimplePageConfig.create(title="Admin Home", text="This is admin home")
        create_menu_item("/app/" ,'Home', -1, 'SimplePage', 2)
        SimplePageConfig.create(title="Home", text="This is the home page")
        create_menu_item("/admin/" ,'UpdateDB', 0, 'UpdateDB', 3)
        SimplePageConfig.create(title="Menu", text="This is the Menu page")
        create_menu_item("/admin/" ,'Report Creator', 0, 'ReportCreator', 4)
        SimplePageConfig.create(title="Config", text="This is the Config page")
        create_menu_item("/app/" ,'Reports', -1, 'Reports', 5)
        create_menu_item("/app/" ,'Charts', 4, 'Charts', 8)
        create_menu_item("/admin/" ,'Chart Creator', 4, 'ChartCreator', 9)
    
        Connection.create(name="local", description="", connection_engine="mysql", \
                          connection_login="******", connection_password="******", \
                          connection_host ="127.0.0.1", \
                          connection_defaultdb="mysql", connection_port = 3306)
        
        
        
        SQLquery.create(name='test', description='', sql="""SELECT *
                                         FROM mysql.user
                                        """, connection_id=1)
        
        ReportInfo.create(name="Users", description="Report description", source_type='SQLquery', \
                          source_id=1, cache_duration=86000, row_callback=""""fnRowCallback": function( nRow, aData, iDisplayIndex ) {
            $('td:eq(2)', nRow).html('<a href="/testpage?' + aData[2] + '"> link </a>');
            return nRow;
        },""")
        
        ServerConfig.create(key="CookieKey", value=random_string(50))
        ServerConfig.create(key="AppName", value="EazyReport")
        ServerConfig.create(key="CacheFolder", value="cache")
    except Exception, e:
        print "Database already exists", e
Пример #2
0
    def __init__(self, pagepath, page_id):
        WebPage.__init__(self, pagepath)
        self.report = None
        self.main_template = "report_creation.tpl"
        self.request_params =  dict(request.params)
        
        self.reports = ReportInfo.select()
        self.table_fields = ReportInfo._meta.fields
        self.action = None
        if  self.request_params.has_key("action"):
            self.action = self.request_params['action']
            if self.action == "create_all":
                json_return = {}
                for report in self.reports:
                    report.create_report()
                    json_return.update(report.get_json_repr())
                Je = JsonEncoder()
                self.special_return = Je.encode(json_return)
            elif self.action == 'new':
                self.sql_query = SQLquery.create(sql='select 1', connection_id=1)
                
                self.report = ReportInfo.create(name='PlaceHolderName', description='', source_type='SQLquery', \
                                                source_id=self.sql_query.id)
                
                redirect(self.pagepath + "?report=PlaceHolderName&action=edit" )

            elif self.request_params.has_key('report'):
                self.report = [report for report in self.reports if report.name==self.request_params['report']][0]
                self.sql_query = SQLquery.get(SQLquery.id == self.report.source_id)
            
            if self.action == 'edit' or self.action == 'new':
                self.current_report = self.report
                self.report.create_report_if_needed()
                self.last_run = report.last_run
                self.datatable = Datatables(self, self.report.name, self.report.get_header(), self.report.row_callback)
                
                
#                 
#                 self.header = report.get_header()
#                 self.css.append(Css("DT_bootstrap.css"))
#                 self.foot_js.append(Js("jquery.dataTables.min.js"))
#                 self.foot_js.append(Js("DT_bootstrap.js"))
#                 
#                 self.header = report.get_header()
#                 self.id_table = random_string(10)
#     
#                 self.drop_down_nb = True
#                 self.drop_down_values = [[20, 50, 100, -1], [20, 50, 100, "All"]]
#                 self.drop_down_text = "records per page"
#                 self.global_search = True
#                 self.global_search_text = "Search all columns:"
#                 self.pagination = True
#                 self.show_nb_records = True
#                 self.records_per_page = 20
#                 self.column_search = True
#                 self.foot_js_templates = [Template("datatables_js_ready", self)]
#                 self.ajax_url = "/cache/" + str(report.name) + ".json"
#                 self.csv_url = "/cache/" + str(report.name) + ".csv"
                
                
            elif self.action == 'update':
                self.sql_query.sql = self.request_params['sql_query_sql']
                self.sql_query.save()
                self.report.cache_duration = self.request_params['cache_duration']
                self.report.name = self.request_params['name']
                self.report.description = self.request_params['description']
                self.report.row_callback = self.request_params['row_callback']
                self.report.report_type =  self.request_params['report_type']
                self.report.save()
                self.report.create_report()
                redirect(self.pagepath + "?report=" + self.report.name +'&action=edit' )