Skip to content

Commit

Permalink
Merge pull request #75 from jacebrowning/hide-invalid-actions
Browse files Browse the repository at this point in the history
Only show valid actions in each page listing
  • Loading branch information
jacebrowning authored Mar 26, 2021
2 parents 77190df + 28df824 commit 2a7dd13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 6 additions & 1 deletion pomace/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions pomace/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import unquote

from flask import redirect, request, url_for
from flask_api import FlaskAPI

Expand All @@ -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/<path:domain>")
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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "pomace"
version = "0.7a10"
version = "0.7"
description = "Dynamic page objects for browser automation."

license = "MIT"
Expand Down

0 comments on commit 2a7dd13

Please sign in to comment.