Skip to content

Commit

Permalink
Make the profile page customisable
Browse files Browse the repository at this point in the history
  • Loading branch information
janbaykara committed Jul 14, 2022
1 parent f93e18a commit 6b546c9
Show file tree
Hide file tree
Showing 13 changed files with 6,503 additions and 1,031 deletions.

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion app/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wagtail.contrib.settings.models import BaseSetting, register_setting
from wagtailautocomplete.edit_handlers import AutocompletePanel

from app.models.wagtail import BookPage, create_streamfield
from app.models.wagtail import BookPage, YourBooks, create_streamfield


@register_setting(icon="users")
Expand All @@ -15,5 +15,15 @@ class MembershipJourney(BaseSetting):
panels = [StreamFieldPanel("welcome_content")]


@register_setting(icon="users")
class MemberProfilePage(BaseSetting):
profile_page_content = create_streamfield(
[
("your_book_list", YourBooks()),
]
)
panels = [StreamFieldPanel("profile_page_content")]


def settings_path(custom_settings_cls):
return f"/admin/settings/{custom_settings_cls._meta.app_label}/{custom_settings_cls._meta.model_name}"
14 changes: 10 additions & 4 deletions app/models/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,20 @@ def gift_giver_subscription(self):
if related_subscription_id:
return djstripe.models.Subscription.get(id=related_subscription_id)

def current_book(self):
from app.models.wagtail import BookPage

@property
def book_types(self):
book_types = self.metadata.get("book_types", None)
if book_types is not None:
book_types = book_types.split(",")
return book_types
return list()

def current_book(self):
from app.models.wagtail import BookPage

if self.book_types is not None and len(self.book_types) > 0:
return (
BookPage.objects.filter(type__in=book_types)
BookPage.objects.filter(type__in=self.book_types)
.order_by("-published_date")
.first()
)
Expand Down
6 changes: 6 additions & 0 deletions app/models/wagtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,12 @@ def get_context(self, value, parent_context=None):
return context


class YourBooks(BookGridBlock):
class Meta:
template = "app/blocks/your_books_grid_block.html"
icon = "fa fa-book"


class SingleBookBlock(blocks.StructBlock):
book = blocks.PageChooserBlock(
page_type="app.bookpage",
Expand Down
3 changes: 0 additions & 3 deletions app/templates/account/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ <h1>{% user_display request.user %}</h1>
<li class="{% block account_nav_profile %}{% endblock %}">
<a class='nav-link {% active_link "account_membership" %}' href="{% url 'account_membership' %}">{% trans 'Membership' %}</a>
</li>
<li class="{% block account_nav_billing_shipping %}{% endblock %}">
<a class='nav-link {% active_link "billing_shipping" %}' href="{% url 'billing_shipping' %}">{% trans 'Billing/Shipping' %}</a>
</li>
<li class="{% block account_nav_gift_cards %}{% endblock %}">
<a class='nav-link {% active_link "gift_cards" %}' href="{% url 'gift_cards' %}">{% trans 'Gift Cards' %}</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/account/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h3 class='my-4 text-center'>Thinking of cancelling?</h3>
<div class='d-flex flex-column justify-content-center align-items-center my-4'>
{% include "app/includes/membership_card.html" %}
</div>
{% get_books since=user.active_subscription.created as books %}
{% get_books since=user.active_subscription.created types=user.primary_product.book_types as books %}
{% if books|length > 0 %}
<section class='container my-5'>
<div class='row text-center my-4'>
Expand Down
174 changes: 154 additions & 20 deletions app/templates/account/membership.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,159 @@
{% extends "account/base.html" %}
{% load account django_bootstrap5 gravatar setting gift_card %}

{% block account_content %}
<div>
{% if user.is_member %}
<div class='d-flex flex-column justify-content-center align-items-center'>
{% include "app/includes/membership_card.html" %}
<br /><br />
{% if not user.active_subscription.cancel_at %}
{% url "cancel_membership" as cancellation_url %}
<br />
{% bootstrap_button size='sm' button_class='btn-outline-danger' href=cancellation_url content="Cancel membership" %}
{% extends "base.html" %}
{% load active_link_tags wagtailsettings_tags account django_bootstrap5 gravatar setting gift_card i18n %}

{% block content_padding %}py-5{% endblock %}

{% block content_width %} {% endblock %}

{% block content_extra_classes %}bg-white{% endblock %}

{% block content %}

<div class='container' style='max-width: 960px'>

<header class='mb-3'>

<div class='d-md-flex align-items-center tw-justify-center md:tw-justify-start tw-text-center md:tw-text-left'>
<img src="{% gravatar_url user.email 150 %}" style="width: 150px; height: 150px;" class='rounded-full bg-light mb-3 overflow-hidden md:tw-mr-3' />
<div>
<div class='h3'>{% user_display request.user %}</div>
{% if user.has_never_subscribed %}
<a href="/join" class='d-inline-block badge rounded-pill bg-warning fs-7 tw-tracking-normal text-black tw-no-underline'>
Finish signup
</a>
{% elif user.is_expired_member %}
<div class='text-secondary'>Expired member</div>
{% elif user.is_member %}
<div class='text-secondary'>
Member
</div>
{% endif %}

</div>
</div>

<br />

<ul class="nav nav-tabs">
<li class="{% block account_nav_profile %}{% endblock %}">
<a class='nav-link {% active_link "account_membership" %}' href="{% url 'account_membership' %}">{% trans 'Membership' %}</a>
</li>
<li class="{% block account_nav_gift_cards %}{% endblock %}">
<a class='nav-link {% active_link "gift_cards" %}' href="{% url 'gift_cards' %}">{% trans 'Gift Cards' %}</a>
</li>
<li class="{% block account_nav_email %}{% endblock %}">
<a class='nav-link {% active_link "account_email" %}' href="{% url 'account_email' %}">{% trans 'Email' %}</a>
</li>
<li class="{% block account_nav_change_password %}{% endblock %}">
<a class='nav-link {% active_link "account_change_password" %}' href="{% url 'account_change_password' %}">{% trans 'Password' %}</a>
</li>
</ul>
</header>

{% if user.is_member %}
{% get_settings %}
{% if settings.app.MemberProfilePage.profile_page_content %}
{% include "app/includes/layout.html" with streamfield=settings.app.MemberProfilePage.profile_page_content %}
{% endif %}

{% if request.user.is_member or request.user.gifts_bought|length > 0 %}
<div class='row'>
{% if request.user.is_member %}
<div class='col-md-6'>
<section>
<h3>
Shipping
</h3>
{% for key, line in request.user.shipping_address.items %}
{% if line %}
{{ line }}<br />
{% endif %}
{% endfor %}
<div class='my-4'>
{% url "customerportal" as portal_url %}
{% bootstrap_button button_class='btn-secondary' href=portal_url content="Update shipping" %}
</div>
</section>
</div>
{% endif %}
</div>
{% else %}
<h3 class='fw-light text-center'>
You're not a member at the moment.
</h3>
<div class='my-4 text-center'>
{% bootstrap_button href="/join" content="Become a member" %}

<section class='col-md-6'>
{% if request.user.is_member %}
<h3>
Billing
</h3>
{% for si in user.active_subscription.items.all %}
<div class='row'>
<div class='col'>{{ si.plan.product.name }}</div><div class='col'>{{ si.plan.human_readable_price }}</div>
</div>
{% endfor %}
{% if user.active_subscription.discount.coupon %}
<div class='row'>
<div class='col'>Discount</div><div class='col'>{{ user.active_subscription.discount.coupon.percent_off }}% off</div>
</div>
{% endif %}
{% endif %}
<div class='my-4'>
{% url "customerportal" as portal_url %}
{% bootstrap_button button_class='btn-secondary' href=portal_url content="Update billing" %}
</div>

{% if not user.active_subscription.cancel_at %}
{% url "cancel_membership" as cancellation_url %}
<div class='my-4'>
{% bootstrap_button button_class='btn-outline-danger' href=cancellation_url content="Cancel membership" %}
</div>
{% endif %}

{% if request.user.gifts_bought|length > 0 %}
<section class='card'>
<div class="card-body">
<h4>
Gift cards you're paying for
</h4>
{% for subscription in request.user.gifts_bought %}
<hr />
<div class='my-4 w-100 d-flex flex-column align-items-center justify-content-center'>
{% include "app/includes/gift_card.html" with subscription=subscription %}
</div>
{% if subscription.status != 'active' %}
<h5>Not active / no charge</h3>
{% else %}
{% for si in subscription.items.all %}
<div class='row'>
<div class='col'>{{ si.plan.product.name }}</div><div class='col'>{{ si.plan.human_readable_price }}</div>
</div>
{% endfor %}
{% if subscription.discount.coupon %}
<div class='row'>
<div class='col'>Discount</div><div class='col'>{{ subscription.discount.coupon.percent_off }}% off</div>
</div>
{% endif %}
{% endif %}
<div class='text-center'>
{% if not subscription.cancel_at %}
{% url "cancel_membership" subscription_id=subscription.id as cancellation_url %}
{% bootstrap_button size='sm' button_class='btn-outline-danger' href=cancellation_url content="Cancel gift card" %}
{% endif %}
</div>
{% endfor %}
</div>
</section>
{% endif %}
</section>
</div>
{% endif %}
{% else %}
<h3 class='fw-light text-center'>
You're not a member at the moment.
</h3>
<div class='my-4 text-center'>
{% bootstrap_button href="/join" content="Become a member" %}
<br /><br />
{% bootstrap_button href="/join?gift_mode=true" content="Buy a gift card" %}
</div>
{% endif %}

</div>

{% endblock %}
1 change: 1 addition & 0 deletions app/templates/app/blocks/list_item_block.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load django_bootstrap5 wagtailimages_tags %}
<article class='{{class}}'>
{{background_color}}
<div class='p-3 {% firstof background_color "bg-white" %} h-100 d-flex flex-column'>
<h5 class='fw-bold'>{{ value.title }}</h5>
<div class='text-center my-3'>
Expand Down
14 changes: 14 additions & 0 deletions app/templates/app/blocks/your_books_grid_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load books %}
{% get_books since=user.active_subscription.created types=user.primary_product.book_types as books %}
{% if books|length > 0 %}
<section class='my-4'>
<div class='row my-4'>
<h3>Books you've received</h3>
</div>
<div class='row align-items-center g-1'>
{% for book in books %}
{% include "app/includes/simple_book_card.html" with book=book class='col-12 col-sm-6 col-md-4 col-lg-3 col-xl-2' %}
{% endfor %}
</div>
</section>
{% endif %}
6 changes: 3 additions & 3 deletions app/templates/app/confirm_shipping.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ <h1 class="h2 fw-bold text-center">
<header class='p-3'>
<h5 class='mb-0'>
{% if gift_mode %}
This month's book
Your next book delivery
{% else %}
Your book this month
Your next book delivery
{% endif %}
</h5>
<p class='mb-0 text-muted'>And a new book <b>{{ price.plan.delivery_frequency }}</b></p>
<p class='mb-0 text-muted'>And then every <b>{{ price.plan.delivery_frequency }}</b></p>
</header>
{% include "app/includes/simple_book_card.html" with book=current_book %}
</article>
Expand Down
4 changes: 3 additions & 1 deletion app/templatetags/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@


@register.simple_tag
def get_books(since=None):
def get_books(since=None, types=None):
qs = (
BookPage.objects.live()
.order_by("-published_date")
.filter(published_date__isnull=False)
)
if since:
qs = qs.filter(published_date__gte=since)
if types and len(types) > 0:
qs = qs.filter(type__in=types)
return qs
5 changes: 0 additions & 5 deletions app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
LoginRequiredTemplateView.as_view(template_name="account/membership.html"),
name="account_membership",
),
path(
"accounts/billing-and-shipping/",
LoginRequiredTemplateView.as_view(template_name="account/billing.html"),
name="billing_shipping",
),
path(
"accounts/gift-cards/",
LoginRequiredTemplateView.as_view(template_name="account/gifts.html"),
Expand Down
Loading

0 comments on commit 6b546c9

Please sign in to comment.