mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-09-15 12:47:59 +08:00
only include source path element in url when multiple sources
This commit is contained in:
@@ -15,8 +15,7 @@
|
||||
# 3) somedir/dataset_annotations: an annotation directory. The corresponding h5ad must exist, but the directory may not.
|
||||
# in this case, descriptor == 'somedir/dataset_annotations', dataset == 'somedir/dataset.h5ad'
|
||||
|
||||
from flask.helpers import url_for
|
||||
|
||||
from cellxgene_gateway import flask_util
|
||||
from cellxgene_gateway.items.item import Item
|
||||
from cellxgene_gateway.items.item_source import ItemSource, LookupResult
|
||||
|
||||
@@ -41,12 +40,14 @@ class CacheKey:
|
||||
return self.source.get_local_path(self.annotation_item)
|
||||
|
||||
def relaunch_url(self):
|
||||
return url_for("do_relaunch", source=self.source_name, path=self.descriptor)
|
||||
return flask_util.relaunch_url(self.descriptor, self.source_name)
|
||||
|
||||
def gateway_basepath(self):
|
||||
return (
|
||||
url_for("do_view", source_name=self.source_name, path=self.descriptor) + "/"
|
||||
)
|
||||
return self.view_url + "/"
|
||||
|
||||
@property
|
||||
def view_url(self):
|
||||
return flask_util.view_url(self.descriptor, self.source_name)
|
||||
|
||||
@property
|
||||
def source_name(self):
|
||||
|
||||
@@ -10,23 +10,20 @@
|
||||
import os
|
||||
import urllib.parse
|
||||
|
||||
from flask import url_for
|
||||
|
||||
from cellxgene_gateway import env
|
||||
from cellxgene_gateway import env, flask_util
|
||||
from cellxgene_gateway.cache_key import CacheKey
|
||||
from cellxgene_gateway.dir_util import annotations_suffix, make_annotations, make_h5ad
|
||||
|
||||
|
||||
def render_annotations(item, item_source):
|
||||
url = url_for(
|
||||
"do_view",
|
||||
path=item_source.get_annotations_subpath(item),
|
||||
source_name=item_source.name,
|
||||
url = flask_util.view_url(
|
||||
item_source.get_annotations_subpath(item), item_source.name
|
||||
)
|
||||
new_annotation = f"<a class='new' href='{url}'>new</a>"
|
||||
annotations = (
|
||||
", ".join(
|
||||
[
|
||||
f"<a href='{url_for('do_view', path=a.descriptor, source_name = item_source.name)}/'>{a.name}</a>"
|
||||
f"<a href='{CacheKey(item, item_source, a).view_url}/'>{a.name}</a>"
|
||||
for a in item.annotations
|
||||
]
|
||||
)
|
||||
@@ -38,8 +35,7 @@ def render_annotations(item, item_source):
|
||||
|
||||
|
||||
def render_item(item, item_source):
|
||||
url = url_for("do_view", path=item.descriptor, source_name=item_source.name) + "/"
|
||||
item_string = f"<li> <a href='{ url }'>{item.name}</a> {render_annotations(item, item_source)}</li>"
|
||||
item_string = f"<li> <a href='{ CacheKey(item, item_source).view_url }/'>{item.name}</a> {render_annotations(item, item_source)}</li>"
|
||||
return item_string
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,27 @@
|
||||
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
||||
# the specific language governing permissions and limitations under the License.
|
||||
|
||||
from flask import request
|
||||
from flask import request, url_for
|
||||
|
||||
|
||||
def querystring():
|
||||
qs = request.query_string.decode()
|
||||
return f"?{qs}" if len(qs) > 0 else ""
|
||||
|
||||
|
||||
include_source_in_url = False
|
||||
|
||||
|
||||
def url(endpoint, descriptor, source_name):
|
||||
if include_source_in_url:
|
||||
return url_for(endpoint, source_name=source_name, path=descriptor)
|
||||
else:
|
||||
return url_for(endpoint, path=descriptor)
|
||||
|
||||
|
||||
def view_url(descriptor, source_name):
|
||||
return url("do_view", descriptor, source_name)
|
||||
|
||||
|
||||
def relaunch_url(descriptor, source_name):
|
||||
return url("do_relaunch", descriptor, source_name)
|
||||
|
||||
@@ -26,7 +26,7 @@ from flask_api import status
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from cellxgene_gateway import env
|
||||
from cellxgene_gateway import env, flask_util
|
||||
from cellxgene_gateway.backend_cache import BackendCache
|
||||
from cellxgene_gateway.cache_entry import CacheEntryStatus
|
||||
from cellxgene_gateway.cache_key import CacheKey
|
||||
@@ -248,7 +248,7 @@ def do_relaunch(path):
|
||||
match.terminate()
|
||||
qs = request.query_string.decode()
|
||||
return redirect(
|
||||
url_for("do_view", path=path) + (f"?{qs}" if len(qs) > 0 else ""),
|
||||
key.view_url + (f"?{qs}" if len(qs) > 0 else ""),
|
||||
code=302,
|
||||
)
|
||||
|
||||
@@ -302,6 +302,7 @@ def main():
|
||||
default_item_source = "local"
|
||||
if len(item_sources) == 0:
|
||||
raise Exception("Please specify CELLXGENE_DATA or CELLXGENE_BUCKET")
|
||||
flask_util.include_source_in_url = len(item_sources) > 1
|
||||
|
||||
launch()
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<tr>
|
||||
<td>{{ entry.pid }}</td>
|
||||
<td><a
|
||||
href="{{ url_for('do_view', path=entry.key.descriptor, source_name=entry.key.source_name) }}">{{ entry.key.h5ad_item.descriptor }}</a>
|
||||
href="{{ entry.key.view_url }}">{{ entry.key.h5ad_item.descriptor }}</a>
|
||||
</td>
|
||||
<td>{{ entry.key.annotation_descriptor }}</td>
|
||||
<td>{{ entry.source_name }}</td>
|
||||
|
||||
Reference in New Issue
Block a user