Exemplo n.º 1
0
def notification_settings(request):
    forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms) or ():
            form = safe_execute(form, plugin, request.user, request.POST
                                or None)
            if not form:
                continue
            helper = FormHelper()
            helper.form_tag = False
            forms.append((form, helper))

    # Ensure our form comes first
    helper = FormHelper()
    helper.form_tag = False
    forms = [
        (NotificationSettingsForm(request.user, request.POST or None), helper),
    ] + forms

    if request.POST:
        if all(f.is_valid() for f, h in forms):
            for form, helper in forms:
                form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'forms': forms,
        'page': 'notifications',
    })
    return render_to_response('sentry/account/notifications.html', context,
                              request)
Exemplo n.º 2
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST or None)

    # TODO(dcramer): this is an extremely bad pattern and we need a more optimal
    # solution for rendering this (that ideally plays well with the org data)
    project_list = []
    organization_list = Organization.objects.get_for_user(
        user=request.user,
    )
    for organization in organization_list:
        team_list = Team.objects.get_for_user(
            user=request.user,
            organization=organization,
        )
        for team in team_list:
            project_list.extend(
                Project.objects.get_for_user(
                    user=request.user,
                    team=team,
                )
            )

    project_forms = [
        (project, ProjectEmailOptionsForm(
            project, request.user,
            request.POST or None,
            prefix='project-%s' % (project.id,)
        ))
        for project in sorted(project_list, key=lambda x: (
            x.team.name if x.team else None, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms) or ():
            form = safe_execute(form, plugin, request.user, request.POST or None, prefix=plugin.slug)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(itertools.chain(
            [settings_form], ext_forms, (f for _, f in project_forms)
        ))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/notifications.html', context, request)
Exemplo n.º 3
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST
                                             or None)

    project_list = list(
        Project.objects.filter(
            team__organizationmemberteam__organizationmember__user=request.
            user,
            team__organizationmemberteam__is_active=True,
            status=ProjectStatus.VISIBLE,
        ).distinct())

    project_forms = [
        (project,
         ProjectEmailOptionsForm(project,
                                 request.user,
                                 request.POST or None,
                                 prefix='project-%s' % (project.id, )))
        for project in sorted(project_list,
                              key=lambda x: (x.team.name
                                             if x.team else None, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms,
                                 _with_transaction=False) or ():
            form = safe_execute(form,
                                plugin,
                                request.user,
                                request.POST or None,
                                prefix=plugin.slug,
                                _with_transaction=False)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(
            itertools.chain([settings_form], ext_forms,
                            (f for _, f in project_forms)))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/notifications.html', context,
                              request)
Exemplo n.º 4
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST
                                             or None)

    project_list = Project.objects.get_for_user(request.user,
                                                access=MEMBER_USER)
    project_forms = [
        (project,
         ProjectEmailOptionsForm(project,
                                 request.user,
                                 request.POST or None,
                                 prefix='project-%s' % (project.id, )))
        for project in sorted(project_list,
                              key=lambda x: (x.team.name, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms) or ():
            form = safe_execute(form,
                                plugin,
                                request.user,
                                request.POST or None,
                                prefix=plugin.slug)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(
            itertools.chain([settings_form], ext_forms,
                            (f for _, f in project_forms)))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
    })
    return render_to_response('sentry/account/notifications.html', context,
                              request)