From 5438235144a020c00c12fe30e69e9ded61c3ac41 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 18 Nov 2023 14:44:06 +1100 Subject: [PATCH] feat: Hide address div if user has addresses --- sites/website.py | 50 ++++++++++++++++++++++++++++++----------- templates/city-old.html | 2 +- templates/city.html | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/sites/website.py b/sites/website.py index af6dbde..9703d50 100644 --- a/sites/website.py +++ b/sites/website.py @@ -59,6 +59,11 @@ def render(data,db_object): btc = "" + btc if eth != "": eth = "" + eth + + hide_addresses = False + if hns == "" and btc == "" and eth == "": + hide_addresses = True + if hnschat != "": hnschat = "" + hnschat + "" if location != "": @@ -71,25 +76,44 @@ def render(data,db_object): else: avatar = "

" + request.host.split(':')[0] + "/

" + template = "Standard" + if 'template' in db_object: if db_object['template'] != "": - return render_template(get_template(db_object['template']),bg_colour=bg_colour,text_colour=text_colour, - fg_colour=fg_colour, avatar=avatar,main_domain=main_domain, - hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, - hns=hns,btc=btc,eth=eth, data=html) + template = db_object['template'] + + if hide_addresses: + return render_template_string(get_template_without_address(template),bg_colour=bg_colour,text_colour=text_colour, + fg_colour=fg_colour, avatar=avatar,main_domain=main_domain, + hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, + hns=hns,btc=btc,eth=eth, data=html) + else: + return render_template(get_template_file(template),bg_colour=bg_colour,text_colour=text_colour, + fg_colour=fg_colour, avatar=avatar,main_domain=main_domain, + hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, + hns=hns,btc=btc,eth=eth, data=html) except Exception as e: - return "

Invalid data


Please contact support


This can often be fixed by saving your site again in the editor


" + "" - - - - return render_template('city.html',bg_colour=bg_colour,text_colour=text_colour, - fg_colour=fg_colour, avatar=avatar,main_domain=main_domain, - hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, - hns=hns,btc=btc,eth=eth, data=html) + return "

Nothing here yet

" + "" +def get_template_without_address(template): + file = "templates/" +get_template_file(template) + with open(file) as f: + data = f.read() + + # Read template + soup = BeautifulSoup(data, 'html.parser') + # Remove addresses div + try: + addresses = soup.find(id="addresses") + addresses.decompose() + finally: + # Return template without addresses + return str(soup) + + def calculate_contrast_ratio(color1, color2): def calculate_luminance(color): def adjust_color_value(value): @@ -129,7 +153,7 @@ def generate_foreground_color(background_color): def rgb_to_hex(rgb_color): return "#{:02x}{:02x}{:02x}".format(*rgb_color) -def get_template(template): +def get_template_file(template): if template == "Original": return "city-old.html" diff --git a/templates/city-old.html b/templates/city-old.html index 96cf2f0..333ad41 100644 --- a/templates/city-old.html +++ b/templates/city-old.html @@ -46,7 +46,7 @@
-
+

{{hns|safe}}

diff --git a/templates/city.html b/templates/city.html index d2a71de..6db7d53 100644 --- a/templates/city.html +++ b/templates/city.html @@ -43,7 +43,7 @@

{{data|safe}}

-
+

Donate