kopia lustrzana https://github.com/simonw/datasette
				
				
				
			Also remove default_cache_ttl_hashed setting, refs #1661
							rodzic
							
								
									8658c66438
								
							
						
					
					
						commit
						9979dcd07f
					
				| 
						 | 
					@ -134,11 +134,6 @@ SETTINGS = (
 | 
				
			||||||
        5,
 | 
					        5,
 | 
				
			||||||
        "Default HTTP cache TTL (used in Cache-Control: max-age= header)",
 | 
					        "Default HTTP cache TTL (used in Cache-Control: max-age= header)",
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    Setting(
 | 
					 | 
				
			||||||
        "default_cache_ttl_hashed",
 | 
					 | 
				
			||||||
        365 * 24 * 60 * 60,
 | 
					 | 
				
			||||||
        "Default HTTP cache TTL for hashed URL pages",
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    Setting("cache_size_kb", 0, "SQLite cache size in KB (0 == use SQLite default)"),
 | 
					    Setting("cache_size_kb", 0, "SQLite cache size in KB (0 == use SQLite default)"),
 | 
				
			||||||
    Setting(
 | 
					    Setting(
 | 
				
			||||||
        "allow_csv_stream",
 | 
					        "allow_csv_stream",
 | 
				
			||||||
| 
						 | 
					@ -172,17 +167,11 @@ SETTINGS = (
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    Setting("base_url", "/", "Datasette URLs should use this base path"),
 | 
					    Setting("base_url", "/", "Datasette URLs should use this base path"),
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					_HASH_URLS_REMOVED = "The hash_urls setting has been removed, try the datasette-hashed-urls plugin instead"
 | 
				
			||||||
OBSOLETE_SETTINGS = {
 | 
					OBSOLETE_SETTINGS = {
 | 
				
			||||||
    option.name: option
 | 
					    "hash_urls": _HASH_URLS_REMOVED,
 | 
				
			||||||
    for option in (
 | 
					    "default_cache_ttl_hashed": _HASH_URLS_REMOVED,
 | 
				
			||||||
        Setting(
 | 
					 | 
				
			||||||
            "hash_urls",
 | 
					 | 
				
			||||||
            False,
 | 
					 | 
				
			||||||
            "The hash_urls setting has been removed, try the datasette-hashed-urls plugin instead",
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
DEFAULT_SETTINGS = {option.name: option.default for option in SETTINGS}
 | 
					DEFAULT_SETTINGS = {option.name: option.default for option in SETTINGS}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FAVICON_PATH = app_root / "datasette" / "static" / "favicon.png"
 | 
					FAVICON_PATH = app_root / "datasette" / "static" / "favicon.png"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,10 +57,10 @@ class Config(click.ParamType):
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        name, value = config.split(":", 1)
 | 
					        name, value = config.split(":", 1)
 | 
				
			||||||
        if name not in DEFAULT_SETTINGS:
 | 
					        if name not in DEFAULT_SETTINGS:
 | 
				
			||||||
            if name in OBSOLETE_SETTINGS:
 | 
					            msg = (
 | 
				
			||||||
                msg = OBSOLETE_SETTINGS[name].help
 | 
					                OBSOLETE_SETTINGS.get(name)
 | 
				
			||||||
            else:
 | 
					                or f"{name} is not a valid option (--help-settings to see all)"
 | 
				
			||||||
                msg = f"{name} is not a valid option (--help-settings to see all)"
 | 
					            )
 | 
				
			||||||
            self.fail(
 | 
					            self.fail(
 | 
				
			||||||
                msg,
 | 
					                msg,
 | 
				
			||||||
                param,
 | 
					                param,
 | 
				
			||||||
| 
						 | 
					@ -94,10 +94,10 @@ class Setting(CompositeParamType):
 | 
				
			||||||
    def convert(self, config, param, ctx):
 | 
					    def convert(self, config, param, ctx):
 | 
				
			||||||
        name, value = config
 | 
					        name, value = config
 | 
				
			||||||
        if name not in DEFAULT_SETTINGS:
 | 
					        if name not in DEFAULT_SETTINGS:
 | 
				
			||||||
            if name in OBSOLETE_SETTINGS:
 | 
					            msg = (
 | 
				
			||||||
                msg = OBSOLETE_SETTINGS[name].help
 | 
					                OBSOLETE_SETTINGS.get(name)
 | 
				
			||||||
            else:
 | 
					                or f"{name} is not a valid option (--help-settings to see all)"
 | 
				
			||||||
                msg = f"{name} is not a valid option (--help-settings to see all)"
 | 
					            )
 | 
				
			||||||
            self.fail(
 | 
					            self.fail(
 | 
				
			||||||
                msg,
 | 
					                msg,
 | 
				
			||||||
                param,
 | 
					                param,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,14 +28,7 @@ class Urls:
 | 
				
			||||||
        return self.path("-/logout")
 | 
					        return self.path("-/logout")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def database(self, database, format=None):
 | 
					    def database(self, database, format=None):
 | 
				
			||||||
        db = self.ds.databases[database]
 | 
					        return self.path(tilde_encode(database), format=format)
 | 
				
			||||||
        if self.ds.setting("hash_urls") and db.hash:
 | 
					 | 
				
			||||||
            path = self.path(
 | 
					 | 
				
			||||||
                f"{tilde_encode(database)}-{db.hash[:HASH_LENGTH]}", format=format
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            path = self.path(tilde_encode(database), format=format)
 | 
					 | 
				
			||||||
        return path
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def table(self, database, table, format=None):
 | 
					    def table(self, database, table, format=None):
 | 
				
			||||||
        path = f"{self.database(database)}/{tilde_encode(table)}"
 | 
					        path = f"{self.database(database)}/{tilde_encode(table)}"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -798,14 +798,12 @@ def test_settings_json(app_client):
 | 
				
			||||||
        "allow_facet": True,
 | 
					        "allow_facet": True,
 | 
				
			||||||
        "suggest_facets": True,
 | 
					        "suggest_facets": True,
 | 
				
			||||||
        "default_cache_ttl": 5,
 | 
					        "default_cache_ttl": 5,
 | 
				
			||||||
        "default_cache_ttl_hashed": 365 * 24 * 60 * 60,
 | 
					 | 
				
			||||||
        "num_sql_threads": 1,
 | 
					        "num_sql_threads": 1,
 | 
				
			||||||
        "cache_size_kb": 0,
 | 
					        "cache_size_kb": 0,
 | 
				
			||||||
        "allow_csv_stream": True,
 | 
					        "allow_csv_stream": True,
 | 
				
			||||||
        "max_csv_mb": 100,
 | 
					        "max_csv_mb": 100,
 | 
				
			||||||
        "truncate_cells_html": 2048,
 | 
					        "truncate_cells_html": 2048,
 | 
				
			||||||
        "force_https_urls": False,
 | 
					        "force_https_urls": False,
 | 
				
			||||||
        "hash_urls": False,
 | 
					 | 
				
			||||||
        "template_debug": False,
 | 
					        "template_debug": False,
 | 
				
			||||||
        "trace_debug": False,
 | 
					        "trace_debug": False,
 | 
				
			||||||
        "base_url": "/",
 | 
					        "base_url": "/",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -312,8 +312,9 @@ def test_help_settings():
 | 
				
			||||||
        assert setting.name in result.output
 | 
					        assert setting.name in result.output
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_help_error_on_hash_urls_setting():
 | 
					@pytest.mark.parametrize("setting", ("hash_urls", "default_cache_ttl_hashed"))
 | 
				
			||||||
 | 
					def test_help_error_on_hash_urls_setting(setting):
 | 
				
			||||||
    runner = CliRunner()
 | 
					    runner = CliRunner()
 | 
				
			||||||
    result = runner.invoke(cli, ["--setting", "hash_urls", 1])
 | 
					    result = runner.invoke(cli, ["--setting", setting, 1])
 | 
				
			||||||
    assert result.exit_code == 2
 | 
					    assert result.exit_code == 2
 | 
				
			||||||
    assert 'The hash_urls setting has been removed' in result.output
 | 
					    assert "The hash_urls setting has been removed" in result.output
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Ładowanie…
	
		Reference in New Issue