Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a product group type dropdown when creating/editing them #1326

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

lukegb
Copy link
Contributor

@lukegb lukegb commented Jan 23, 2024

Resolves #1322.

...also fix a bug when viewing payments in the admin panel where it reports "is not None" as an error because "is" has a specific meaning in Jinja2.

It's still just a free text thing in the database.

Fixes #1322.
"is not None" is not a valid Jinja2 test; "is not none" is, because "none" is
the name of a Jinja2 test.
Comment on lines +204 to +211
product_group_type = PRODUCT_GROUP_TYPES_DICT.get(
product.parent.type
)
purchase_cls = (
product_group_type.purchase_cls
if product_group_type
else Purchase
)
Copy link
Contributor

@jayaddison jayaddison Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could combine these two, by providing a dict lookup fallback/default?

[ removed to prevent accidental commit ]

(although arguably less clear, partly due to the text wrapping to fit within line limits)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind; I see that there's an additional level of indirection for the purchase_cls lookup. Hrm. I'll ponder that a bit, but this seems OK as-is, and my suggestion's not valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the purchase class is an attribute on the thing in the dict, rather than directly being an element of it, so this doesn't work in and of itself.

@@ -16,7 +16,7 @@ <h2>Payment {{ payment.id }}</h2>
{% endif %}
{% if payment.provider == 'banktransfer' and payment.state == 'inprogress' %}
<a class="btn btn-primary" href="{{ url_for('.reset_expiry', payment_id=payment.id) }}">Reset expiry</a>
<a class="btn btn-warning {% if payment.reminder_sent_at is not None -%} disabled {%- endif %}" href="{{ url_for('.send_reminder', payment_id=payment.id) }}">Remind</a>
<a class="btn btn-warning {% if payment.reminder_sent_at is not none -%} disabled {%- endif %}" href="{{ url_for('.send_reminder', payment_id=payment.id) }}">Remind</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is none was news to me, but yep, that checks out - nice find.

purchase_cls: type[Purchase]


PRODUCT_GROUP_TYPES = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm muddling my way back through the design factors for the change: is there a reason these should go here instead of alongside the similar-ish constants in purchase.py?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That list doesn't seem to be used at all, so it can probably be removed.

The root issue here is that there's inevitable duplication because we have a polymorphic type hierarchy under Purchase. Which of those Purchase types is created is determined by the Product's ProductGroup.type. And the point of #1214 (I haven't checked how relevant it still is) is that we should probably only be checking one of those.

Anyway I'm happy that this PR is a net improvement to the situation.

@russss russss enabled auto-merge (rebase) January 23, 2024 22:34
@russss russss merged commit 3dba199 into main Jan 23, 2024
2 checks passed
@russss russss deleted the lukegb/validate-product-group-type branch January 23, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProductGroup type should be validated on creation
3 participants