Exemplo n.º 1
0
 def test_session_details_view_toggles(self):
     toggles.all_toggles()
     data = json.dumps({'sessionId': self.session_key, 'domain': 'domain'})
     response = Client().post(self.url,
                              data,
                              content_type="application/json")
     self.assertEqual(200, response.status_code)
     expected_response = self.expected_response.copy()
     expected_response['enabled_toggles'] = ['FORM_LINK_WORKFLOW']
     expected_response['enabled_previews'] = ['CALC_XPATHS']
     self.assertJSONEqual(response.content, expected_response)
Exemplo n.º 2
0
    def _get_toggles_to_migrate(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from toggle.models import Toggle
        from toggle.shortcuts import namespaced_item

        all_user_ids = self._user_ids_in_domain()

        toggles_to_migrate = []
        domain_item = namespaced_item(self.domain, NAMESPACE_DOMAIN)

        for toggle in all_toggles() + all_previews():
            try:
                current_toggle = Toggle.get(toggle.slug)
            except ResourceNotFound:
                continue

            enabled_for = set(current_toggle.enabled_users)

            new_toggle = Toggle(slug=toggle.slug, enabled_users=[])
            if domain_item in enabled_for:
                new_toggle.enabled_users.append(domain_item)

            enabled_users = enabled_for & all_user_ids
            new_toggle.enabled_users.extend(list(enabled_users))

            if new_toggle.enabled_users:
                toggles_to_migrate.append(new_toggle.to_json())

        return toggles_to_migrate
Exemplo n.º 3
0
 def static_toggle(self):
     """
     Returns the corresponding toggle definition from corehq/toggles.py
     """
     for toggle in all_toggles():
         if toggle.slug == self.toggle_slug:
             return toggle
Exemplo n.º 4
0
    def _get_mocked_toggles(self):
        from toggle.models import generate_toggle_id
        from toggle.models import Toggle
        from toggle.shortcuts import namespaced_item

        mocked_toggles = {
            toggle.slug: Toggle(_id=generate_toggle_id(toggle.slug),
                                slug=toggle.slug)
            for toggle in random.sample(all_toggles(), 3)
        }
        toggles = mocked_toggles.values()
        domain_item = namespaced_item(self.domain_name, NAMESPACE_DOMAIN)
        toggles[0].enabled_users = [domain_item]
        toggles[1].enabled_users = ['user1', 'other-user', 'user2']
        toggles[2].enabled_users = [
            'user1', domain_item,
            namespaced_item('other_domain', NAMESPACE_DOMAIN)
        ]

        expected_items = {
            toggles[0].slug: [domain_item],
            toggles[1].slug: ['user1', 'user2'],
            toggles[2].slug: ['user1', domain_item],
        }

        return mocked_toggles, expected_items
Exemplo n.º 5
0
    def page_context(self):
        toggles = list(all_toggles())
        domain_counts = {}
        user_counts = {}
        if self.show_usage:
            for t in toggles:
                counter = Counter()
                try:
                    usage = Toggle.get(t.slug)
                except ResourceNotFound:
                    domain_counts[t.slug] = 0
                    user_counts[t.slug] = 0
                else:
                    for u in usage.enabled_users:
                        namespace = u.split(":", 1)[0] if u.find(":") != -1 else NAMESPACE_USER
                        counter[namespace] += 1
                    domain_counts[t.slug] = counter.get(NAMESPACE_DOMAIN, 0)
                    user_counts[t.slug] = counter.get(NAMESPACE_USER, 0)

        return {
            'domain_counts': domain_counts,
            'page_url': self.page_url,
            'show_usage': self.show_usage,
            'toggles': toggles,
            'tags': ALL_TAGS,
            'user_counts': user_counts,
        }
Exemplo n.º 6
0
 def static_toggle(self):
     """
     Returns the corresponding toggle definition from corehq/toggles.py
     """
     for toggle in all_toggles():
         if toggle.slug == self.toggle_slug:
             return toggle
Exemplo n.º 7
0
 def get_toggle(self):
     if not self.toggle_slug in [t.slug for t in all_toggles()]:
         raise Http404()
     try:
         return Toggle.get(self.toggle_slug)
     except ResourceNotFound:
         return Toggle(slug=self.toggle_slug)
Exemplo n.º 8
0
    def _get_toggles(self):
        def _sort_key(toggle):
            return (not (toggle['domain_enabled'] or toggle['user_enabled']),
                    toggle['tag_index'], toggle['label'])

        unsorted_toggles = [{
            'slug':
            toggle.slug,
            'label':
            toggle.label,
            'description':
            toggle.description,
            'help_link':
            toggle.help_link,
            'tag':
            toggle.tag.name,
            'tag_index':
            toggle.tag.index,
            'tag_description':
            toggle.tag.description,
            'tag_css_class':
            toggle.tag.css_class,
            'has_domain_namespace':
            toggles.NAMESPACE_DOMAIN in toggle.namespaces,
            'domain_enabled':
            toggle.enabled(self.domain, namespace=toggles.NAMESPACE_DOMAIN),
            'user_enabled':
            toggle.enabled(self.request.couch_user.username,
                           namespace=toggles.NAMESPACE_USER),
        } for toggle in toggles.all_toggles()]

        return sorted(unsorted_toggles, key=_sort_key)
Exemplo n.º 9
0
def set_toggle(slug, item, enabled, namespace=None):
    """
    Sets a toggle value explicitly. Should only save anything if the value needed to be changed.
    """
    if toggle_enabled(slug, item, namespace=namespace) != enabled:
        ns_item = namespaced_item(item, namespace)
        try:
            toggle_doc = Toggle.get(slug)
        except ResourceNotFound:
            toggle_doc = Toggle(slug=slug, enabled_users=[])
        if enabled:
            toggle_doc.add(ns_item)
        else:
            toggle_doc.remove(ns_item)
        from corehq.feature_previews import all_previews
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        static_toggles_by_slug = {
            t.slug: t
            for t in all_toggles() + all_previews()
        }
        if namespace == NAMESPACE_DOMAIN and slug in static_toggles_by_slug:
            static_toggle = static_toggles_by_slug[slug]
            if static_toggle.save_fn:
                static_toggle.save_fn(item, enabled)
        update_toggle_cache(slug, item, enabled, namespace)
Exemplo n.º 10
0
def _get_toggles_to_migrate(domain):
    from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
    from toggle.models import Toggle
    from toggle.shortcuts import namespaced_item

    domain_item = namespaced_item(domain, NAMESPACE_DOMAIN)
    usernames = set(get_all_usernames_by_domain(domain))

    for toggle in all_toggles() + all_previews():
        try:
            current_toggle = Toggle.get(toggle.slug)
        except ResourceNotFound:
            continue

        enabled_for = set(current_toggle.enabled_users)

        new_toggle = Toggle(slug=toggle.slug, enabled_users=[])
        if domain_item in enabled_for:
            new_toggle.enabled_users.append(domain_item)

        enabled_users = enabled_for & usernames
        new_toggle.enabled_users.extend(list(enabled_users))

        if new_toggle.enabled_users:
            yield new_toggle.to_json()
 def handle(self, *args, **options):
     toggle_map = dict([(t.slug, t) for t in all_toggles()])
     domains = [row['key'] for row in Domain.get_all(include_docs=False)]
     for domain in domains:
         if toggle_map['rich_text'].enabled(domain) or toggle_map['experimental_ui'].enabled(domain):
             #logger.info('migrating domain {}'.format(domain))
             apps = get_apps_in_domain(domain, include_remote=False)
             for app in apps:
                 app_dirty = False
                 builder = ParentCasePropertyBuilder(app)
                 relationships = builder.get_parent_type_map(app.get_case_types(), allow_multiple_parents=True)
                 for module in app.modules:
                     for form in module.forms:
                         if form.doc_type == 'Form' and form.requires_case():
                             #logger.info('migrating form {}'.format(form.name.get('en', form.name)))
                             base_case_type = form.get_module().case_type
                             self._replace_in_form(form, relationships, base_case_type, 0)
                             prefixes = re.findall(r'#case/\w+/', form.source)
                             prefixes = set(prefixes)
                             for p in prefixes:
                                 if p != "#case/parent/" and p != "#case/grandparent/":
                                     self._form_error(form, "Unknown prefix remaining: {}".format(p))
                             if options['save']:
                                 try:
                                     save_xform(form.get_app(), form, form.source)
                                     app_dirty = True
                                 except:
                                     self._form_error(form, "Form xml invalid")
                 if app_dirty:
                     app.save()
     logger.info('done with cmitfb_migrate_syntax')
Exemplo n.º 12
0
    def _get_toggles_to_migrate(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from toggle.models import Toggle
        from toggle.shortcuts import namespaced_item

        all_user_ids = self._user_ids_in_domain()

        toggles_to_migrate = []
        domain_item = namespaced_item(self.domain, NAMESPACE_DOMAIN)

        for toggle in all_toggles() + all_previews():
            try:
                current_toggle = Toggle.get(toggle.slug)
            except ResourceNotFound:
                continue

            enabled_for = set(current_toggle.enabled_users)

            new_toggle = Toggle(slug=toggle.slug, enabled_users=[])
            if domain_item in enabled_for:
                new_toggle.enabled_users.append(domain_item)

            enabled_users = enabled_for & all_user_ids
            new_toggle.enabled_users.extend(list(enabled_users))

            if new_toggle.enabled_users:
                toggles_to_migrate.append(new_toggle.to_json())

        return toggles_to_migrate
Exemplo n.º 13
0
def toggle_diff(request, domain):
    params = json_request(request.GET)
    other_domain = params.get('domain')
    diff = []
    if Domain.get_by_name(other_domain):
        diff = [{
            'slug': t.slug,
            'label': t.label,
            'url': reverse(ToggleEditView.urlname, args=[t.slug]),
            'tag_name': _('Preview'),
            'tag_css_class': 'default',
            'tag_index': -1,
        } for t in feature_previews.all_previews()
                if _can_copy_toggle(t, request.domain, other_domain)]
        diff.extend([{
            'slug': t.slug,
            'label': t.label,
            'url': reverse(ToggleEditView.urlname, args=[t.slug]),
            'tag_name': t.tag.name,
            'tag_css_class': t.tag.css_class,
            'tag_index': t.tag.index,
        } for t in toggles.all_toggles()
                     if _can_copy_toggle(t, request.domain, other_domain)])
        diff.sort(key=lambda x: (x['tag_index'], x['label']))
    return json_response(diff)
Exemplo n.º 14
0
 def enabled_flags(self):
     def _sort_key(toggle_enabled_tuple):
         return (not toggle_enabled_tuple[1], not toggle_enabled_tuple[2], toggle_enabled_tuple[0].label)
     unsorted_toggles = [(
         toggle,
         toggle.enabled(self.domain, namespace=NAMESPACE_DOMAIN),
         toggle.enabled(self.request.couch_user.username, namespace=NAMESPACE_USER)
     ) for toggle in all_toggles()]
     return sorted(unsorted_toggles, key=_sort_key)
Exemplo n.º 15
0
def toggle_diff(request, domain):
    params = json_request(request.GET)
    other_domain = params.get('domain')
    diff = []
    if Domain.get_by_name(other_domain):
        diff = [{'slug': t.slug, 'label': t.label, 'url': reverse(ToggleEditView.urlname, args=[t.slug])}
                for t in feature_previews.all_previews() + all_toggles()
                if t.enabled(request.domain, NAMESPACE_DOMAIN) and not t.enabled(other_domain, NAMESPACE_DOMAIN)]
        diff.sort(key=lambda x: x['label'])
    return json_response(diff)
Exemplo n.º 16
0
    def enabled_flags(self):
        def _sort_key(toggle_enabled_tuple):
            return (not toggle_enabled_tuple[1], not toggle_enabled_tuple[2],
                    toggle_enabled_tuple[0].label)

        unsorted_toggles = [(toggle,
                             toggle.enabled(self.domain,
                                            namespace=NAMESPACE_DOMAIN),
                             toggle.enabled(self.request.couch_user.username,
                                            namespace=NAMESPACE_USER))
                            for toggle in all_toggles()]
        return sorted(unsorted_toggles, key=_sort_key)
Exemplo n.º 17
0
def test_toggle_properties():
    """
    Check toggle properties
    """
    for toggle in toggles.all_toggles():
        assert toggle.slug
        assert toggle.label, 'Toggle "{}" label missing'.format(toggle.slug)
        assert toggle.tag, 'Toggle "{}" tag missing'.format(toggle.slug)
        assert toggle.tag in ALL_TAGS, 'Toggle "{}" tag "{}" unrecognized'.format(
            toggle.slug, toggle.tag)
        assert toggle.namespaces, 'Toggle "{}" namespaces missing'.format(
            toggle.slug)
 def handle(self, *args, **options):
     toggle_map = dict([(t.slug, t) for t in all_toggles()])
     domains = [row['key'] for row in Domain.get_all(include_docs=False)]
     for domain in domains:
         if toggle_map['rich_text'].enabled(domain) or toggle_map['experimental_ui'].enabled(domain):
             logger.info('migrating domain {}'.format(domain))
             apps = get_apps_in_domain(domain, include_remote=False)
             for app in apps:
                 call_command('migrate_app_to_cmitfb', app.id)
             toggle_map['rich_text'].set(domain, False, NAMESPACE_DOMAIN)
             toggle_map['experimental_ui'].set(domain, False, NAMESPACE_DOMAIN)
     logger.info('done with cmitfb_toggle_to_flag')
Exemplo n.º 19
0
 def handle(self, *args, **options):
     toggle_map = dict([(t.slug, t) for t in all_toggles()])
     domains = [row['key'] for row in Domain.get_all(include_docs=False)]
     for domain in domains:
         if toggle_map['rich_text'].enabled(
                 domain) or toggle_map['experimental_ui'].enabled(domain):
             logger.info('migrating domain {}'.format(domain))
             apps = get_apps_in_domain(domain, include_remote=False)
             for app in apps:
                 call_command('migrate_app_to_cmitfb', app.id)
             toggle_map['rich_text'].set(domain, False, NAMESPACE_DOMAIN)
             toggle_map['experimental_ui'].set(domain, False,
                                               NAMESPACE_DOMAIN)
     logger.info('done with cmitfb_toggle_to_flag')
Exemplo n.º 20
0
def toggle_diff(request, domain):
    params = json_request(request.GET)
    other_domain = params.get('domain')
    diff = []
    if Domain.get_by_name(other_domain):
        diff = [{
            'slug': t.slug,
            'label': t.label,
            'url': reverse(ToggleEditView.urlname, args=[t.slug])
        } for t in feature_previews.all_previews() + all_toggles()
                if t.enabled(request.domain, NAMESPACE_DOMAIN)
                and not t.enabled(other_domain, NAMESPACE_DOMAIN)]
        diff.sort(key=lambda x: x['label'])
    return json_response(diff)
Exemplo n.º 21
0
    def set_flags(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from corehq.feature_previews import all_previews

        for toggle in all_toggles():
            if toggle.enabled(self.existing_domain, NAMESPACE_DOMAIN):
                self.stdout.write('Setting flag: {}'.format(toggle.slug))
                if not self.no_commit:
                    toggle.set(self.new_domain, True, NAMESPACE_DOMAIN)

        for preview in all_previews():
            if preview.enabled(self.existing_domain):
                self.stdout.write('Setting preview: {}'.format(preview.slug))
                if not self.no_commit:
                    preview.set(self.new_domain, True, NAMESPACE_DOMAIN)
                    if preview.save_fn is not None:
                        preview.save_fn(self.new_domain, True)
Exemplo n.º 22
0
    def set_flags(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from corehq.feature_previews import all_previews

        for toggle in all_toggles():
            if toggle.enabled(self.existing_domain, NAMESPACE_DOMAIN):
                self.stdout.write('Setting flag: {}'.format(toggle.slug))
                if not self.no_commit:
                    toggle.set(self.new_domain, True, NAMESPACE_DOMAIN)

        for preview in all_previews():
            if preview.enabled(self.existing_domain):
                self.stdout.write('Setting preview: {}'.format(preview.slug))
                if not self.no_commit:
                    preview.set(self.new_domain, True, NAMESPACE_DOMAIN)
                    if preview.save_fn is not None:
                        preview.save_fn(self.new_domain, True)
Exemplo n.º 23
0
    def set_flags(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from corehq.feature_previews import all_previews
        from corehq.apps.hqwebapp.templatetags.hq_shared_tags import toggle_js_domain_cachebuster

        for toggle in all_toggles():
            if toggle.enabled(self.existing_domain):
                self.stdout.write("Setting flag: {}".format(toggle.slug))
                if not self.no_commmit:
                    toggle.set(self.new_domain, True, NAMESPACE_DOMAIN)

        for preview in all_previews():
            if preview.enabled(self.existing_domain):
                self.stdout.write("Setting preview: {}".format(preview.slug))
                if not self.no_commmit:
                    preview.set(self.new_domain, True, NAMESPACE_DOMAIN)
                    if preview.save_fn is not None:
                        preview.save_fn(self.new_domain, True)

        toggle_js_domain_cachebuster.clear(self.new_domain)
Exemplo n.º 24
0
    def set_flags(self):
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        from corehq.feature_previews import all_previews
        from corehq.apps.hqwebapp.templatetags.hq_shared_tags import toggle_js_domain_cachebuster

        for toggle in all_toggles():
            if toggle.enabled(self.existing_domain):
                self.stdout.write('Setting flag: {}'.format(toggle.slug))
                if not self.no_commmit:
                    toggle.set(self.new_domain, True, NAMESPACE_DOMAIN)

        for preview in all_previews():
            if preview.enabled(self.existing_domain):
                self.stdout.write('Setting preview: {}'.format(preview.slug))
                if not self.no_commmit:
                    preview.set(self.new_domain, True, NAMESPACE_DOMAIN)
                    if preview.save_fn is not None:
                        preview.save_fn(self.new_domain, True)

        toggle_js_domain_cachebuster.clear(self.new_domain)
Exemplo n.º 25
0
 def handle(self, *args, **options):
     toggle_map = dict([(t.slug, t) for t in all_toggles()])
     domains = [row['key'] for row in Domain.get_all(include_docs=False)]
     for domain in domains:
         if toggle_map['rich_text'].enabled(
                 domain) or toggle_map['experimental_ui'].enabled(domain):
             #logger.info('migrating domain {}'.format(domain))
             apps = get_apps_in_domain(domain, include_remote=False)
             for app in apps:
                 app_dirty = False
                 builder = ParentCasePropertyBuilder(app)
                 relationships = builder.get_parent_type_map(
                     app.get_case_types(), allow_multiple_parents=True)
                 for module in app.modules:
                     for form in module.forms:
                         if form.doc_type == 'Form' and form.requires_case(
                         ):
                             #logger.info('migrating form {}'.format(form.name.get('en', form.name)))
                             base_case_type = form.get_module().case_type
                             self._replace_in_form(form, relationships,
                                                   base_case_type, 0)
                             prefixes = re.findall(r'#case/\w+/',
                                                   form.source)
                             prefixes = set(prefixes)
                             for p in prefixes:
                                 if p != "#case/parent/" and p != "#case/grandparent/":
                                     self._form_error(
                                         form,
                                         "Unknown prefix remaining: {}".
                                         format(p))
                             if options['save']:
                                 try:
                                     save_xform(form.get_app(), form,
                                                form.source)
                                     app_dirty = True
                                 except:
                                     self._form_error(
                                         form, "Form xml invalid")
                 if app_dirty:
                     app.save()
     logger.info('done with cmitfb_migrate_syntax')
Exemplo n.º 26
0
def set_toggle(slug, item, enabled, namespace=None):
    """
    Sets a toggle value explicitly. Should only save anything if the value needed to be changed.
    """
    if toggle_enabled(slug, item, namespace=namespace) != enabled:
        ns_item = namespaced_item(item, namespace)
        try:
            toggle_doc = Toggle.get(slug)
        except ResourceNotFound:
            toggle_doc = Toggle(slug=slug, enabled_users=[])
        if enabled:
            toggle_doc.add(ns_item)
        else:
            toggle_doc.remove(ns_item)
        from corehq.feature_previews import all_previews
        from corehq.toggles import all_toggles, NAMESPACE_DOMAIN
        static_toggles_by_slug = {t.slug: t for t in all_toggles() + all_previews()}
        if namespace == NAMESPACE_DOMAIN and slug in static_toggles_by_slug:
            static_toggle = static_toggles_by_slug[slug]
            if static_toggle.save_fn:
                static_toggle.save_fn(item, enabled)
Exemplo n.º 27
0
    def _get_mocked_toggles(self):
        from toggle.models import generate_toggle_id
        from toggle.models import Toggle
        from toggle.shortcuts import namespaced_item

        mocked_toggles = {
            toggle.slug: Toggle(_id=generate_toggle_id(toggle.slug), slug=toggle.slug)
            for toggle in random.sample(all_toggles(), 3)
        }
        toggles = mocked_toggles.values()
        domain_item = namespaced_item(self.domain_name, NAMESPACE_DOMAIN)
        toggles[0].enabled_users = [domain_item]
        toggles[1].enabled_users = ['user1', 'other-user', 'user2']
        toggles[2].enabled_users = ['user1', domain_item, namespaced_item('other_domain', NAMESPACE_DOMAIN)]

        expected_items = {
            toggles[0].slug: [domain_item],
            toggles[1].slug: ['user1', 'user2'],
            toggles[2].slug: ['user1', domain_item],
        }

        return mocked_toggles, expected_items
Exemplo n.º 28
0
    def _get_toggles(self):

        def _sort_key(toggle):
            return (not (toggle['domain_enabled'] or toggle['user_enabled']),
                    [t.name for t in toggles.ALL_TAGS].index(toggle['tag']),
                    toggle['label'])

        unsorted_toggles = [{
            'slug': toggle.slug,
            'label': toggle.label,
            'description': toggle.description,
            'help_link': toggle.help_link,
            'tag': toggle.tag.name,
            'tag_description': toggle.tag.description,
            'tag_css_class': toggle.tag.css_class,
            'has_domain_namespace': toggles.NAMESPACE_DOMAIN in toggle.namespaces,
            'domain_enabled': toggle.enabled(self.domain, namespace=toggles.NAMESPACE_DOMAIN),
            'user_enabled': toggle.enabled(self.request.couch_user.username,
                                           namespace=toggles.NAMESPACE_USER),
        } for toggle in toggles.all_toggles()]

        return sorted(unsorted_toggles, key=_sort_key)
Exemplo n.º 29
0
 def page_context(self):
     toggles = list(all_toggles())
     domain_counts = {}
     active_domain_count = {}
     user_counts = {}
     last_used = {}
     last_modified = {}
     if self.show_usage:
         for t in toggles:
             counter = Counter()
             try:
                 usage = Toggle.get(t.slug)
             except ResourceNotFound:
                 domain_counts[t.slug] = 0
                 user_counts[t.slug] = 0
                 active_domain_count[t.slug] = 0
             else:
                 for u in usage.enabled_users:
                     namespace = u.split(
                         ":", 1)[0] if u.find(":") != -1 else NAMESPACE_USER
                     counter[namespace] += 1
                 usage_info = _get_usage_info(usage)
                 domain_counts[t.slug] = counter.get(NAMESPACE_DOMAIN, 0)
                 active_domain_count[t.slug] = usage_info["_active_domains"]
                 user_counts[t.slug] = counter.get(NAMESPACE_USER, 0)
                 last_used[t.slug] = usage_info["_latest"]
                 last_modified[t.slug] = usage.last_modified
     return {
         'domain_counts': domain_counts,
         'active_domain_count': active_domain_count,
         'page_url': self.page_url,
         'show_usage': self.show_usage,
         'toggles': toggles,
         'tags': ALL_TAGS,
         'user_counts': user_counts,
         'last_used': last_used,
         'last_modified': last_modified,
     }
Exemplo n.º 30
0
 def page_context(self):
     toggles = list(all_toggles())
     domain_counts = {}
     active_domain_count = {}
     user_counts = {}
     last_used = {}
     last_modified = {}
     if self.show_usage:
         for t in toggles:
             counter = Counter()
             try:
                 usage = Toggle.get(t.slug)
             except ResourceNotFound:
                 domain_counts[t.slug] = 0
                 user_counts[t.slug] = 0
                 active_domain_count[t.slug] = 0
             else:
                 for u in usage.enabled_users:
                     namespace = u.split(":", 1)[0] if u.find(":") != -1 else NAMESPACE_USER
                     counter[namespace] += 1
                 usage_info = _get_usage_info(usage)
                 domain_counts[t.slug] = counter.get(NAMESPACE_DOMAIN, 0)
                 active_domain_count[t.slug] = usage_info["_active_domains"]
                 user_counts[t.slug] = counter.get(NAMESPACE_USER, 0)
                 last_used[t.slug] = usage_info["_latest"]
                 last_modified[t.slug] = usage.last_modified
     return {
         'domain_counts': domain_counts,
         'active_domain_count': active_domain_count,
         'page_url': self.page_url,
         'show_usage': self.show_usage,
         'toggles': toggles,
         'tags': ALL_TAGS,
         'user_counts': user_counts,
         'last_used': last_used,
         'last_modified': last_modified,
     }
Exemplo n.º 31
0
def find_static_toggle(slug):
    for toggle in all_toggles():
        if toggle.slug == slug:
            return toggle
Exemplo n.º 32
0
 def page_context(self):
     return {
         'toggles': all_toggles(),
         'tags': ALL_TAGS
     }
Exemplo n.º 33
0
 def toggle_map(self):
     return dict([(t.slug, t) for t in all_toggles()])
Exemplo n.º 34
0
 def toggle_map(self):
     return dict([(t.slug, t) for t in all_toggles()])
Exemplo n.º 35
0
def _find_static_toggle(slug):
    for toggle in all_toggles():
        if toggle.slug == slug:
            return toggle
Exemplo n.º 36
0
def _get_toggles_with_tag(tag=None):
    toggles = []
    for toggle in all_toggles():
        if not tag or tag in toggle.tag.name:
            toggles.append(toggle)
    return toggles
Exemplo n.º 37
0
 def page_context(self):
     return {
         'toggles': all_toggles(),
     }
Exemplo n.º 38
0
 def show_toggles(self):
     counts = Counter(t.tag.name for t in all_toggles() + all_previews())
     for tag, count in counts.items():
         self.logger.log("commcare.static_analysis.toggle_count", count,
                         [f"toggle_tag:{tag}"])
Exemplo n.º 39
0
 def page_context(self):
     return {'toggles': all_toggles(), 'tags': ALL_TAGS}