From 58bc8b4bca4a0272ea78294d8aa413598eaf75c6 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 23 Nov 2016 16:39:29 +0800 Subject: webui: Add "from_localhost" to IndexHandler and products template --- fg21sim/webui/handlers/index.py | 14 +++++++++++++- fg21sim/webui/templates/products.html | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fg21sim/webui/handlers/index.py b/fg21sim/webui/handlers/index.py index b351619..89d079d 100644 --- a/fg21sim/webui/handlers/index.py +++ b/fg21sim/webui/handlers/index.py @@ -11,6 +11,18 @@ from .base import BaseRequestHandler class IndexHandler(BaseRequestHandler): """ Index page handler of the Web UI. + + Attributes + ---------- + from_localhost : bool + ``True`` if the request is from the localhost, otherwise ``False``. """ + def initialize(self): + """Hook for subclass initialization. Called for each request.""" + if self.request.remote_ip == "127.0.0.1": + self.from_localhost = True + else: + self.from_localhost = False + def get(self): - self.render("index.html") + self.render("index.html", from_localhost=self.from_localhost) diff --git a/fg21sim/webui/templates/products.html b/fg21sim/webui/templates/products.html index e7c7427..a883565 100644 --- a/fg21sim/webui/templates/products.html +++ b/fg21sim/webui/templates/products.html @@ -25,12 +25,14 @@ + {% if from_localhost %}
+ {% end %}
-- cgit v1.2.2