mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Refactored view class hierarchy, refs #272
See https://github.com/simonw/datasette/issues/272#issuecomment-502393107
This commit is contained in:
parent
aa911122fe
commit
d4df640d18
5 changed files with 11 additions and 11 deletions
|
|
@ -49,7 +49,7 @@ class DatasetteError(Exception):
|
|||
self.messagge_is_html = messagge_is_html
|
||||
|
||||
|
||||
class RenderMixin(HTTPMethodView):
|
||||
class BaseView(HTTPMethodView):
|
||||
def _asset_urls(self, key, template, context):
|
||||
# Flatten list-of-lists from plugins:
|
||||
seen_urls = set()
|
||||
|
|
@ -128,7 +128,7 @@ class RenderMixin(HTTPMethodView):
|
|||
)
|
||||
|
||||
|
||||
class BaseView(RenderMixin):
|
||||
class DataView(BaseView):
|
||||
name = ""
|
||||
re_named_parameter = re.compile(":([a-zA-Z0-9_]+)")
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ from sanic import response
|
|||
|
||||
from datasette.utils import to_css_class, validate_sql_select
|
||||
|
||||
from .base import BaseView, DatasetteError
|
||||
from .base import DataView, DatasetteError
|
||||
|
||||
|
||||
class DatabaseView(BaseView):
|
||||
class DatabaseView(DataView):
|
||||
name = "database"
|
||||
|
||||
async def data(self, request, database, hash, default_labels=False, _size=None):
|
||||
|
|
@ -65,7 +65,7 @@ class DatabaseView(BaseView):
|
|||
)
|
||||
|
||||
|
||||
class DatabaseDownload(BaseView):
|
||||
class DatabaseDownload(DataView):
|
||||
name = "database_download"
|
||||
|
||||
async def view_get(self, request, database, hash, correct_hash_present, **kwargs):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from sanic import response
|
|||
from datasette.utils import CustomJSONEncoder
|
||||
from datasette.version import __version__
|
||||
|
||||
from .base import RenderMixin
|
||||
from .base import BaseView
|
||||
|
||||
|
||||
# Truncate table list on homepage at:
|
||||
|
|
@ -16,7 +16,7 @@ TRUNCATE_AT = 5
|
|||
COUNT_TABLE_LIMIT = 30
|
||||
|
||||
|
||||
class IndexView(RenderMixin):
|
||||
class IndexView(BaseView):
|
||||
name = "index"
|
||||
|
||||
def __init__(self, datasette):
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import json
|
||||
from sanic import response
|
||||
from .base import RenderMixin
|
||||
from .base import BaseView
|
||||
|
||||
|
||||
class JsonDataView(RenderMixin):
|
||||
class JsonDataView(BaseView):
|
||||
name = "json_data"
|
||||
|
||||
def __init__(self, datasette, filename, data_callback):
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from datasette.utils import (
|
|||
value_as_boolean,
|
||||
)
|
||||
from datasette.filters import Filters
|
||||
from .base import BaseView, DatasetteError, ureg
|
||||
from .base import DataView, DatasetteError, ureg
|
||||
|
||||
LINK_WITH_LABEL = (
|
||||
'<a href="/{database}/{table}/{link_id}">{label}</a> <em>{id}</em>'
|
||||
|
|
@ -33,7 +33,7 @@ LINK_WITH_LABEL = (
|
|||
LINK_WITH_VALUE = '<a href="/{database}/{table}/{link_id}">{id}</a>'
|
||||
|
||||
|
||||
class RowTableShared(BaseView):
|
||||
class RowTableShared(DataView):
|
||||
async def sortable_columns_for_table(self, database, table, use_rowid):
|
||||
db = self.ds.databases[database]
|
||||
table_metadata = self.ds.table_metadata(database, table)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue