From 6a99c94b47c26d8932b1d6ee4593d124867eaacd Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Thu, 18 Jul 2019 11:47:21 -0500
Subject: [PATCH] Python 3: remove use of unicode()

---
 gracedb/api/v1/events/views.py                             | 2 +-
 gracedb/events/templatetags/logtags.py                     | 3 ---
 gracedb/events/templatetags/scientific.py                  | 5 +++--
 .../commands/update_user_accounts_from_ligo_ldap.py        | 7 ++++---
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/gracedb/api/v1/events/views.py b/gracedb/api/v1/events/views.py
index 58fc41311..9b7f81633 100644
--- a/gracedb/api/v1/events/views.py
+++ b/gracedb/api/v1/events/views.py
@@ -1281,7 +1281,7 @@ class EventLogTagDetail(InheritPermissionsAPIView):
             # client that the creation was sucessful when, in fact, the database
             # was unchanged.
             tag = eventlog.tags.filter(name=tagname)[0]
-            msg = "Log already has tag %s" % unicode(tag)
+            msg = "Log already has tag {0}".format(tag.name)
             return Response(msg,status=status.HTTP_409_CONFLICT)
         except:
             # Check authorization
diff --git a/gracedb/events/templatetags/logtags.py b/gracedb/events/templatetags/logtags.py
index 0e38cfac6..d07c6188e 100644
--- a/gracedb/events/templatetags/logtags.py
+++ b/gracedb/events/templatetags/logtags.py
@@ -19,9 +19,6 @@ def getLogsForTag(event,name=None):
         # In either case, we want the template to just ignore it.
         return None
 
-@register.filter("tagUnicode")
-def tagUnicode(tag):
-    return unicode(tag);
 
 @register.filter("logsForTagHaveImage")
 def logsForTagAllHaveImages(event,name=None):
diff --git a/gracedb/events/templatetags/scientific.py b/gracedb/events/templatetags/scientific.py
index 0c3df5d80..ce1281520 100644
--- a/gracedb/events/templatetags/scientific.py
+++ b/gracedb/events/templatetags/scientific.py
@@ -1,3 +1,4 @@
+from builtins import str
 from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
 from django import template
 from django.utils.encoding import force_text
@@ -61,7 +62,7 @@ def scientificformat(text):
         elif ( (d > Decimal('-100') and d < Decimal('-0.1')) or ( d > Decimal('0.1') and d < Decimal('100')) ) :
             # this is what the original floatformat() function does
             sign, digits, exponent = d.quantize(Decimal('.01'), ROUND_HALF_UP).as_tuple()
-            digits = [unicode(digit) for digit in reversed(digits)]
+            digits = [str(digit) for digit in reversed(digits)]
             while len(digits) <= abs(exponent):
                 digits.append(u'0')
             digits.insert(-exponent, u'.')
@@ -72,7 +73,7 @@ def scientificformat(text):
             # for very small and very large numbers
             sign, digits, exponent = d.as_tuple()
             exponent = d.adjusted()
-            digits = [unicode(digit) for digit in digits][:3] # limit to 2 decimal places
+            digits = [str(digit) for digit in digits][:3] # limit to 2 decimal places
             while len(digits) < 3:
                 digits.append(u'0')
             digits.insert(1, u'.')
diff --git a/gracedb/ligoauth/management/commands/update_user_accounts_from_ligo_ldap.py b/gracedb/ligoauth/management/commands/update_user_accounts_from_ligo_ldap.py
index 38fd05eda..2330e71a5 100644
--- a/gracedb/ligoauth/management/commands/update_user_accounts_from_ligo_ldap.py
+++ b/gracedb/ligoauth/management/commands/update_user_accounts_from_ligo_ldap.py
@@ -1,3 +1,4 @@
+from builtins import str
 import datetime
 import ldap
 
@@ -33,8 +34,8 @@ class LdapPersonResultProcessor(object):
         if self.ldap_connection is None:
             raise RuntimeError('LDAP connection not configured')
         self.user_data = {
-            'first_name': unicode(self.ldap_result['givenName'][0], 'utf-8'),
-            'last_name': unicode(self.ldap_result['sn'][0], 'utf-8'),
+            'first_name': str(self.ldap_result['givenName'][0], 'utf-8'),
+            'last_name': str(self.ldap_result['sn'][0], 'utf-8'),
             'email': self.ldap_result['mail'][0],
             'is_active': self.ldap_connection.lvc_group.ldap_name in
                 self.ldap_result.get('isMemberOf', []),
@@ -239,7 +240,7 @@ class LdapRobotResultProcessor(LdapPersonResultProcessor):
         if self.ldap_connection is None:
             raise RuntimeError('LDAP connection not configured')
         self.user_data = {
-            'last_name': unicode(self.ldap_result['x-LIGO-TWikiName'][0],
+            'last_name': str(self.ldap_result['x-LIGO-TWikiName'][0],
                 'utf-8'),
             'email': self.ldap_result['mail'][0],
             'is_active': self.ldap_connection.groups.get(
-- 
GitLab