Skip to content

Commit 359e058

Browse files
committed
fix(rsc): allow pin_write to use full name
1 parent 67c441e commit 359e058

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pins/boards.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,15 @@ def user_name(self):
736736
user = self.fs.api.get_user()
737737
return user["username"]
738738

739-
def prepare_pin_version(self, pin_dir_path, x, *args, **kwargs):
740-
from jinja2 import Environment
739+
def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwargs):
741740

742-
env = Environment()
743-
template = env.from_string(self.html_template.read_text())
741+
# RSC pin names can have form <user_name>/<name>, but this will try to
742+
# create the object in a directory named <user_name>. So we grab just
743+
# the <name> part.
744+
if "/" in name:
745+
name = name.split("/")[-1]
744746

745-
meta = super().prepare_pin_version(pin_dir_path, x, *args, **kwargs)
747+
meta = super().prepare_pin_version(pin_dir_path, x, name, *args, **kwargs)
746748

747749
# copy in files needed by index.html ----------------------------------
748750
crnt_files = set([meta.file] if isinstance(meta.file, str) else meta.file)
@@ -788,6 +790,13 @@ def prepare_pin_version(self, pin_dir_path, x, *args, **kwargs):
788790
# TODO(compat): set display none in index.html
789791
context["data_preview"] = json.dumps({})
790792

793+
# render html template ----
794+
795+
from jinja2 import Environment
796+
797+
env = Environment()
798+
template = env.from_string(self.html_template.read_text())
799+
791800
rendered = template.render(context)
792801
(Path(pin_dir_path) / "index.html").write_text(rendered)
793802

pins/tests/test_boards.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,10 @@ def test_board_pin_search_name(board, df, search, matches):
268268
from pins.boards import BoardRsConnect # noqa
269269

270270

271-
@pytest.mark.xfail
272271
@pytest.mark.fs_rsc
273272
def test_board_pin_write_rsc_full_name(df, fs_short): # noqa
274273
board_susan = BoardRsConnect("", fs_short)
275-
board_susan.pin_write(df, "susan/df", type="csv")
274+
board_susan.pin_write(df, "susan/some_df", type="csv")
276275

277276

278277
@pytest.mark.fs_rsc

0 commit comments

Comments
 (0)