feat: Hide address div if user has addresses
All checks were successful
Build Docker / Build Main Image (push) Successful in 23s
Build Docker / Build SLDs Image (push) Successful in 27s

This commit is contained in:
Nathan Woodburn 2023-11-18 14:44:06 +11:00
parent d2b78ea6cf
commit 5438235144
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 39 additions and 15 deletions

View File

@ -59,6 +59,11 @@ def render(data,db_object):
btc = "<img src='" + btc_icon + "' width='20px' height='25px' style='margin-right: 5px;'>" + btc btc = "<img src='" + btc_icon + "' width='20px' height='25px' style='margin-right: 5px;'>" + btc
if eth != "": if eth != "":
eth = "<img src='" + eth_icon + "' width='20px' height='30px' style='margin-right: 5px;'>" + eth eth = "<img src='" + eth_icon + "' width='20px' height='30px' style='margin-right: 5px;'>" + eth
hide_addresses = False
if hns == "" and btc == "" and eth == "":
hide_addresses = True
if hnschat != "": if hnschat != "":
hnschat = "<a href='https://hns.chat/#message:"+hnschat+"' target='_blank'><img src='"+hns_icon+"' width='20px' height='20px' style='margin-right: 5px;'>" + hnschat + "</a>" hnschat = "<a href='https://hns.chat/#message:"+hnschat+"' target='_blank'><img src='"+hns_icon+"' width='20px' height='20px' style='margin-right: 5px;'>" + hnschat + "</a>"
if location != "": if location != "":
@ -71,23 +76,42 @@ def render(data,db_object):
else: else:
avatar = "<h1 style='color:"+fg_colour+";'>" + request.host.split(':')[0] + "/</h1>" avatar = "<h1 style='color:"+fg_colour+";'>" + request.host.split(':')[0] + "/</h1>"
template = "Standard"
if 'template' in db_object: if 'template' in db_object:
if db_object['template'] != "": if db_object['template'] != "":
return render_template(get_template(db_object['template']),bg_colour=bg_colour,text_colour=text_colour, 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, fg_colour=fg_colour, avatar=avatar,main_domain=main_domain,
hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, hnschat=hnschat,email=email,location=location, hns_icon=hns_icon,
hns=hns,btc=btc,eth=eth, data=html) hns=hns,btc=btc,eth=eth, data=html)
except Exception as e: except Exception as e:
return "<h1>Invalid data</h1><br><h2>Please contact support</h2><br><p>This can often be fixed by saving your site again in the editor</p><br>" + "<script>console.log('" + str(e).replace('\'','') + "');</script>" return "<h1>Nothing here yet</h1>" + "<script>console.log('" + str(e).replace('\'','') + "');</script>"
return render_template('city.html',bg_colour=bg_colour,text_colour=text_colour, def get_template_without_address(template):
fg_colour=fg_colour, avatar=avatar,main_domain=main_domain, file = "templates/" +get_template_file(template)
hnschat=hnschat,email=email,location=location, hns_icon=hns_icon, with open(file) as f:
hns=hns,btc=btc,eth=eth, data=html) 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_contrast_ratio(color1, color2):
@ -129,7 +153,7 @@ def generate_foreground_color(background_color):
def rgb_to_hex(rgb_color): def rgb_to_hex(rgb_color):
return "#{:02x}{:02x}{:02x}".format(*rgb_color) return "#{:02x}{:02x}{:02x}".format(*rgb_color)
def get_template(template): def get_template_file(template):
if template == "Original": if template == "Original":
return "city-old.html" return "city-old.html"

View File

@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<div class="col text-center align-self-center m-auto"> <div class="col text-center align-self-center m-auto">
<div class="d-xl-flex align-items-xl-center" style="background: #f1ffff;padding: 10px;border-radius: 10px;"> <div class="d-xl-flex align-items-xl-center" id="addresses" style="background: #f1ffff;padding: 10px;border-radius: 10px;">
<div> <div>
<div> <div>
<p style="font-size: 24px;margin-bottom: 0px;"><a href="/.well-known/wallets/HNS" target="_blank">{{hns|safe}}</a></p> <p style="font-size: 24px;margin-bottom: 0px;"><a href="/.well-known/wallets/HNS" target="_blank">{{hns|safe}}</a></p>

View File

@ -43,7 +43,7 @@
<div style="background: #f1ffff;border-radius: 10px;padding: 25px;padding-top: 2%;padding-left: 2%;padding-right: 2%;padding-bottom: 2%;margin: 22px;"> <div style="background: #f1ffff;border-radius: 10px;padding: 25px;padding-top: 2%;padding-left: 2%;padding-right: 2%;padding-bottom: 2%;margin: 22px;">
<p style="font-size: 24px;">{{data|safe}}</p> <p style="font-size: 24px;">{{data|safe}}</p>
</div> </div>
<div class="text-center" style="background: #f1ffff;padding: 25px;border-radius: 10px;margin: 22px;"> <div class="text-center" id="addresses" style="background: #f1ffff;padding: 25px;border-radius: 10px;margin: 22px;">
<h1>Donate</h1> <h1>Donate</h1>
<div> <div>
<div> <div>