Fix more dodgy uses of redirect() (bug 787258)

This commit is contained in:
Kumar McMillan 2012-08-31 11:53:31 -05:00
Родитель e16dbf59da
Коммит 9079e7d17a
10 изменённых файлов: 35 добавлений и 31 удалений

Просмотреть файл

@ -576,10 +576,10 @@ def purchase(request, addon):
# This is the non-Ajax fallback.
if status != 'COMPLETED':
return redirect(url)
return http.HttpResponseRedirect(url)
messages.success(request, _('Purchase complete'))
return redirect(shared_url('addons.detail', addon))
return http.HttpResponseRedirect(shared_url('addons.detail', addon))
# TODO(andym): again, remove this once we figure out logged out flow.
@ -631,7 +631,7 @@ def purchase_complete(request, addon, status):
# For mobile, bounce back to the details page.
if request.MOBILE:
url = urlparams(shared_url('detail', addon), **context)
return redirect(url)
return http.HttpResponseRedirect(url)
context.update({'addon': addon})
response = jingo.render(request, 'addons/paypal_result.html', context)
@ -815,7 +815,7 @@ def report_abuse(request, addon):
if request.method == "POST" and form.is_valid():
send_abuse_report(request, addon, form.cleaned_data['text'])
messages.success(request, _('Abuse reported.'))
return redirect(addon.get_url_path())
return http.HttpResponseRedirect(addon.get_url_path())
else:
return jingo.render(request, 'addons/report_abuse_full.html',
{'addon': addon, 'abuse_form': form, })
@ -824,4 +824,5 @@ def report_abuse(request, addon):
@cache_control(max_age=60 * 60 * 24)
def persona_redirect(request, persona_id):
persona = get_object_or_404(Persona, persona_id=persona_id)
return redirect('addons.detail', persona.addon.slug, permanent=True)
return http.HttpResponsePermanentRedirect('addons.detail',
persona.addon.slug)

Просмотреть файл

@ -4,7 +4,6 @@ import re
from django import http
from django.conf import settings
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import redirect
from django.utils.encoding import iri_to_uri
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
@ -168,6 +167,6 @@ def record(request):
def plugin_check_redirect(request):
return redirect('%s?%s' %
return http.HttpResponseRedirect('%s?%s' %
(settings.PFS_URL,
iri_to_uri(request.META.get('QUERY_STRING', ''))))

Просмотреть файл

@ -60,8 +60,9 @@ def legacy_redirect(request, uuid, edit=False):
key = 'uuid' if len(uuid) == 36 else 'nickname'
c = get_object_or_404(Collection.objects, **{key: uuid})
if edit:
return redirect(c.edit_url())
return redirect(c.get_url_path() + '?' + request.GET.urlencode())
return http.HttpResponseRedirect(c.edit_url())
to = c.get_url_path() + '?' + request.GET.urlencode()
return http.HttpResponseRedirect(to)
def legacy_directory_redirects(request, page):
@ -75,7 +76,7 @@ def legacy_directory_redirects(request, page):
loc = reverse('collections.user', args=[request.amo_user.username])
elif page == 'favorites':
loc = reverse('collections.following')
return redirect(loc)
return http.HttpResponseRedirect(loc)
class CollectionFilter(BaseFilter):
@ -181,7 +182,7 @@ def collection_detail(request, username, slug):
return http.HttpResponseForbidden()
if request.GET.get('format') == 'rss':
return redirect(c.feed_url(), permanent=True)
return http.HttpResponsePermanentRedirect(c.feed_url())
base = Addon.objects.valid() & c.addons.all()
filter = CollectionAddonFilter(request, base,
@ -251,7 +252,7 @@ def get_notes(collection, raw=False):
def collection_vote(request, username, slug, direction):
c = get_collection(request, username, slug)
if request.method != 'POST':
return redirect(c.get_url_path())
return http.HttpResponseRedirect(c.get_url_path())
vote = {'up': 1, 'down': -1}[direction]
qs = (CollectionVote.objects.using('default')
@ -271,7 +272,7 @@ def collection_vote(request, username, slug, direction):
if request.is_ajax():
return http.HttpResponse()
else:
return redirect(c.get_url_path())
return http.HttpResponseRedirect(c.get_url_path())
def initial_data_from_request(request):
@ -389,7 +390,7 @@ def change_addon(request, collection, action):
url = '%s?addon_id=%s' % (reverse('collections.ajax_list'), addon.id)
else:
url = collection.get_url_path()
return redirect(url)
return http.HttpResponseRedirect(url)
@write
@ -500,7 +501,7 @@ def edit_privacy(request, collection, username, slug):
collection.save()
log.info(u'%s changed privacy on collection %s' %
(request.amo_user, collection.id))
return redirect(collection.get_url_path())
return http.HttpResponseRedirect(collection.get_url_path())
@write
@ -545,7 +546,7 @@ def delete_icon(request, collection, username, slug):
return {'icon': collection.icon_url}
else:
messages.success(request, _('Icon Deleted'))
return redirect(collection.edit_url())
return http.HttpResponseRedirect(collection.edit_url())
@login_required
@ -570,7 +571,7 @@ def watch(request, username, slug):
if request.is_ajax():
return {'watching': watching}
else:
return redirect(collection.get_url_path())
return http.HttpResponseRedirect(collection.get_url_path())
def share(request, username, slug):
@ -598,4 +599,4 @@ def mine(request, slug=None):
loc = reverse('collections.user', args=[username])
else:
loc = reverse('collections.detail', args=[username, slug])
return redirect(loc)
return http.HttpResponseRedirect(loc)

Просмотреть файл

@ -29,7 +29,7 @@ def index(request, version=None):
if not COMPAT:
return jingo.render(request, template, {'results': False})
if version not in compat_dict:
return redirect('compat.index', COMPAT[0]['main'])
return http.HttpResponseRedirect('compat.index', COMPAT[0]['main'])
qs = AppCompat.search()
binary = None
@ -43,7 +43,7 @@ def index(request, version=None):
new = reverse('compat.index', args=[ver], add_prefix=False)
url = '/%s%s' % (amo.APP_IDS[int(app)].short, new)
type_ = form.cleaned_data['type'] or None
return redirect(urlparams(url, type=type_))
return http.HttpResponseRedirect(urlparams(url, type=type_))
if form.cleaned_data['type'] != 'all':
binary = form.cleaned_data['type'] == 'binary'

Просмотреть файл

@ -302,7 +302,8 @@ def recs_debug(request):
fragment = urlparse.urlparse(url).fragment
guids = json.loads(urlparse.unquote(fragment)).keys()
qs = ','.join(map(str, get_addon_ids(guids)))
return redirect(reverse('discovery.recs.debug') + '?ids=' + qs)
to = reverse('discovery.recs.debug') + '?ids=' + qs
return http.HttpResponseRedirect(to)
ctx = {'ids': request.GET.get('ids')}
if 'ids' in request.GET:

Просмотреть файл

@ -294,9 +294,9 @@ def _queue(request, TableObj, tab, qs=None):
# Force a limit query for efficiency:
start = review_num - 1
row = qs[start: start + 1][0]
return redirect('%s?num=%s' % (
TableObj.review_url(row),
review_num))
return http.HttpResponseRedirect('%s?num=%s' % (
TableObj.review_url(row),
review_num))
except IndexError:
pass
order_by = request.GET.get('sort', TableObj.default_order_by())

Просмотреть файл

@ -1,8 +1,8 @@
from functools import wraps
from django import http
from django.conf import settings
from django.http import Http404
from django.shortcuts import redirect
from amo.urlresolvers import reverse
@ -14,7 +14,8 @@ def locale_switcher(f):
new_userlang = request.GET.get('userlang')
if new_userlang in settings.AMO_LANGUAGES + settings.HIDDEN_LANGUAGES:
kwargs['locale_code'] = new_userlang
return redirect(reverse(decorated, args=args, kwargs=kwargs))
to = reverse(decorated, args=args, kwargs=kwargs)
return http.HttpResponseRedirect(to)
else:
return f(request, *args, **kwargs)
return decorated

Просмотреть файл

@ -1,5 +1,4 @@
from django import http
from django.shortcuts import redirect
from django.utils.encoding import smart_unicode as u
from amo.helpers import page_title
@ -26,4 +25,4 @@ def share(request, obj, name, description):
'description': description,
})
form.full_clean()
return redirect(service.url.format(**form.cleaned_data))
return http.HttpResponseRedirect(service.url.format(**form.cleaned_data))

Просмотреть файл

@ -1044,4 +1044,5 @@ def preapproval(request):
'key': result['preapprovalKey'],
'expiry': data['endDate'],
}
return redirect(paypal.get_preapproval_url(result['preapprovalKey']))
to = paypal.get_preapproval_url(result['preapprovalKey'])
return http.HttpResponseRedirect(to)

Просмотреть файл

@ -54,7 +54,8 @@ def _find_version_page(qs, addon, version_num):
url = reverse('addons.versions', args=[addon.slug])
if version_num in ids:
page = 1 + ids.index(version_num) / PER_PAGE
return redirect(urlparams(url, 'version-%s' % version_num, page=page))
to = urlparams(url, 'version-%s' % version_num, page=page)
return http.HttpResponseRedirect(to)
else:
raise http.Http404()
@ -169,4 +170,4 @@ def download_latest(request, addon, type='xpi', platform=None):
url = posixpath.join(reverse(pattern, args=args), file.filename)
if request.GET:
url += '?' + request.GET.urlencode()
return redirect(url)
return http.HttpResponseRedirect(url)