* Fixed issue #29, thank you to Jason Nolen for reporting it. Prior

versions of Python used a different name for base64 functions, so 
  a wrapper has been added to lib.py to enable both old- and new-
  style functions to be used.
This commit is contained in:
Ross Poulton 2008-11-18 00:14:36 +00:00
parent 3361e08458
commit 77f3e71bd9
3 changed files with 21 additions and 8 deletions

9
lib.py
View File

@ -8,6 +8,14 @@ lib.py - Common functions (eg multipart e-mail)
chart_colours = ('80C65A', '990066', 'FF9900', '3399CC', 'BBCCED', '3399CC', 'FFCC33')
try:
from base64 import urlsafe_b64encode as b64encode
except ImportError:
from base64 import encodestring as b64encode
try:
from base64 import urlsafe_b64decode as b64decode
except ImportError:
from base64 import decodestring as b64decode
def send_templated_mail(template_name, email_context, recipients, sender=None, bcc=None, fail_silently=False, files=None):
"""
@ -327,3 +335,4 @@ def safe_template_context(ticket):
context['ticket']['assigned_to'] = context['ticket']['_get_assigned_to']
return context

View File

@ -880,14 +880,16 @@ class UserSettings(models.Model):
def _set_settings(self, data):
# data should always be a Python dictionary.
import cPickle, base64
self.settings_pickled = base64.urlsafe_b64encode(cPickle.dumps(data))
import cPickle
from helpdesk.lib import b64encode
self.settings_pickled = b64encode(cPickle.dumps(data))
def _get_settings(self):
# return a python dictionary representing the pickled data.
import cPickle, base64
import cPickle
from helpdesk.lib import b64decode
try:
return cPickle.loads(base64.urlsafe_b64decode(str(self.settings_pickled)))
return cPickle.loads(b64decode(str(self.settings_pickled)))
except cPickle.UnpicklingError:
return {}

View File

@ -308,8 +308,9 @@ def ticket_list(request):
if not (saved_query.shared or saved_query.user == request.user):
return HttpResponseRedirect(reverse('helpdesk_list'))
import base64, cPickle
query_params = cPickle.loads(base64.urlsafe_b64decode(str(saved_query.query)))
import cPickle
from helpdesk.lib import b64decode
query_params = cPickle.loads(b64decode(str(saved_query.query)))
elif not ( request.GET.has_key('queue')
or request.GET.has_key('assigned_to')
or request.GET.has_key('status')
@ -366,8 +367,9 @@ def ticket_list(request):
tickets = apply_query(Ticket.objects.select_related(), query_params)
import cPickle, base64
urlsafe_query = base64.urlsafe_b64encode(cPickle.dumps(query_params))
import cPickle
from helpdesk.lib import b64encode
urlsafe_query = b64encode(cPickle.dumps(query_params))
user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))