Exemplo n.º 1
0
def account_settings(request):
    ctx = {}

    # Don't use `request.amo_user` because it's too cached.
    user = request.user
    if user.is_authenticated():
        amo_user = user.get_profile()
        form = forms.UserEditForm(request.POST or None, instance=amo_user)
        if request.method == 'POST':
            if form.is_valid():
                form.save()
                messages.success(request, _('Settings Updated.'))
                amo.log(amo.LOG.USER_EDITED)
                response = redirect('account.settings')
                # TODO: Detect when we're changing the user's locale and region
                # and bust on '/', bust on '/settings' for everything else.
                bust_fragments(response, '/')
                return response
            else:
                messages.form_errors(request)
        ctx = {'form': form, 'amouser': amo_user}
    else:
        if request.method == 'POST':
            messages.success(request, _('Settings Updated.'))

    return jingo.render(request, 'account/settings.html', ctx)
Exemplo n.º 2
0
def account_settings(request):
    ctx = {}

    # Don't use `request.amo_user` because it's too cached.
    user = request.user
    if user.is_authenticated():
        amo_user = user.get_profile()
        form = forms.UserEditForm(request.POST or None, instance=amo_user)
        if request.method == 'POST':
            if form.is_valid():
                form.save()
                messages.success(request, _('Settings Updated.'))
                amo.log(amo.LOG.USER_EDITED)
                response = redirect('account.settings')
                # TODO: Detect when we're changing the user's locale and region
                # and bust on '/', bust on '/settings' for everything else.
                bust_fragments(response, '/')
                return response
            else:
                messages.form_errors(request)
        ctx = {'form': form, 'amouser': amo_user}
    else:
        if request.method == 'POST':
            messages.success(request, _('Settings Updated.'))

    return jingo.render(request, 'account/settings.html', ctx)
Exemplo n.º 3
0
def account_settings(request):
    ctx = {}

    # Don't use `request.amo_user` because it's too cached.
    user = request.user
    if user.is_authenticated():
        amo_user = user.get_profile()
        if request.method == 'POST':
            if 'authorized_apps' in request.POST:
                ids = request.POST.getlist('authorized_apps')
                Token.objects.filter(pk__in=ids).delete()
                form = forms.UserEditForm(None, instance=amo_user)
            else:
                form = forms.UserEditForm(request.POST, instance=amo_user)
                if form.is_valid():
                    form.save()
                    messages.success(request, _('Settings Updated.'))
                    amo.log(amo.LOG.USER_EDITED)
                    response = redirect('account.settings')
                    # TODO: Detect when we're changing the user's
                    # locale and region and bust on '/', bust on
                    # '/settings' for everything else.
                    bust_fragments(response, '/')
                    return response
                else:
                    messages.form_errors(request)
        else:
            form = forms.UserEditForm(None, instance=amo_user)
        tokens = Token.objects.filter(user=user, token_type=ACCESS_TOKEN)
        ctx = {'form': form, 'amouser': amo_user, 'tokens': tokens}
    else:
        if request.method == 'POST':
            messages.success(request, _('Settings Updated.'))

    return jingo.render(request, 'account/settings.html', ctx)
Exemplo n.º 4
0
 def test_formatted_prefix(self):
     """Assert that bust_fragments formats (kw)?args into the URLs ok."""
     bust_fragments(self.resp,
                    '/foo/{1}/{asdf}',
                    'first',
                    'second',
                    asdf='kw')
     self.assert_header_set('["/foo/second/kw"]')
Exemplo n.º 5
0
 def test_formatted_prefix_unicode(self):
     """
     Formatting unicode args works properly.
     """
     bust_fragments(self.resp,
                    '/foo/{1}/{asdf}',
                    'first',
                    'second',
                    asdf=u'\u2603')
     self.assert_header_set(u'["/foo/second/\\u2603"]')
Exemplo n.º 6
0
 def test_formatted_prefix_unicode(self):
     """
     Formatting unicode args works properly.
     """
     bust_fragments(self.resp, "/foo/{1}/{asdf}", "first", "second", asdf=u"\u2603")
     self.assert_header_set(u'["/foo/second/\\u2603"]')
Exemplo n.º 7
0
 def test_formatted_prefix(self):
     """Assert that bust_fragments formats (kw)?args into the URLs ok."""
     bust_fragments(self.resp, "/foo/{1}/{asdf}", "first", "second", asdf="kw")
     self.assert_header_set('["/foo/second/kw"]')
Exemplo n.º 8
0
 def test_list(self):
     """Assert that bust_fragments applies a list properly."""
     bust_fragments(self.resp, ["/foo/bar", "/zip/zap"])
     self.assert_header_set('["/foo/bar", "/zip/zap"]')
Exemplo n.º 9
0
 def test_min_args(self):
     """Assert that bust_fragments applies with the minimum args."""
     bust_fragments(self.resp, "/foo/bar")
     self.assert_header_set('["/foo/bar"]')
Exemplo n.º 10
0
 def test_formatted_prefix(self):
     """Assert that bust_fragments formats (kw)?args into the URLs ok."""
     bust_fragments(self.resp, '/foo/{1}/{asdf}', 'first', 'second',
                    asdf='kw')
     self.assert_header_set('["/foo/second/kw"]')
Exemplo n.º 11
0
 def test_list(self):
     """Assert that bust_fragments applies a list properly."""
     bust_fragments(self.resp, ['/foo/bar', '/zip/zap'])
     self.assert_header_set('["/foo/bar", "/zip/zap"]')
Exemplo n.º 12
0
 def test_min_args(self):
     """Assert that bust_fragments applies with the minimum args."""
     bust_fragments(self.resp, '/foo/bar')
     self.assert_header_set('["/foo/bar"]')