def _flag_is_active_for_user(flag, user=None, **kwargs): if flag.staff and user.is_staff: return True if flag.superusers and user.is_superuser: return True flag_users = cache.get(keyfmt(get_setting('FLAG_USERS_CACHE_KEY'), flag.name)) if flag_users is None: flag_users = flag.users.all() cache_flag(instance=flag) if user in flag_users: return True flag_groups = cache.get(keyfmt(get_setting('FLAG_GROUPS_CACHE_KEY'), flag.name)) if flag_groups is None: flag_groups = flag.groups.all() cache_flag(instance=flag) user_groups = user.groups.all() for group in flag_groups: if group in user_groups: return True
def _get_flag(flag_name): flag = cache.get(keyfmt(get_setting('FLAG_CACHE_KEY'), flag_name)) if flag is None: try: flag = Flag.objects.get(name=flag_name) cache_flag(instance=flag) except Flag.DoesNotExist: flag = None return flag