Skip to content

Commit

Permalink
Populate app name and url as always-available template variables
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Feb 8, 2019
1 parent f6a9ac4 commit 64d1550
Show file tree
Hide file tree
Showing 24 changed files with 8 additions and 70 deletions.
7 changes: 2 additions & 5 deletions apps/bookmarklets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ class Controller:
name = "Bookmarklets"

@cherrypy.tools.negotiable()
def GET(self):
@staticmethod
def GET():
"""Present a static list of bookmarklets"""

app_url = cherrypy.engine.publish("url:internal").pop()

anonymizer = cherrypy.engine.publish(
"registry:first_value",
"config:url_anonymizer",
Expand All @@ -27,8 +26,6 @@ def GET(self):

return {
"html": ("bookmarklets.jinja.html", {
"app_name": self.name,
"app_url": app_url,
"anonymizer": anonymizer,
"ubounce": ubounce
})
Expand Down
4 changes: 0 additions & 4 deletions apps/bookmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ def GET(self, *_args, **kwargs):
"bookmarks:recent"
).pop()

app_url = cherrypy.engine.publish("url:internal").pop()

return {
"html": ("bookmarks.jinja.html", {
"app_name": self.name,
"app_url": app_url,
"bookmarks": bookmarks,
"query": query
})
Expand Down
4 changes: 0 additions & 4 deletions apps/bounce/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,14 @@ def GET(self, *_args, **kwargs):
for bounce in bounces
}

app_url = cherrypy.engine.publish("url:internal").pop()

return {
"html": ("bounce.jinja.html", {
"departing_from": departing_from,
"departing_url": url,
"site": host,
"group": group,
"name": name,
"app_url": app_url,
"bounces": bounces,
"app_name": self.name
})
}

Expand Down
7 changes: 1 addition & 6 deletions apps/bounce/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ def side_effect(*args, **_):
helpers.html_var(render_mock, "bounces")
)

@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_bookmarklet_url_https(self, publish_mock, render_mock):
def test_bookmarklet_url_https(self, publish_mock):
"""The bookmarklet URL respects HTTPS."""

def side_effect(*args, **_):
Expand All @@ -277,10 +276,6 @@ def side_effect(*args, **_):
u="http://unrecognized.example.com"
)

self.assertTrue(
helpers.html_var(render_mock, "app_url").startswith("https")
)

@mock.patch("cherrypy.tools.negotiable.render_html")
@mock.patch("cherrypy.engine.publish")
def test_departing_site(self, publish_mock, render_mock):
Expand Down
1 change: 0 additions & 1 deletion apps/calls/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ def GET(self, *_args, **kwargs):
"total": total,
"newer_offset": newer_offset,
"older_offset": older_offset,
"app_name": self.name
})
}
1 change: 0 additions & 1 deletion apps/captures/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ def GET(self, *_args, **kwargs):
"captures": captures,
"newer_offset": newer_offset,
"older_offset": older_offset,
"app_name": self.name
})
}
1 change: 0 additions & 1 deletion apps/grids/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def GET(self, *_args, **kwargs):

return {
"html": ("grids.jinja.html", {
"app_name": self.name,
"headers": headers,
"name": name,
"names": [key.split(":")[1] for key in grids.keys()],
Expand Down
1 change: 0 additions & 1 deletion apps/headers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ def GET(self, *_args, **_kwargs):
"text": ["{}: {}".format(*header) for header in headers],
"html": ("headers.jinja.html", {
"headers": headers,
"app_name": self.name,
})
}
1 change: 0 additions & 1 deletion apps/headlines/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def GET(self, *_args, **kwargs):
"headlines": headlines,
"limit": limit,
"offset": offset,
"app_name": self.name
}),
"json": headlines,
}
1 change: 0 additions & 1 deletion apps/homepage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def GET(self, *_args, **_kwargs):
return {
"etag_key": template,
"html": (template, {
"app_name": self.name,
"apps": apps
})
}
11 changes: 1 addition & 10 deletions apps/htmlhead/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ class Controller:
def GET(self, *_args, **_kwargs):
"""Present a form for specifying a URL to fetch."""

app_url = cherrypy.engine.publish("url:internal").pop()

return {
"html": ("htmlhead.jinja.html", {
"app_url": app_url,
"app_name": self.name,
})
"html": ("htmlhead.jinja.html", {})
}

@cherrypy.tools.negotiable()
Expand All @@ -28,8 +23,6 @@ def POST(self, url=None, username=None, password=None):
section.
"""

app_url = cherrypy.engine.publish("url:internal").pop()

status_code = None
request_failed = False

Expand Down Expand Up @@ -70,8 +63,6 @@ def POST(self, url=None, username=None, password=None):
"failure_message": failure_message,
"status_code": status_code,
"url": url,
"app_url": app_url,
"app_name": self.name,
"tags": head_tags,
"username": username,
"password": password
Expand Down
1 change: 0 additions & 1 deletion apps/ip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def GET(self, *_args, **_kwargs):
external_ip
),
"html": ("ip.jinja.html", {
"app_name": self.name,
"client_ip": client_ip,
"external_ip": external_ip,
})
Expand Down
6 changes: 0 additions & 6 deletions apps/later/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ def GET(self, *_args, **kwargs):
tags = bookmark["tags"]
comments = bookmark["comments"]

app_url = cherrypy.engine.publish(
"url:internal"
).pop()

bookmarks_url = cherrypy.engine.publish(
"url:internal",
"/bookmarks"
Expand All @@ -81,13 +77,11 @@ def GET(self, *_args, **kwargs):
return {
"html": ("later.jinja.html", {
"bookmarks_url": bookmarks_url,
"app_url": app_url,
"error": error,
"bookmark": bookmark,
"title": title,
"url": url,
"tags": tags,
"comments": comments,
"app_name": self.name
})
}
1 change: 0 additions & 1 deletion apps/phone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ def GET(self, *_args, **kwargs):
"comment": state_lookup[2],
"state_name": state_name_lookup[1],
"sparql": sparql,
"app_name": self.name
})
}
1 change: 0 additions & 1 deletion apps/redirect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def GET(self, *_args, **kwargs):

return {
"html": ("redirect.jinja.html", {
"app_name": self.name,
"dest": url
})
}
4 changes: 0 additions & 4 deletions apps/registry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ def GET(self, *_args, **kwargs):
"registry:list_keys",
).pop()

app_url = cherrypy.engine.publish("url:internal").pop()

view = "search"
if key:
view = "add"

return {
"html": ("registry.jinja.html", {
"app_url": app_url,
"q": q,
"uid": uid,
"entries": entries,
"app_name": self.name,
"view": view,
"key": key,
"glossary": glossary,
Expand Down
4 changes: 0 additions & 4 deletions apps/reminder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ def GET(self, *_args, **_kwargs):
"notifier:send"
).pop()

app_url = cherrypy.engine.publish("url:internal").pop()

return {
"html": ("reminder.jinja.html", {
"app_name": self.name,
"templates": templates,
"upcoming": upcoming,
"app_url": app_url,
}),
}

Expand Down
6 changes: 0 additions & 6 deletions apps/speak/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ def GET(self, *_args, **_kwargs):
application.
"""
app_url = cherrypy.engine.publish(
"url:internal"
).pop()

can_speak = cherrypy.engine.publish("speak:can_speak").pop()

return {
"html": ("speak.jinja.html", {
"app_name": self.name,
"app_url": app_url,
"can_speak": can_speak
})
}
Expand Down
3 changes: 0 additions & 3 deletions apps/startpage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def edit_page(self, page_name, page_content=None):

return {
"html": ("edit.jinja.html", {
"app_name": self.name,
"button_label": button_label,
"cancel_url": cancel_url,
"page_name": page_name or "",
Expand Down Expand Up @@ -103,7 +102,6 @@ def render_page(self, page_name, page_record):
return {
"etag_key": page_name,
"html": ("startpage.jinja.html", {
"app_name": self.name,
"created": page_record["created"],
"anonymizer_url": anonymizer_url,
"edit_url": edit_url,
Expand Down Expand Up @@ -175,7 +173,6 @@ def GET(self, *args, **kwargs):

return {
"html": ("postedit.jinja.html", {
"app_name": self.name,
"page_url": page_url
})
}
Expand Down
2 changes: 0 additions & 2 deletions apps/transform/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def GET(self, *_args, **_kwargs):
"json": {"transforms": self.list_of_transforms()},
"text": "\n".join(self.list_of_transforms()),
"html": ("transform.jinja.html", {
"app_name": self.name,
"transforms": self.list_of_transforms()
})
}
Expand All @@ -74,7 +73,6 @@ def POST(self, transform, value):
"json": {"result": result},
"text": result,
"html": ("transform.jinja.html", {
"app_name": self.name,
"result": result,
"current_transform": transform,
"transforms": self.list_of_transforms(),
Expand Down
2 changes: 0 additions & 2 deletions apps/visitors/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def GET(self, *_args, **kwargs):
"durations": durations,
"site_domains": site_domains,
"saved_queries": saved_queries,
"app_name": self.name,
"annotations": annotations,
"app_url": cherrypy.engine.publish("url:internal").pop(),
"cookies": cookies
})
}
Expand Down
1 change: 0 additions & 1 deletion apps/weather/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def GET(self, *_args, **_kwargs):

return {
"html": ("weather.jinja.html", {
"app_name": self.name,
"forecasts": forecasts
})
}
Expand Down
5 changes: 1 addition & 4 deletions apps/whois/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def GET(self, *args, **kwargs):

if not address:
return {
"html": ("whois.jinja.html", {
"app_name": self.name
})
"html": ("whois.jinja.html", {})
}

address_unquoted = urllib.parse.unquote_plus(address).lower()
Expand Down Expand Up @@ -95,7 +93,6 @@ def GET(self, *args, **kwargs):
"ip_address": ip_address,
"whois": whois,
"ip_facts": facts,
"app_name": self.name,
"visitors_url": visitors_url,
"earliest_visit": visit_days.get("earliest"),
"latest_visit": visit_days.get("latest"),
Expand Down
3 changes: 3 additions & 0 deletions tools/negotiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def render_html(self, body):
if not template_file:
return None

values["app_name"] = cherrypy.request.app.root.name
values["app_url"] = cherrypy.engine.publish("url:internal").pop()

template = cherrypy.engine.publish(
"lookup-template",
template_file
Expand Down

0 comments on commit 64d1550

Please sign in to comment.