refactor out custom madness in favor of sanity.

getting rid of app_url because it was a strange wrapper around
request.host_url & doesn't seem to provide any value except to confuse
the code. eliminated it.

in the process touched up some comments & email templates.

	modified:   make_post_sell/lib/mail.py
	modified:   make_post_sell/lib/mail_messages.py
	modified:   make_post_sell/models/product.py
	modified:   make_post_sell/models/shop.py
	modified:   make_post_sell/request_methods.py
	modified:   make_post_sell/templates/base.j2
	modified:   make_post_sell/templates/product_edit.j2
This commit is contained in:
Russell Ballestrini 2022-07-05 12:43:02 -04:00
parent 6426be4d27
commit 82ae89d244
7 changed files with 36 additions and 42 deletions

View file

@ -76,10 +76,10 @@ def send_purchase_email(request, to_email, products, total_cost):
product_text = "<br/>".join(product_text_list)
message_text = PURCHASE_1_TEXT.format(
"%.2f" % total_cost, request.app_url
"%.2f" % total_cost, request.host_url
)
message_html = PURCHASE_1_HTML.format(
subject, request.app_url, product_text, "%.2f" % total_cost
subject, request.host_url, product_text, "%.2f" % total_cost
)
send_pyramid_email(request, to_email, subject, message_text, message_html)
@ -119,10 +119,10 @@ def send_sale_email(request, shop, products, total_cost):
product_text = "<br/>".join(product_text_list)
message_text = SALE_1_TEXT.format(
"%.2f" % total_cost, request.app_url
"%.2f" % total_cost, shop.absolute_sales_url(request)
)
message_html = SALE_1_HTML.format(
subject, request.app_url, shop.id, product_text, "%.2f" % total_cost
subject, shop.absolute_sales_url(request), product_text, "%.2f" % total_cost
)
# send a separate email for each shop owner.

View file

@ -40,7 +40,7 @@ Thank you very much!
"""
# 0: subject,
# 1: request.app_url,
# 1: request.host_url,
# 2: product_text,
# 3: total_cost,
@ -99,10 +99,9 @@ Great job!
"""
# 0: subject,
# 1: request.app_url,
# 2: shop.id,
# 3: product_text,
# 4: total_cost,
# 1: shop.absolute_sales_url
# 2: product_text,
# 3: total_cost,
SALE_1_HTML = """
<!DOCTYPE html>
@ -116,12 +115,12 @@ SALE_1_HTML = """
You made a <u>sale</u>!
</h2>
<b>${4}</b>
<b>${3}</b>
{3}
{2}
<p>
You may view <a href="{1}/s/{2}/sales" style="font-weight: bold;" target="_blank">all your sales</a> at any time.
You may view <a href="{1}" style="font-weight: bold;" target="_blank">all your sales</a> at any time.
</p>
<p style="font-size: .8em;">
@ -130,8 +129,8 @@ SALE_1_HTML = """
</span>
<br>
<br>
<a href="{1}/s/{2}/sales" style="color: #439fe0; font-weight: normal; text-decoration: none; word-break: break-word;" target="_blank">
{2}/u/purchases
<a href="{1}" style="color: #439fe0; font-weight: normal; text-decoration: none; word-break: break-word;" target="_blank">
{1}
</a>
</p>

View file

@ -86,7 +86,10 @@ class Product(RBase, Base):
created_timestamp = Column(BigInteger, nullable=False)
updated_timestamp = Column(BigInteger, nullable=False)
# this value should be treated as immutable after object creation.
is_bundle = Column(Boolean, default=False, nullable=False)
# this value should be treated as immutable after object creation.
is_sellable = Column(Boolean, default=False, nullable=False)
# lazy="joined" performs a left join to reduce queries, it's magic.
@ -188,10 +191,13 @@ class Product(RBase, Base):
@property
def is_ready(self):
"""internal safety checks prior to allowing the sale of this product."""
if self.is_sellable:
if self.is_bundle:
return True if len(self.bundle_metadata["product-ids"]) >= 1 else False
return self.has_product_file
# content is always ready, for example a blog post only needs a title & description.
return True
@property
@ -331,11 +337,11 @@ class Product(RBase, Base):
For example:
https://makepostsell.com/p/product-uuid
https://my.makepostsell.com/p/product-uuid
"""
if slug:
return "{}/p/{}/{}".format(request.app_url, self.id, self.slug)
return "{}/p/{}".format(request.app_url, self.id)
return "{}/p/{}/{}".format(request.host_url, self.id, self.slug)
return "{}/p/{}".format(request.host_url, self.id)
def absolute_edit_url(self, request):
"""

View file

@ -145,6 +145,7 @@ class Shop(RBase, Base):
@property
def is_ready(self):
"""is the shop ready to accept charges?"""
if self.stripe_secret_api_key and self.stripe_public_api_key:
return True
return False
@ -226,11 +227,11 @@ class Shop(RBase, Base):
For example:
https://makepostsell.com/s/<shop-uuid>
https://my.makepostsell.com/s/<shop-uuid>
"""
if slug:
return "{}/s/{}/{}".format(request.app_url, self.id, self.slug)
return "{}/s/{}".format(request.app_url, self.id)
return "{}/s/{}/{}".format(request.host_url, self.id, self.slug)
return "{}/s/{}".format(request.host_url, self.id)
def absolute_settings_url(self, request):
"""
@ -238,9 +239,8 @@ class Shop(RBase, Base):
For example:
https://makepostsell.com/s/<shop-uuid>/edit
https://my.makepostsell.com/s/<shop-uuid>/settings
"""
return "{}/settings".format(self.absolute_url(request, slug=False))
def absolute_about_url(self, request):
@ -249,8 +249,9 @@ class Shop(RBase, Base):
For example:
https://makepostsell.com/s/<shop-uuid>/about
https://my.makepostsell.com/s/<shop-uuid>/about
"""
# why ure slug for this URL, is it for SEO?
return "{}/about".format(self.absolute_url(request))
def absolute_terms_url(self, request):
@ -259,6 +260,9 @@ class Shop(RBase, Base):
def absolute_privacy_policy_url(self, request):
return "{}/privacy-policy".format(self.absolute_url(request, slug=False))
def absolute_sales_url(self, request):
return "{}/sales".format(self.absolute_url(request, slug=False))
def set_description(self, new_description):
self.description = new_description
self.description_html = markdown_to_html(self.description)

View file

@ -129,22 +129,6 @@ def includeme(config):
"""Attach app settings dictionary."""
return app_settings
def add_app_url(request):
"""
Use the app_url from config if request.domain ends with the
configured root_domain. Otherwise just use the request's host_url
"""
config_app_url = request.app.get("app_url", request.host_url)
root_domain = request.app.get("root_domain")
if root_domain and request.domain.endswith(root_domain):
return config_app_url
elif request.domain == "localhost":
return config_app_url
return request.host_url
def add_app_domain(request):
return request.app_url.split("://")[-1].split(":")[0]
def add_secure_uploads_client(request):
"""returns an S3 compatible client."""
import boto3
@ -206,8 +190,6 @@ def includeme(config):
config.add_request_method(add_spam, "spam", reify=True)
config.add_request_method(add_app, "app", reify=True)
config.add_request_method(add_app_url, "app_url", reify=True)
config.add_request_method(add_app_domain, "app_domain", reify=True)
config.add_request_method(add_is_shop_domain, "is_shop_domain", reify=True)
config.add_request_method(add_is_saas_domain, "is_saas_domain", reify=True)

View file

@ -24,7 +24,7 @@
{% endif %}
{%- block append_to_head_tag_section %}
<title>{{ request.app_domain }}</title>
<title>{{ request.domain }}</title>
{% endblock %}
</head>

View file

@ -1,6 +1,9 @@
{% extends "base.j2" -%}
{%- block call_to_action -%}
<br/>
<br/>
permanent link: <a href="{{ product.absolute_url(request) }}">{{ product.absolute_url(request) }}</a>
{%- endblock call_to_action -%}
{% block content -%}