Esempio n. 1
0
    def get_synced_lists(self):
        synced_lists = []

        for synced_list_data in details_table.get_details():
            details_id = synced_list_data._id

            database_data = database_table.find_detail(details_id)
            provider_data = provider_table.find_detail(details_id)
            list_data = lists_table.find_detail(details_id)
            columns_data = columns_table.find_details(details_id)

            if database_data and provider_data and list_data and columns_data:

                driver = self.get_driver(database_data)
                adapter.setup(driver)

                table = database_data.table
                primary_key = adapter.get_primary_key(table)

                last_inserted_id = self._get_last_inserted_id(
                    list_data, table, primary_key)
                columns_dict = self.get_columns(columns_data)

                try:
                    rows_to_be_synced = adapter.get_rows_to_be_inserted(
                        table, columns_dict, primary_key, last_inserted_id)

                    provider_name = self._get_provider(provider_data.provider)

                    synced_lists.append({
                        "id":
                        synced_list_data._id,
                        "name":
                        list_data.name,
                        "last_synced":
                        synced_list_data.last_synced,
                        "provider":
                        provider_name,
                        "database":
                        database_data,
                        "table":
                        table,
                        "rows_to_be_synced":
                        len(rows_to_be_synced)
                    })
                except Exception, err:
                    logging.error(err)
                    continue
Esempio n. 2
0
	def sync(self, details_id):
		database_data = database_table.find_detail(details_id)
		provider_data = provider_table.find_detail(details_id)
		list_data = lists_table.find_detail(details_id)
		columns_data = columns_table.find_details(details_id)

		adapter.setup(self.get_driver(database_data))

		table = database_data.table
		primary_key = adapter.get_primary_key(table)

		columns = self.get_columns(columns_data)

		if primary_key and adapter.is_valid_connection():
			last_inserted_id = self.get_last_id(adapter, table, primary_key, list_data)
			rows_to_be_inserted = adapter.get_rows_to_be_inserted(table, columns, primary_key, last_inserted_id)
			number_of_rows = len(rows_to_be_inserted)

			if self.status("Completed", list_data) and number_of_rows == 0:
				return True

			provider = Provider(provider_data.provider, provider_data.apikey)
			
			row_chunks = self.split_rows(rows_to_be_inserted, 100)
			header_row = tuple(columns.keys())
			
			self.update_status_running(last_inserted_id, 
				number_of_rows,
				details_id)

			last_id = adapter.get_last_inserted_id(table, 
				primary_key, 
				"last")

			self.sync_users_thread(self.sync_users, 
				provider, 
				list_data.id,
				header_row, 
				row_chunks, 
				last_id, 
				details_id,
				columns)

			return True

		return False
Esempio n. 3
0
    def get_synced_lists(self):
        synced_lists = []
        
        for synced_list_data in details_table.get_details():
            details_id = synced_list_data._id

            database_data = database_table.find_detail(details_id)
            provider_data = provider_table.find_detail(details_id)
            list_data = lists_table.find_detail(details_id)
            columns_data = columns_table.find_details(details_id)

            if database_data and provider_data and list_data and columns_data:

                driver = self.get_driver(database_data)
                adapter.setup(driver)

                table = database_data.table
                primary_key = adapter.get_primary_key(table)

                last_inserted_id = self._get_last_inserted_id(list_data, table, primary_key)
                columns_dict = self.get_columns(columns_data)

                try:
                    rows_to_be_synced = adapter.get_rows_to_be_inserted(table, columns_dict, primary_key, last_inserted_id)
                    
                    provider_name = self._get_provider(provider_data.provider) 
                    
                    synced_lists.append({
                        "id": synced_list_data._id,
                        "name": list_data.name,
                        "last_synced": synced_list_data.last_synced,
                        "provider": provider_name,
                        "database": database_data,
                        "table": table,
                        "rows_to_be_synced": len(rows_to_be_synced)
                    })
                except Exception, err:
                    logging.error(err)
                    continue
Esempio n. 4
0
class DatabaseView(BaseView):

    @authenticated
    def get(self):
        errors = self.get_session_object("errors")
        driver = self.get_session_object("driver")

        self.render("setup/database.html", errors=errors, driver=driver)

    @authenticated
    def post(self):
        self.check_xsrf_cookie()

        try:
            driver = {
                "host": self.get_argument("driver.host", ""),
                "port" : self.get_argument("driver.port" , ""),
                "database": self.get_argument("driver.database" , ""),
                "username": self.get_argument("driver.username" , ""),
                "password": self.get_argument("driver.password" , ""),
                "driver": self.get_argument("driver.driver" , ""),
                "table": self.get_argument("tables" , "")
            }

            valid_form = CreateDbDataForm.to_python(driver)
        except InvalidForm, e:
            self.session["errors"] = e.unpack_errors()
            self.session["driver"] = driver
            self.redirect("/database")

        adapter.setup(driver)

        if adapter.is_valid_connection():
            self.session["driver"] = driver
            
            self.delete_session_object("errors")
            
            self.redirect("/columns")
        else:
            self.session["errors"] = {"invalid_connection": True}
            self.redirect("/database")