Merge pull request #544 from gwasser/decode

Support b64 decoding on py2 and py3
This commit is contained in:
Garret Wassermann 2017-08-30 10:52:43 -04:00 committed by GitHub
commit 87ee738428
2 changed files with 16 additions and 4 deletions

View File

@ -11,13 +11,17 @@ import mimetypes
import os
try:
# Python 2 support
from base64 import urlsafe_b64encode as b64encode
except ImportError:
from base64 import encodestring as b64encode
# Python 3 support
from base64 import encodebytes as b64encode
try:
# Python 2 support
from base64 import urlsafe_b64decode as b64decode
except ImportError:
from base64 import decodestring as b64decode
# Python 3 support
from base64 import decodebytes as b64decode
from django.conf import settings
from django.db.models import Q

View File

@ -25,6 +25,8 @@ from django.utils.html import escape
from django import forms
from django.utils import timezone
from django.utils import six
from helpdesk.forms import (
TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm,
TicketCCEmailForm, TicketCCUserForm, EditFollowUpForm, TicketDependencyForm
@ -817,7 +819,10 @@ def ticket_list(request):
import json
from helpdesk.lib import b64decode
try:
if six.PY3:
query_params = json.loads(b64decode(str(saved_query.query)).decode())
else:
query_params = json.loads(b64decode(str(saved_query.query)))
except ValueError:
# Query deserialization failed. (E.g. was a pickled query)
return HttpResponseRedirect(reverse('helpdesk:list'))
@ -1114,7 +1119,10 @@ def run_report(request, report):
import json
from helpdesk.lib import b64decode
try:
if six.PY3:
query_params = json.loads(b64decode(str(saved_query.query)).decode())
else:
query_params = json.loads(b64decode(str(saved_query.query)))
except:
return HttpResponseRedirect(reverse('helpdesk:report_index'))