Skip to content

Commit

Permalink
refactor: parse main slot only on demand
Browse files Browse the repository at this point in the history
BREAKING CHANGE: legagy code needs to call parse_main_slot()

Refs: #56
  • Loading branch information
simontaurus committed Oct 27, 2024
1 parent 4cc9e3f commit 62becc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/page_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def mass_page_edit():
wtsite = WtSite.from_domain("wiki-dev.open-semantic-lab.org", pwd_file_path)
# wtpage = wtsite.get_WtPage("LabNote:220601-sist-0001-ni")
# wtpage = wtsite.get_WtPage("testesfesefsef")
# wtpage.parse_main_slot()
# wtpage.append_template("TestTemplate", {"p1": "v1"})
# wtpage.append_text("Some text",)
# wtpage.append_template("TestTemplate", {"p1": "v2"})
Expand Down
11 changes: 8 additions & 3 deletions src/osw/wtsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,6 @@ def init(self):
if self.exists:
self._original_content = self._page.text()
self._content = self._original_content
self._dict = wt.create_flat_content_structure_from_wikitext(
self._content, array_mode="only_multiple"
)
# multi content revisions
# second API call - ToDo: combine / replace with first call
rev = self.wtSite._site.api(
Expand Down Expand Up @@ -989,6 +986,14 @@ def init(self):
# todo: set content for slots not in revision["slots"] (use
# SLOTS) --> create empty slots

def parse_main_slot(self):
"""Parses the main slot content of the page
Requires wikitext dependencies installed with 'pip install osw[wikitext]'
"""
self._dict = wt.create_flat_content_structure_from_wikitext(
self._content, array_mode="only_multiple"
)

def create_slot(self, slot_key, content_model):
"""Creates a new slot for the page. Availables Keys and content models are defined in
SLOTS.
Expand Down

0 comments on commit 62becc7

Please sign in to comment.