<commit_before>import json
from urllib import urlencode
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from corehq import toggles
from corehq.apps.app_manager.dbaccessors import get_app
from corehq.apps.app_manager.decorators import require_deploy_apps


CASE_TYPE_CONFLICT_MSG = (
    "Warning: The form's new module "
    "has a different case type from the old module.<br />"
    "Make sure all case properties you are loading "
    "are available in the new case type"
)


@require_deploy_apps
def back_to_main(request, domain, app_id=None, module_id=None, form_id=None,
                 unique_form_id=None):
    """
    returns an HttpResponseRedirect back to the main page for the App Manager app
    with the correct GET parameters.

    This is meant to be used by views that process a POST request,
    which then redirect to the main page.

    """
    # TODO: Refactor this function. The length of the args matters :(

    page = None
    params = {}

    args = [domain]

    if app_id is not None:
        args.append(app_id)
        if unique_form_id is not None:
            app = get_app(domain, app_id)
            obj = app.get_form(unique_form_id, bare=False)
            module_id = obj['module'].id
            form_id = obj['form'].id
        if module_id is not None:
            args.append(module_id)
            if form_id is not None:
                args.append(form_id)

    if page:
        view_name = page
    else:
        view_name = {
            1: 'view_app',
            2: 'view_app',
            3: 'view_module',
            4: 'form_designer' if toggles.APP_MANAGER_V2.enabled(domain) else 'view_form',
        }[len(args)]

    return HttpResponseRedirect(
        "%s%s" % (
            reverse('corehq.apps.app_manager.views.%s' % view_name, args=args),
            "?%s" % urlencode(params) if params else ""
        )
    )


def get_langs(request, app):
    lang = request.GET.get(
        'lang',
        request.COOKIES.get('lang', app.langs[0] if hasattr(app, 'langs') and app.langs else '')
    )
    langs = None
    if app and hasattr(app, 'langs'):
        if not app.langs and not app.is_remote_app:
            # lots of things fail if the app doesn't have any languages.
            # the best we can do is add 'en' if there's nothing else.
            app.langs.append('en')
            app.save()<commit_msg>use view name instead of dot notation<commit_after>import json
from urllib import urlencode
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from corehq import toggles
from corehq.apps.app_manager.dbaccessors import get_app
from corehq.apps.app_manager.decorators import require_deploy_apps


CASE_TYPE_CONFLICT_MSG = (
    "Warning: The form's new module "
    "has a different case type from the old module.<br />"
    "Make sure all case properties you are loading "
    "are available in the new case type"
)


@require_deploy_apps
def back_to_main(request, domain, app_id=None, module_id=None, form_id=None,
                 unique_form_id=None):
    """
    returns an HttpResponseRedirect back to the main page for the App Manager app
    with the correct GET parameters.

    This is meant to be used by views that process a POST request,
    which then redirect to the main page.

    """
    # TODO: Refactor this function. The length of the args matters :(

    page = None
    params = {}

    args = [domain]

    if app_id is not None:
        args.append(app_id)
        if unique_form_id is not None:
            app = get_app(domain, app_id)
            obj = app.get_form(unique_form_id, bare=False)
            module_id = obj['module'].id
            form_id = obj['form'].id
        if module_id is not None:
            args.append(module_id)
            if form_id is not None:
                args.append(form_id)

    if page:
        view_name = page
    else:
        view_name = {
            1: 'view_app',
            2: 'view_app',
            3: 'view_module',
            4: 'form_designer' if toggles.APP_MANAGER_V2.enabled(domain) else 'view_form',
        }[len(args)]

    return HttpResponseRedirect(
        "%s%s" % (
            reverse(view_name, args=args),
            "?%s" % urlencode(params) if params else ""
        )
    )


def get_langs(request, app):
    lang = request.GET.get(
        'lang',
        request.COOKIES.get('lang', app.langs[0] if hasattr(app, 'langs') and app.langs else '')
    )
    langs = None
    if app and hasattr(app, 'langs'):
        if not app.langs and not app.is_remote_app:
            # lots of things fail if the app doesn't have any languages.
            # the best we can do is add 'en' if there's nothing else.
            app.langs.append('en')
            app.save()
{'fraction_non_alphanumeric': 0.08802456499488229, 'fraction_numerical': 0.0024564994882292734, 'mean_word_length': 2.3534660260809885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5986180', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1471, 'n_words': 476}