[error-report-web] Post/views.py: Fix for python3

Submitted by Robert Yang on March 5, 2019, 8:53 a.m. | Patch ID: 159293

Details

Message ID 1551776002-130748-1-git-send-email-liezhi.yang@windriver.com
State New
Headers show

Commit Message

Robert Yang March 5, 2019, 8:53 a.m.
Now it works for python 2 and 3.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 Post/views.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/Post/views.py b/Post/views.py
index 7f2cffb..2f8e4ae 100644
--- a/Post/views.py
+++ b/Post/views.py
@@ -13,9 +13,9 @@  from django.shortcuts import HttpResponse, render
 from django.views.decorators.csrf import csrf_exempt
 from django.shortcuts import redirect
 from Post.models import BuildFailure, Build, ErrorType
-from parser import Parser
+from .parser import Parser
 from django.conf import settings
-from createStatistics import Statistics
+from .createStatistics import Statistics
 from django.core.paginator import Paginator, EmptyPage
 from django.core.exceptions import FieldError, ObjectDoesNotExist
 from django.http import JsonResponse
@@ -55,20 +55,23 @@  def addData(request, return_json=False):
             # Backward compatibility with send-error-report < 0.3
             # The json is url encoded so we need to undo this here.
             data = request.body[len('data='):]
-            data = urllib.unquote_plus(data)
+            data = urllib.parse.unquote_plus(data)
+
+        data = data.decode('utf-8')
 
         p = Parser(data)
         result = p.parse(request)
+        print(result)
 
         if return_json:
             response = JsonResponse(result)
         else:
-            if not result.has_key('error'):
+            if 'error' not in result:
               response = HttpResponse("Your entry can be found here: "+result['build_url'])
             else:
               response = HttpResponse(result['error'])
 
-        if result.has_key('error'):
+        if 'error' in result:
             response.status_code=500
     else:
         if return_json:
@@ -123,7 +126,7 @@  def search(request, mode=results_mode.LATEST, **kwargs):
 
     items = BuildFailure.objects.all()
 
-    if request.GET.has_key("limit"):
+    if "limit" in request.GET:
         try:
             n_limit = int(request.GET['limit'])
             if n_limit > 0:
@@ -200,14 +203,14 @@  def search(request, mode=results_mode.LATEST, **kwargs):
       ],
     }
 
-    if request.GET.has_key("filter") and request.GET.has_key("type"):
+    if "filter" in request.GET and "type" in request.GET:
         items = apply_filter(context, items, request.GET['type'], request.GET['filter'])
     if mode == results_mode.SPECIAL_SUBMITTER and hasattr(settings,"SPECIAL_SUBMITTER"):
         #Special submitter mode see settings.py to enable
         name = settings.SPECIAL_SUBMITTER['name']
         items = items.filter(BUILD__NAME__istartswith=name)
 
-    elif mode == results_mode.SEARCH and request.GET.has_key("query"):
+    elif mode == results_mode.SEARCH and "query" in request.GET:
         query = request.GET["query"]
 
         items = items.filter(