From 28df8240be9a0789b5a776e99520b1d925457079 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Fri, 26 Mar 2021 10:21:29 -0400 Subject: [PATCH] Only show valid actions in each page listing --- pomace/models.py | 7 ++++++- pomace/server.py | 23 ++++++++++++++--------- pyproject.toml | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pomace/models.py b/pomace/models.py index 6012dad..71e481e 100644 --- a/pomace/models.py +++ b/pomace/models.py @@ -98,6 +98,10 @@ def locator(self) -> Locator: except IndexError: return Locator("id", "placeholder") + @property + def valid(self) -> bool: + return self.locator.uses >= 0 + def __post_init__(self): if self.verb and self._verb != Verb.TYPE and not self.sorted_locators: if settings.dev: @@ -376,7 +380,8 @@ def __dir__(self): add_placeholder = True for action in self.actions: if action: - names.append(str(action)) + if action.valid: + names.append(str(action)) else: add_placeholder = False if add_placeholder: diff --git a/pomace/server.py b/pomace/server.py index 968b75d..7512e87 100644 --- a/pomace/server.py +++ b/pomace/server.py @@ -1,3 +1,5 @@ +from urllib.parse import unquote + from flask import redirect, request, url_for from flask_api import FlaskAPI @@ -9,28 +11,31 @@ @app.route("/") def index(): - return redirect("/sites/example.com") + return redirect("/sites?url=http://example.com") + +@app.route("/sites") +def pomace(): + if "url" not in request.args: + return redirect("/") -@app.route("/sites/") -def pomace(domain: str): utils.launch_browser(restore_previous_url=False) - url = "https://" + domain - page = models.Page.at(url) + url = request.args.get("url") + page = models.Page.at(url) # type: ignore for action, value in request.args.items(): - page, _updated = page.perform(action, value, _logger=app.logger) + if "_" in action: + page, _updated = page.perform(action, value, _logger=app.logger) - domain = page.url.split("://", 1)[-1] data = { "id": page.identity, "url": page.url, "title": page.title, "html": page.html.prettify(), "text": page.text, - "_next": url_for(".pomace", domain=domain, _external=True), - "_actions": [str(a) for a in page.actions if a], + "_next": unquote(url_for(".pomace", url=page.url, _external=True)), + "_actions": dir(page), } if not app.debug: diff --git a/pyproject.toml b/pyproject.toml index 747d0af..bc666bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pomace" -version = "0.7a10" +version = "0.7" description = "Dynamic page objects for browser automation." license = "MIT"