From 03680800a896aaba7d78f6b2f1bbedeac0a1e387 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sat, 8 Jan 2022 12:00:03 -0500 Subject: [PATCH] Plausible Analytics and better Link Unfurling! modified: make_post_sell/models/shop.py new file: make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py modified: make_post_sell/templates/base.j2 modified: make_post_sell/templates/content.j2 modified: make_post_sell/templates/product.j2 modified: make_post_sell/templates/shop_settings.j2 renamed: make_post_sell/templates/snippets/google-analytics.j2 -> make_post_sell/templates/snippets/analytics.j2 modified: make_post_sell/views/shop.py --- make_post_sell/models/shop.py | 1 + ...39_plausible_domain_name_column_on_shop.py | 24 +++++++++++ make_post_sell/templates/base.j2 | 25 +++++------ make_post_sell/templates/content.j2 | 17 ++++++++ make_post_sell/templates/product.j2 | 17 ++++++++ make_post_sell/templates/shop_settings.j2 | 43 +++++++++++++------ .../{google-analytics.j2 => analytics.j2} | 4 ++ make_post_sell/views/shop.py | 7 +++ 8 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py rename make_post_sell/templates/snippets/{google-analytics.j2 => analytics.j2} (63%) diff --git a/make_post_sell/models/shop.py b/make_post_sell/models/shop.py index 8fbda50..f4cf8f4 100644 --- a/make_post_sell/models/shop.py +++ b/make_post_sell/models/shop.py @@ -52,6 +52,7 @@ class Shop(RBase, Base): # example: "UA-XX31XX60-3". google_analytics_id = Column(Unicode(32), nullable=True, default="") + plausible_domain_name = Column(Unicode(256), nullable=True, default="") # example: "cus_12345678AbCdEF" but may be null. # this is how the shop pays for make_post_sell. diff --git a/make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py b/make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py new file mode 100644 index 0000000..f5e03ce --- /dev/null +++ b/make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py @@ -0,0 +1,24 @@ +"""plausible_domain_name column on shop + +Revision ID: cdad5c220c39 +Revises: bfc4195a7f56 +Create Date: 2022-01-07 19:57:52.202252 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'cdad5c220c39' +down_revision = 'bfc4195a7f56' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('mps_shop', sa.Column('plausible_domain_name', sa.Unicode(length=256), nullable=True, server_default="")) + + +def downgrade(): + op.drop_column('mps_shop', 'plausible_domain_name') diff --git a/make_post_sell/templates/base.j2 b/make_post_sell/templates/base.j2 index 5e0df7b..722d9e5 100644 --- a/make_post_sell/templates/base.j2 +++ b/make_post_sell/templates/base.j2 @@ -7,31 +7,28 @@ {%- endif %} - {% block title %}{{ request.app_domain }}{% endblock %} - - - {% set theme_color = request.shop.ribbon_color_1 or "#5871ad" %} - - - - {% include 'snippets/google-analytics.j2' %} + {% include 'snippets/analytics.j2' %} + + {% set theme_color = request.shop.ribbon_color_1 or "#5871ad" %} + + + + {%- block append_to_head_tag_section %} - {% endblock append_to_head_tag_section %} - + {{ request.app_domain }} + {% endblock %} diff --git a/make_post_sell/templates/content.j2 b/make_post_sell/templates/content.j2 index dc2b2d9..0480f69 100644 --- a/make_post_sell/templates/content.j2 +++ b/make_post_sell/templates/content.j2 @@ -1,5 +1,22 @@ {% extends "base.j2" -%} +{%- block append_to_head_tag_section %} + + {{ product.title }} + + + + + {%- if "thumbnail1" in product.extensions %} + + {%- endif %} + +{%- endblock append_to_head_tag_section -%} + + {%- block call_to_action -%} {% if request.user.can_edit_shop(request.shop) %} ✎ Edit diff --git a/make_post_sell/templates/product.j2 b/make_post_sell/templates/product.j2 index fd4c800..744d744 100644 --- a/make_post_sell/templates/product.j2 +++ b/make_post_sell/templates/product.j2 @@ -1,5 +1,22 @@ {% extends "base.j2" -%} +{%- block append_to_head_tag_section %} + + {{ product.title }} + + + + + {%- if "thumbnail1" in product.extensions %} + + {%- endif %} + +{%- endblock append_to_head_tag_section -%} + + {%- block call_to_action -%} {% if request.user.can_edit_shop(request.shop) %} ✎ Edit diff --git a/make_post_sell/templates/shop_settings.j2 b/make_post_sell/templates/shop_settings.j2 index b6c789e..6c2ef2a 100644 --- a/make_post_sell/templates/shop_settings.j2 +++ b/make_post_sell/templates/shop_settings.j2 @@ -71,19 +71,6 @@

- - - -
-
-
+ + + + + +
+
+
diff --git a/make_post_sell/templates/snippets/google-analytics.j2 b/make_post_sell/templates/snippets/analytics.j2 similarity index 63% rename from make_post_sell/templates/snippets/google-analytics.j2 rename to make_post_sell/templates/snippets/analytics.j2 index 2394424..d398b57 100644 --- a/make_post_sell/templates/snippets/google-analytics.j2 +++ b/make_post_sell/templates/snippets/analytics.j2 @@ -1,3 +1,7 @@ +{% if request.shop and request.shop.domain_name and request.shop.plausible_domain_name %} + +{% endif %} + {% if request.shop and request.shop.google_analytics_id %} diff --git a/make_post_sell/views/shop.py b/make_post_sell/views/shop.py index 6f08afd..060dc8b 100644 --- a/make_post_sell/views/shop.py +++ b/make_post_sell/views/shop.py @@ -303,6 +303,7 @@ def shop_settings(request): ribbon_color_2 = request.params.get("ribbon_color_2", shop.ribbon_color_2) google_analytics_id = request.params.get("google_analytics_id", shop.google_analytics_id) + plausible_domain_name = request.params.get("plausible_domain_name", shop.plausible_domain_name) stripe_public_api_key = request.params.get("stripe_public_api_key", shop.stripe_public_api_key) stripe_secret_api_key = request.params.get("stripe_secret_api_key", shop.stripe_secret_api_key) @@ -374,6 +375,11 @@ def shop_settings(request): msg = ("You set the shop's Google Analytics Id.", "success") request.session.flash(msg) + if plausible_domain_name != shop.plausible_domain_name: + shop.plausible_domain_name = plausible_domain_name + msg = ("You set the shop's Plausible Analytics Domain Name.", "success") + request.session.flash(msg) + if stripe_public_api_key and stripe_public_api_key != shop.stripe_public_api_key: if stripe_public_api_key.startswith("pk_"): shop.stripe_public_api_key = stripe_public_api_key @@ -487,6 +493,7 @@ def shop_settings(request): "ribbon_color_1": ribbon_color_1, "ribbon_color_2": ribbon_color_2, "google_analytics_id": google_analytics_id, + "plausble_domain_name": plausible_domain_name, "stripe_public_api_key": stripe_public_api_key, "stripe_secret_api_key": stripe_secret_api_key, "signed_posts": signed_posts,