[Answered ]-Django blocktrans and with tag – DRY approach

2👍

✅

Your HTML is always the same with a different temp_max_language_versions variable. Three ways around this:

1 – use an include:

{% if user.userprofile.subscription_category == subscription_type_free %}
    {% include 'path_to_include.html' with  temp_max_language_versions=max_language_versions_free_subscription %}
{% elif user.userprofile.subscription_category == subscription_type_03 %}
....

2 – OR you could add that to the category itself; some pseudo-code:

class SubscriptionCategory(...):

    @property
    def temp_max_language_versions(self):
         if self.type == 'something':
              return 'something_else'

3 – if it’s specific to the view, you could add that to the category via the view as well.

Leave a comment