def get_layout(request): all_slugs = set(_ADD_ONS.keys()) layout_slugs = set( [slug for section in _LAYOUT for slug in section['slugs']]) if all_slugs != layout_slugs: difference = ", ".join(all_slugs ^ layout_slugs) if all_slugs - layout_slugs: raise AddOnNotFoundException( "Add-ons not in layout: {}".format(difference)) raise AddOnNotFoundException( "Add-ons in layout do not exist: {}".format(difference)) return [ dict( { 'add_ons': [{ 'slug': slug, 'name': _ADD_ONS[slug].name, 'description': _ADD_ONS[slug].description, 'help_link': _ADD_ONS[slug].help_link, 'upgrade_text': _ADD_ONS[slug].upgrade_text, 'show_upgrade': (not _ADD_ONS[slug].has_privilege(request) and _ADD_ONS[slug].upgrade_text is not None), } for slug in section['slugs'] if _ADD_ONS[slug].has_privilege(request) or _ADD_ONS[slug].upgrade_text is not None] }, **section) for section in _LAYOUT ]
def show(slug, request, app, module=None, form=None): if slug not in _ADD_ONS: raise AddOnNotFoundException(slug) add_on = _ADD_ONS[slug] # Do not show if there's a required privilege missing if not add_on.has_privilege(request): return False # Show if flag to enable all toggles is on if toggles.ENABLE_ALL_ADD_ONS.enabled_for_request(request): return True if _grandfathered(slug, app): return True # Show if add-on has been enabled for app show = slug in app.add_ons and app.add_ons[slug] # Show if add-on is also a feature preview this domain has on # (that has not been turned off for this app specifically) if slug not in app.add_ons: previews = feature_previews.previews_dict(app.domain) if slug in previews: show = show or previews[slug] # Show if add-on is being used by the current form/module if form: show = show or add_on.used_in_form(form) elif module: show = show or add_on.used_in_module(module) return show