[extensions-web] Replace custom post_only_view with the standard require_POST decorator
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Replace custom post_only_view with the standard require_POST decorator
- Date: Wed, 14 Dec 2011 22:12:05 +0000 (UTC)
commit 9befe6fd88815858b1736c1b3de8cb2d2d913110
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Dec 14 17:07:04 2011 -0500
Replace custom post_only_view with the standard require_POST decorator
sweettooth/auth/views.py | 5 +++--
sweettooth/decorators.py | 8 --------
sweettooth/errorreports/views.py | 2 +-
sweettooth/extensions/views.py | 13 +++++++------
sweettooth/review/views.py | 5 +++--
5 files changed, 14 insertions(+), 19 deletions(-)
---
diff --git a/sweettooth/auth/views.py b/sweettooth/auth/views.py
index fb1dcd5..3372a11 100644
--- a/sweettooth/auth/views.py
+++ b/sweettooth/auth/views.py
@@ -3,11 +3,12 @@ from django.contrib.auth import models
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404, redirect
+from django.views.decorators.http import require_POST
from review.models import CodeReview
from extensions.models import Extension
-from decorators import ajax_view, post_only_view
+from decorators import ajax_view
from utils import render
def profile(request, user):
@@ -28,7 +29,7 @@ def profile(request, user):
is_editable=is_editable))
@ajax_view
- post_only_view
+ require_POST
@login_required
def ajax_change_display_name(request):
if request.POST['id'] != 'new_display_name':
diff --git a/sweettooth/decorators.py b/sweettooth/decorators.py
index ca548b0..9205315 100644
--- a/sweettooth/decorators.py
+++ b/sweettooth/decorators.py
@@ -15,14 +15,6 @@ def model_view(model):
return new_view
return inner
-def post_only_view(view):
- @functools.wraps(view)
- def new_view(request, **kw):
- if request.method != 'POST':
- return HttpResponseForbidden()
- return view(request, **kw)
- return new_view
-
def ajax_view(view):
@functools.wraps(view)
def new_view(request, **kw):
diff --git a/sweettooth/errorreports/views.py b/sweettooth/errorreports/views.py
index 2a7dde4..07536a2 100644
--- a/sweettooth/errorreports/views.py
+++ b/sweettooth/errorreports/views.py
@@ -12,7 +12,7 @@ from errorreports.models import ErrorReport, error_reported
from errorreports.forms import ErrorReportForm
from extensions.models import Extension
-from decorators import post_only_view, model_view
+from decorators import model_view
from utils import render
@model_view(Extension.objects.visible())
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 1d8dc85..95f2c5c 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -9,12 +9,13 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils import simplejson as json
+from django.views.decorators.http import require_POST
from sorl.thumbnail.shortcuts import get_thumbnail
from extensions import models
from extensions.forms import UploadForm
-from decorators import ajax_view, model_view, post_only_view
+from decorators import ajax_view, model_view
from utils import render
def shell_download(request, uuid):
@@ -35,7 +36,7 @@ def shell_download(request, uuid):
return redirect(version.source.url)
@ajax_view
- post_only_view
+ require_POST
def shell_update(request):
installed = json.loads(request.POST['installed'])
operations = {}
@@ -185,7 +186,7 @@ def extension_version_view(request, obj, **kwargs):
return render(request, template_name, context)
@ajax_view
- post_only_view
+ require_POST
@model_view(models.ExtensionVersion)
def ajax_submit_and_lock_view(request, obj):
if not obj.extension.user_can_edit(request.user):
@@ -200,7 +201,7 @@ def ajax_submit_and_lock_view(request, obj):
models.submitted_for_review.send(sender=request, request=request, version=obj)
@ajax_view
- post_only_view
+ require_POST
@model_view(models.Extension)
def ajax_inline_edit_view(request, obj):
if not obj.user_can_edit(request.user):
@@ -225,7 +226,7 @@ def ajax_inline_edit_view(request, obj):
return value
@ajax_view
- post_only_view
+ require_POST
@model_view(models.Extension)
def ajax_upload_screenshot_view(request, obj):
obj.screenshot = request.FILES['file']
@@ -233,7 +234,7 @@ def ajax_upload_screenshot_view(request, obj):
return get_thumbnail(obj.screenshot, request.GET['geometry']).url
@ajax_view
- post_only_view
+ require_POST
@model_view(models.Extension)
def ajax_upload_icon_view(request, obj):
obj.icon = request.FILES['file']
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index 14267a6..05c9d31 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -17,12 +17,13 @@ from django.template import Context
from django.template.loader import render_to_string
from django.utils.html import escape
from django.utils import simplejson as json
+from django.views.decorators.http import require_POST
from review.diffview import get_chunks_html, split_lines, NoWrapperHtmlFormatter
from review.models import CodeReview, ChangeStatusLog, get_all_reviewers
from extensions import models
-from decorators import ajax_view, model_view, post_only_view
+from decorators import ajax_view, model_view
from utils import render
IMAGE_TYPES = {
@@ -222,7 +223,7 @@ def download_zipfile(request, pk):
return redirect(version.source.url)
- post_only_view
+ require_POST
@model_view(models.ExtensionVersion)
def submit_review_view(request, obj):
extension, version = obj.extension, obj
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]