コード例 #1
0
ファイル: views.py プロジェクト: alexbriski/pootle
def handle_form(request, current_directory, current_project, current_language,
                ctx):
    if request.method != 'POST':
        # Not a POST method. Return a default starting state of the form
        return form_factory(current_directory)()

    # Reconstruct the NoticeForm with the user data.
    form = form_factory(current_directory)(request.POST)
    if not form.is_valid():
        return form

    message = form.cleaned_data['message']
    languages = form.cleaned_data.get('language_selection', [])
    projects = form.cleaned_data.get('project_selection', [])
    publish_dirs = []
    ctx['notices_published'] = []

    # Figure out which directories, projects, and languages are involved
    if current_language and current_project:
        # The current translation project
        publish_dirs = [current_directory]
        languages = [current_language]
        projects = [current_project]
    elif current_language:
        languages = [current_language]
        if form.cleaned_data['project_all']:
            # The current language
            publish_dirs = [current_language.directory]
        else:
            # Certain projects in the current language
            translation_projects = TranslationProject.objects.filter(
                language=current_language, project__in=projects)
            publish_dirs = [tp.directory for tp in translation_projects]
    elif current_project:
        projects = [current_project]
        if form.cleaned_data['language_all']:
            # The current project
            publish_dirs = [current_project.directory]
        else:
            # Certain languages in the current project
            translation_projects = TranslationProject.objects.filter(
                language__in=languages, project=current_project)
            publish_dirs = [tp.directory for tp in translation_projects]
    else:
        # The form is top-level (server-wide)
        if form.cleaned_data['project_all']:
            if form.cleaned_data['language_all']:
                # Publish at server root
                publish_dirs = [current_directory]
            else:
                # Certain languages
                publish_dirs = [l.directory for l in languages]
        else:
            if form.cleaned_data['language_all']:
                # Certain projects
                publish_dirs = [p.directory for p in projects]
            else:
                # Specific translation projects
                translation_projects = TranslationProject.objects.filter(
                    language__in=languages, project__in=projects)
                publish_dirs = [tp.directory for tp in translation_projects]

    # RSS (notices)
    if form.cleaned_data['publish_rss']:
        for d in publish_dirs:
            new_notice = create_notice(request.user, message, d)
            ctx['notices_published'].append(new_notice)

    # E-mail
    if form.cleaned_data['send_email']:
        email_header = form.cleaned_data['email_header']
        recipients = get_recipients(
            form.cleaned_data['restrict_to_active_users'],
            form.cleaned_data['directory'])
        # Send the email to the recipients, ensuring addresses are hidden
        send_mail(email_header, message, bcc=recipients, fail_silently=True)

    form = form_factory(current_directory)()

    return form
コード例 #2
0
ファイル: views.py プロジェクト: alex-silva/pootle
def handle_form(request, current_directory, current_project, current_language,
                ctx):
    if request.method != 'POST':
        # Not a POST method. Return a default starting state of the form
        return form_factory(current_directory)()

    # Reconstruct the NoticeForm with the user data.
    form = form_factory(current_directory)(request.POST)
    if not form.is_valid():
        return form

    message = form.cleaned_data['message']
    languages = form.cleaned_data.get('language_selection', [])
    projects = form.cleaned_data.get('project_selection', [])
    publish_dirs = []
    ctx['notices_published'] = []

    # Figure out which directories, projects, and languages are involved
    if current_language and current_project:
        # The current translation project
        publish_dirs = [current_directory]
        languages = [current_language]
        projects = [current_project]
    elif current_language:
        languages = [current_language]
        if form.cleaned_data['project_all']:
            # The current language
            publish_dirs = [current_language.directory]
        else:
            # Certain projects in the current language
            translation_projects = TranslationProject.objects.filter(
                    language=current_language, project__in=projects)
            publish_dirs = [tp.directory for tp in translation_projects]
    elif current_project:
        projects = [current_project]
        if form.cleaned_data['language_all']:
            # The current project
            publish_dirs = [current_project.directory]
        else:
            # Certain languages in the current project
            translation_projects = TranslationProject.objects.filter(
                    language__in=languages, project=current_project)
            publish_dirs = [tp.directory for tp in translation_projects]
    else:
        # The form is top-level (server-wide)
        if form.cleaned_data['project_all']:
            if form.cleaned_data['language_all']:
                # Publish at server root
                publish_dirs = [current_directory]
            else:
                # Certain languages
                publish_dirs = [l.directory for l in languages]
        else:
            if form.cleaned_data['language_all']:
                # Certain projects
                publish_dirs = [p.directory for p in projects]
            else:
                # Specific translation projects
                translation_projects = TranslationProject.objects.filter(
                        language__in=languages, project__in=projects)
                publish_dirs = [tp.directory for tp in translation_projects]

    # RSS (notices)
    if form.cleaned_data['publish_rss']:
        for d in publish_dirs:
            new_notice = create_notice(request.user, message, d)
            ctx['notices_published'].append(new_notice)

    # E-mail
    if form.cleaned_data['send_email']:
        email_header = form.cleaned_data['email_header']
        recipients = get_recipients(
            form.cleaned_data['restrict_to_active_users'],
            form.cleaned_data['directory']
        )
        # Send the email to the recipients, ensuring addresses are hidden
        send_mail(email_header, message, bcc=recipients, fail_silently=True)

    form = form_factory(current_directory)()

    return form
コード例 #3
0
ファイル: views.py プロジェクト: ericholscher/pootle
def handle_form(request, current_directory, current_project,
                current_language, template_vars):
    if request.method != 'POST':
        # Not a POST method. Return a default starting state of the form
        return form_factory(current_directory)()

    # Reconstruct the NoticeForm with the user data.
    form = form_factory(current_directory)(request.POST)
    if not form.is_valid():
        return form

    message = form.cleaned_data['message']
    languages = form.cleaned_data.get('language_selection', [])
    projects = form.cleaned_data.get('project_selection', [])
    publish_dirs = []
    template_vars['notices_published'] = []

    # Figure out which directories, projects, and languages are involved
    if current_language and current_project:
        # The current translation project
        publish_dirs = [current_directory]
        languages = [current_language]
        projects = [current_project]
    elif current_language:
        languages = [current_language]
        if form.cleaned_data['project_all']:
            # The current language
            publish_dirs = [current_language.directory]
        else:
            # Certain projects in the current language
            translation_projects = TranslationProject.objects.filter(
                    language=current_language, project__in=projects)
            publish_dirs = [tp.directory for tp in translation_projects]
    elif current_project:
        projects = [current_project]
        if form.cleaned_data['language_all']:
            # The current project
            publish_dirs = [current_project.directory]
        else:
            # Certain languages in the current project
            translation_projects = TranslationProject.objects.filter(
                    language__in=languages, project=current_project)
            publish_dirs = [tp.directory for tp in translation_projects]
    else:
        # The form is top-level (server-wide)
        if form.cleaned_data['project_all']:
            if form.cleaned_data['language_all']:
                # Publish at server root
                publish_dirs = [current_directory]
            else:
                # Certain languages
                publish_dirs = [l.directory for l in languages]
        else:
            if form.cleaned_data['language_all']:
                # Certain projects
                publish_dirs = [p.directory for p in projects]
            else:
                # Specific translation projects
                translation_projects = TranslationProject.objects.filter(
                        language__in=languages, project__in=projects)
                publish_dirs = [tp.directory for tp in translation_projects]

    # RSS (notices)
    if form.cleaned_data['publish_rss']:
        for d in publish_dirs:
            create_notice(request.user, message, d)

    # E-mail
    if form.cleaned_data['send_email']:
        email_header = form.cleaned_data['email_header']

        if languages:
            lang_filter = Q(languages__in=languages)
        else:
            lang_filter = Q(languages__isnull=False)

        if projects:
            proj_filter = Q(projects__in=projects)
        else:
            proj_filter = Q(projects__isnull=False)

        to_list = PootleProfile.objects.filter(lang_filter, proj_filter)
        to_list = to_list.distinct()

        # Take into account 'only active users' flag from the form.
        if form.cleaned_data['restrict_to_active_users']:
            to_list = to_list.exclude(submission=None)
            to_list = to_list.exclude(suggestion=None)
            to_list = to_list.exclude(suggester=None)

        recipients = []
        for person in to_list:
            # Check if the User object here as permissions
            directory = form.cleaned_data['directory']

            if not check_profile_permission(person, 'view', directory):
                continue

            if person.user.email != '':
                recipients.append(person.user.email)

        # Send the email to the recipients, ensuring addresses are hidden
        send_mail(email_header, message, bcc=recipients, fail_silently=True)

    if not template_vars['notices_published']:
        template_vars['notices_published'] = None

    form = form_factory(current_directory)()

    return form
コード例 #4
0
def handle_form(request, current_directory, current_project, current_language,
                template_vars):
    if request.method != 'POST':
        # Not a POST method. Return a default starting state of the form
        return form_factory(current_directory)()

    # Reconstruct the NoticeForm with the user data.
    form = form_factory(current_directory)(request.POST)
    if not form.is_valid():
        return form

    message = form.cleaned_data['message']
    languages = form.cleaned_data.get('language_selection', [])
    projects = form.cleaned_data.get('project_selection', [])
    publish_dirs = []
    template_vars['notices_published'] = []

    # Figure out which directories, projects, and languages are involved
    if current_language and current_project:
        # The current translation project
        publish_dirs = [current_directory]
        languages = [current_language]
        projects = [current_project]
    elif current_language:
        languages = [current_language]
        if form.cleaned_data['project_all']:
            # The current language
            publish_dirs = [current_language.directory]
        else:
            # Certain projects in the current language
            translation_projects = TranslationProject.objects.filter(
                language=current_language, project__in=projects)
            publish_dirs = [tp.directory for tp in translation_projects]
    elif current_project:
        projects = [current_project]
        if form.cleaned_data['language_all']:
            # The current project
            publish_dirs = [current_project.directory]
        else:
            # Certain languages in the current project
            translation_projects = TranslationProject.objects.filter(
                language__in=languages, project=current_project)
            publish_dirs = [tp.directory for tp in translation_projects]
    else:
        # The form is top-level (server-wide)
        if form.cleaned_data['project_all']:
            if form.cleaned_data['language_all']:
                # Publish at server root
                publish_dirs = [current_directory]
            else:
                # Certain languages
                publish_dirs = [l.directory for l in languages]
        else:
            if form.cleaned_data['language_all']:
                # Certain projects
                publish_dirs = [p.directory for p in projects]
            else:
                # Specific translation projects
                translation_projects = TranslationProject.objects.filter(
                    language__in=languages, project__in=projects)
                publish_dirs = [tp.directory for tp in translation_projects]

    # RSS (notices)
    if form.cleaned_data['publish_rss']:
        for d in publish_dirs:
            create_notice(request.user, message, d)

    # E-mail
    if form.cleaned_data['send_email']:
        email_header = form.cleaned_data['email_header']

        if languages:
            lang_filter = Q(languages__in=languages)
        else:
            lang_filter = Q(languages__isnull=False)

        if projects:
            proj_filter = Q(projects__in=projects)
        else:
            proj_filter = Q(projects__isnull=False)

        to_list = PootleProfile.objects.filter(lang_filter, proj_filter)
        to_list = to_list.distinct()

        # Take into account 'only active users' flag from the form.
        if form.cleaned_data['restrict_to_active_users']:
            to_list = to_list.exclude(submission=None)
            to_list = to_list.exclude(suggestion=None)
            to_list = to_list.exclude(suggester=None)

        recipients = []
        for person in to_list:
            # Check if the User object here as permissions
            directory = form.cleaned_data['directory']

            if not check_profile_permission(person, 'view', directory):
                continue

            if person.user.email != '':
                recipients.append(person.user.email)

        # Send the email to the recipients, ensuring addresses are hidden
        send_mail(email_header, message, bcc=recipients, fail_silently=True)

    if not template_vars['notices_published']:
        template_vars['notices_published'] = None

    form = form_factory(current_directory)()

    return form