From ca101418439a8682da70c06df31b2b2fbf8e6683 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 18 Nov 2023 13:21:38 +1100 Subject: [PATCH] feat: Add option for selecting template --- main.py | 13 +++++-- sites/slds.py | 23 ++++++------ sites/sldserver.py | 2 +- sites/website.py | 18 ++++++++-- templates/city-old.html | 79 +++++++++++++++++++++++++++++++++++++++++ templates/city.html | 57 +++++++++++++---------------- templates/edit.html | 5 +++ 7 files changed, 150 insertions(+), 47 deletions(-) create mode 100644 templates/city-old.html diff --git a/main.py b/main.py index f654e5f..09d348a 100644 --- a/main.py +++ b/main.py @@ -33,6 +33,9 @@ if IMAGE_LOCATION == None: random_sites = "" +# Templates available for user +templates = ['Standard', 'Original'] + #Assets routes @app.route('/assets/') def assets(path): @@ -134,6 +137,7 @@ def edit(): fg_colour = "" text_colour = "" email = "" + template = "" if 'data' in data: html = data['data'].encode('utf-8').decode('unicode-escape') @@ -165,10 +169,14 @@ def edit(): if 'email' in data: email = data['email'] + if 'template' in data: + selected_template = data['template'] + + return render_template('edit.html',account=user['email'],account_link="account",account_link_name="Account",data=html, hns=hns,btc=btc,eth=eth,hnschat=hnschat,email=email,location=location,avatar=avatar, - bg_colour=bg_colour,fg_colour=fg_colour,text_colour=text_colour, - CITY_DOMAIN=CITY_DOMAIN,domain=user['domain']) + bg_colour=bg_colour,fg_colour=fg_colour,text_colour=text_colour,templates=templates, + selected_template=selected_template,CITY_DOMAIN=CITY_DOMAIN,domain=user['domain']) @app.route('/edit', methods=['POST']) @@ -196,6 +204,7 @@ def send_edit(): data['fg_colour'] = request.form['fg_colour'] data['text_colour'] = request.form['text_colour'] data['email'] = request.form['email'] + data['template'] = request.form['template'] # Convert to json data = json.dumps(data) diff --git a/sites/slds.py b/sites/slds.py index 291b3bd..3c6dc00 100644 --- a/sites/slds.py +++ b/sites/slds.py @@ -54,17 +54,20 @@ def catch_all(path): def not_found(e): return redirect('/') -def clean_template(): +def clean_templates(): # Clean template - with open('templates/city.html') as f: - data = f.read() - - data = data.replace('#f1ffff', '{{fg_colour}}') - data = data.replace('#1fffff', '{{text_colour}}') - data = data.replace('#000000', '{{bg_colour}}') - # Save - with open('templates/city.html', 'w') as f: - f.write(data) + for file in os.listdir('templates'): + if file.endswith('.html'): + with open('templates/' + file) as f: + data = f.read() + + data = data.replace('#f1ffff', '{{fg_colour}}') + data = data.replace('#1fffff', '{{text_colour}}') + data = data.replace('#000000', '{{bg_colour}}') + # Save + with open('templates/' + file, 'w') as f: + f.write(data) + print("Cleaned " + file, flush=True) print("Cleaned template", flush=True) if __name__ == '__main__': diff --git a/sites/sldserver.py b/sites/sldserver.py index 536ff7e..3480f0b 100644 --- a/sites/sldserver.py +++ b/sites/sldserver.py @@ -25,7 +25,7 @@ class GunicornApp(BaseApplication): if __name__ == '__main__': print("Cleaning template...", flush=True) - slds.clean_template() + slds.clean_templates() workers = os.getenv('WORKERS') threads = os.getenv('THREADS') if workers is None: diff --git a/sites/website.py b/sites/website.py index 7e3ade5..aa9bf1f 100644 --- a/sites/website.py +++ b/sites/website.py @@ -66,9 +66,17 @@ def render(data,db_object): if email != "": email = "" + email + "" - - + if avatar != "": + avatar = "" + else: + avatar = "

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

" + 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) except Exception as e: return "

Invalid data


Please contact support


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


" + "" @@ -120,3 +128,9 @@ def generate_foreground_color(background_color): def rgb_to_hex(rgb_color): return "#{:02x}{:02x}{:02x}".format(*rgb_color) + +def get_template(template): + if template == "Original": + return "city-old.html" + + return "city.html" \ No newline at end of file diff --git a/templates/city-old.html b/templates/city-old.html new file mode 100644 index 0000000..96cf2f0 --- /dev/null +++ b/templates/city-old.html @@ -0,0 +1,79 @@ + + + + + + + ShakeCities + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
{{avatar|safe}}
+
+
+
+

{{hnschat|safe}}

+
+
+

{{email|safe}}

+
+
+

{{location|safe}}

+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+

{{data|safe}}

+
+
+
+
+

Powered by ShakeCities

+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/city.html b/templates/city.html index fb5b5d3..eb251d0 100644 --- a/templates/city.html +++ b/templates/city.html @@ -26,44 +26,37 @@ -
-
-
-
-
-
-
-

{{hnschat|safe}}

-
-
-

{{email|safe}}

-
-
-

{{location|safe}}

-
-
-
+
+
{{avatar|safe}}
+
+
+

{{hnschat|safe}}

-
-
-
- - - -
-
+
+

{{email|safe}}

+
+
+

{{location|safe}}

-
+

{{data|safe}}

+
+

Donate

+
+ + + +
+
diff --git a/templates/edit.html b/templates/edit.html index 533c110..34e8e41 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -49,6 +49,11 @@
+