Generic unicode updates
authorMagnus Hagander <magnus@hagander.net>
Sat, 19 Jan 2019 18:48:47 +0000 (19:48 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sat, 26 Jan 2019 15:19:26 +0000 (16:19 +0100)
28 files changed:
pgweb/account/models.py
pgweb/account/recaptcha.py
pgweb/account/views.py
pgweb/contributors/models.py
pgweb/core/lookups.py
pgweb/core/management/commands/moderation_report.py
pgweb/core/models.py
pgweb/core/templatetags/pgfilters.py
pgweb/core/views.py
pgweb/docs/models.py
pgweb/downloads/models.py
pgweb/events/models.py
pgweb/featurematrix/models.py
pgweb/lists/models.py
pgweb/mailqueue/models.py
pgweb/news/management/commands/twitter_post.py
pgweb/news/models.py
pgweb/profserv/admin.py
pgweb/profserv/models.py
pgweb/pugs/models.py
pgweb/quotes/models.py
pgweb/security/models.py
pgweb/sponsors/models.py
pgweb/survey/models.py
pgweb/util/moderation.py
pgweb/util/signals.py
tools/docs/docload.py
tools/search/crawler/lib/parsers.py

index 8db9c5f7c00ea31e57d7a49512d1d934126f26ea..a5600bd88a60ce4d7d63cc8471e1bb8c29e52c82 100644 (file)
@@ -7,7 +7,7 @@ class CommunityAuthOrg(models.Model):
                                help_text="Name of the organisation")
     require_consent = models.BooleanField(null=False, blank=False, default=True)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.orgname
 
 
@@ -22,7 +22,7 @@ class CommunityAuthSite(models.Model):
     cooloff_hours = models.IntegerField(null=False, blank=False, default=0,
                                         help_text="Number of hours a user must have existed in the systems before allowed to log in to this site")
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
 
index 51dbfe40f1f3100e0b73c9071f08563c1a01a655..a3688c564417851117b2374ec1e6341cc50c41ce 100644 (file)
@@ -18,9 +18,9 @@ log = logging.getLogger(__name__)
 class ReCaptchaWidget(forms.widgets.Widget):
     def render(self, name, value, attrs=None):
         if settings.NOCAPTCHA:
-            return u'Captcha disabled on this system'
+            return 'Captcha disabled on this system'
         log.info("Generated captcha")
-        return mark_safe(u'<div class="g-recaptcha" data-sitekey="{0}"></div>'.format(settings.RECAPTCHA_SITE_KEY))
+        return mark_safe('<div class="g-recaptcha" data-sitekey="{0}"></div>'.format(settings.RECAPTCHA_SITE_KEY))
 
     def value_from_datadict(self, data, files, name):
         if settings.NOCAPTCHA:
index 6a014d1559545a03aca24b0027614e374feeaa26..e61f37431dbadf1e5e373e6900faac3192b20cc4 100644 (file)
@@ -428,9 +428,9 @@ def signup_oauth(request):
         l = request.session['oauth_lastname'].lower()
         if f and l:
             for u in itertools.chain([
-                    u"{0}{1}".format(f, l[0]),
-                    u"{0}{1}".format(f[0], l),
-            ], (u"{0}{1}{2}".format(f, l[0], n) for n in xrange(100))):
+                    "{0}{1}".format(f, l[0]),
+                    "{0}{1}".format(f[0], l),
+            ], ("{0}{1}{2}".format(f, l[0], n) for n in range(100))):
                 if not User.objects.filter(username=u[:30]).exists():
                     suggested_username = u[:30]
                     break
index f75f8c85988402c0975a4491fedcea505e447f7d..1ae9c1f8c660af4310d8c00037a44e3e0fa1b0b8 100644 (file)
@@ -11,7 +11,7 @@ class ContributorType(models.Model):
 
     purge_urls = ('/community/contributors/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.typename
 
     class Meta:
@@ -32,7 +32,7 @@ class Contributor(models.Model):
     send_notification = True
     purge_urls = ('/community/contributors/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s %s" % (self.firstname, self.lastname)
 
     class Meta:
index 3d42ffe5027fa2ae49ed7624cb1b98246574b8de..8a5c021c8b73a3af92f64575562386fe246e5c1c 100644 (file)
@@ -16,11 +16,11 @@ class UserLookup(ModelLookup):
 
     def get_item_value(self, item):
         # Display for currently selected item
-        return u"%s (%s)" % (item.username, item.get_full_name())
+        return "%s (%s)" % (item.username, item.get_full_name())
 
     def get_item_label(self, item):
         # Display for choice listings
-        return u"%s (%s)" % (item.username, item.get_full_name())
+        return "%s (%s)" % (item.username, item.get_full_name())
 
 
 registry.register(UserLookup)
index c1be3ffb8fa203d341844e010895c2500de8845b..42c4647b3d0a81bc0a2331f4379a067309b5025e 100644 (file)
@@ -20,7 +20,7 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         with transaction.atomic():
-            counts = [{'name': unicode(x['name']), 'count': len(x['entries'])} for x in get_all_pending_moderations()]
+            counts = [{'name': str(x['name']), 'count': len(x['entries'])} for x in get_all_pending_moderations()]
             if len(counts):
                 # Generate an email and send it off
                 send_template_mail(settings.NOTIFICATION_FROM,
index 93a8b8f9eccefe2d97b12b4e07d42ff0d54a1dca..d8ce70272667993cd3d0157b5d45268354fd831e 100644 (file)
@@ -26,7 +26,7 @@ class Version(models.Model):
     firstreldate = models.DateField(null=False, blank=False, help_text="The date of the .0 release in this tree")
     eoldate = models.DateField(null=False, blank=False, help_text="The final release date for this tree")
 
-    def __unicode__(self):
+    def __str__(self):
         return self.versionstring
 
     @property
@@ -93,7 +93,7 @@ class Country(models.Model):
         verbose_name = 'Country'
         verbose_name_plural = 'Countries'
 
-    def __unicode__(self):\r
+    def __str__(self):
         return self.name
 
 
@@ -110,14 +110,14 @@ class Language(models.Model):
     class Meta:
         ordering = ('name', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
 
 class OrganisationType(models.Model):
     typename = models.CharField(max_length=32, null=False, blank=False)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.typename
 
 
@@ -135,7 +135,7 @@ class Organisation(models.Model):
     send_notification = True
     send_m2m_notification = True
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     class Meta:
@@ -152,7 +152,7 @@ class ImportedRSSFeed(models.Model):
         if self.purgepattern:
             varnish_purge(self.purgepattern)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.internalname
 
 
@@ -162,7 +162,7 @@ class ImportedRSSItem(models.Model):
     url = models.URLField(null=False, blank=False)
     posttime = models.DateTimeField(null=False, blank=False)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
 
     @property
@@ -186,7 +186,7 @@ def validate_sshkey(key):
         if pieces[0] == 'ssh-dss':
             raise ValidationError("For security reasons, ssh-dss keys are not supported")
         if pieces[0] not in _valid_keytypes:
-            raise ValidationError(u"Only keys of types {0} are supported, not {1}.".format(", ".join(_valid_keytypes), pieces[0]))
+            raise ValidationError("Only keys of types {0} are supported, not {1}.".format(", ".join(_valid_keytypes), pieces[0]))
         try:
             base64.b64decode(pieces[1])
         except:
@@ -210,7 +210,7 @@ class ModerationNotification(models.Model):
     author = models.CharField(null=False, blank=False, max_length=100)
     date = models.DateTimeField(null=False, blank=False, auto_now=True)
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s id %s (%s): %s" % (self.objecttype, self.objectid, self.date, self.text[:50])
 
     class Meta:
index a166c6ffd09907641743b6762ed7878c85307652..13f2470c11068b39fac15f634d97d79eee4ca36d 100644 (file)
@@ -38,7 +38,7 @@ def ismultiplecheckboxes(obj):
 
 @register.filter(is_safe=True)
 def isrequired_error(obj):
-    if obj.errors and obj.errors[0] == u"This field is required.":
+    if obj.errors and obj.errors[0] == "This field is required.":
         return True
     return False
 
index 1e54e88599e1714e12c1382ef970c9e1fcc58e92..bd33eebff6f31dd31eaab28c85fa1f45cf16ed61 100644 (file)
@@ -167,7 +167,7 @@ def _make_sitemap(pagelist):
         x.startElement('url', {})
         x.add_xml_element('loc', 'https://www.postgresql.org/%s' % urllib.quote(p[0]))
         if len(p) > 1 and p[1]:
-            x.add_xml_element('priority', unicode(p[1]))
+            x.add_xml_element('priority', str(p[1]))
         if len(p) > 2 and p[2]:
             x.add_xml_element('lastmod', p[2].isoformat() + "Z")
         x.endElement('url')
index 2e6124177291bc798cd8a3b6a5e1806631af7a55..89d326680ee41c8efca71566b3a03709599b4467 100644 (file)
@@ -26,8 +26,8 @@ class DocPageAlias(models.Model):
     file1 = models.CharField(max_length=64, null=False, blank=False, unique=True)
     file2 = models.CharField(max_length=64, null=False, blank=False, unique=True)
 
-    def __unicode__(self):
-        return u"%s <-> %s" % (self.file1, self.file2)
+    def __str__(self):
+        return "%s <-> %s" % (self.file1, self.file2)
 
     # XXX: needs a unique functional index as well, see the migration!
     class Meta:
index 003f0364f0ec6647b779e2834565f07e2abc61bc..0da39456186012719aeedc17177c335578306d60 100644 (file)
@@ -7,7 +7,7 @@ class Category(models.Model):
     catname = models.CharField(max_length=100, null=False, blank=False)
     blurb = models.TextField(null=False, blank=True)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.catname
 
     class Meta:
@@ -17,7 +17,7 @@ class Category(models.Model):
 class LicenceType(models.Model):
     typename = models.CharField(max_length=100, null=False, blank=False)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.typename
 
     class Meta:
@@ -38,7 +38,7 @@ class Product(models.Model):
     send_notification = True
     markdown_fields = ('description', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def verify_submitter(self, user):
@@ -96,7 +96,7 @@ class StackBuilderApp(models.Model):
 
     purge_urls = ('/applications-v2.xml', )
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s %s %s" % (self.textid, self.version, self.platform)
 
     class Meta:
index fa94c14a3fd9b9a5bc266fdf921c225198d9d459..9de2e83b494e147fbe2f9018579183c8cf1b9ac0 100644 (file)
@@ -32,7 +32,7 @@ class Event(models.Model):
         # FIXME: when to expire the front page?
         yield '/$'
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s: %s" % (self.startdate, self.title)
 
     def verify_submitter(self, user):
index 033c238f36de732d9321c639dcccdeaa2616d7cc..9e79ec8bc88586debd41779860681c35c49127b3 100644 (file)
@@ -15,7 +15,7 @@ class FeatureGroup(models.Model):
 
     purge_urls = ('/about/featurematrix/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.groupname
 
     @property
@@ -49,7 +49,7 @@ class Feature(models.Model):
 
     purge_urls = ('/about/featurematrix/.*', )
 
-    def __unicode__(self):
+    def __str__(self):
         # To make it look good in the admin interface, just don't render it
         return ''
 
index 55520e19a916b8b5210175df3a62eaff9bbde563..e0c56a52b83cdd2d8c90b7d639a05556ad1f96dc 100644 (file)
@@ -11,7 +11,7 @@ class MailingListGroup(models.Model):
     def negid(self):
         return -self.id
 
-    def __unicode__(self):
+    def __str__(self):
         return self.groupname
 
     class Meta:
@@ -33,7 +33,7 @@ class MailingList(models.Model):
             return self.shortdesc
         return self.listname
 
-    def __unicode__(self):
+    def __str__(self):
         return self.listname
 
     class Meta:
index f7018431a3ac9ad146bba14861eb27d5e11650be..becfb7363e0838e90ee61fbd07ce8ac55f5a33b8 100644 (file)
@@ -11,5 +11,5 @@ class QueuedMail(models.Model):
     # separately from an antispam and delivery perspective.
     usergenerated = models.BooleanField(null=False, blank=False, default=False)
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s: %s -> %s" % (self.pk, self.sender, self.receiver)
index 5e980fc110bc3a3c029c5579dd1f77167a6f918c..3efbdf40e0a5152e0aadab971873cd1a4221c08e 100644 (file)
@@ -36,7 +36,7 @@ class Command(BaseCommand):
 
         for a in articles:
             # We hardcode 30 chars for the URL shortener. And then 10 to cover the intro and spacing.
-            statusstr = u"News: {0} {1}/about/news/{2}/".format(a.title[:140 - 40], settings.SITE_ROOT, a.id)
+            statusstr = "News: {0} {1}/about/news/{2}/".format(a.title[:140 - 40], settings.SITE_ROOT, a.id)
             r = tw.post('https://api.twitter.com/1.1/statuses/update.json', data={
                 'status': statusstr,
             })
index ab6ed1487f7cab8c26e826aabd61fc280904c1c3..863a02086de951568e612660c94558d555a6195e 100644 (file)
@@ -8,7 +8,7 @@ class NewsTag(models.Model):
     name = models.CharField(max_length=32, null=False, blank=False)
     description = models.CharField(max_length=200, null=False, blank=False)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     class Meta:
@@ -36,7 +36,7 @@ class NewsArticle(models.Model):
         # FIXME: when to expire the front page?
         yield '/$'
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s: %s" % (self.date, self.title)
 
     def verify_submitter(self, user):
index 1094c50cd1511e41e1f21a25f1198fb935bf7be6..5d341e54cf8ab92516cdfaee3dffeddc9b6cd8dd 100644 (file)
@@ -5,7 +5,7 @@ from .models import ProfessionalService
 
 
 class ProfessionalServiceAdmin(PgwebAdmin):
-    list_display = ('__unicode__', 'approved',)
+    list_display = ('__str__', 'approved',)
     list_filter = ('approved',)
     search_fields = ('org__name',)
 
index 7f5b58db707be5b608ba2ed3a409fa21b61c619b..36b7a178b5abd525b632790018f5926dd5f5681c 100644 (file)
@@ -36,7 +36,7 @@ class ProfessionalService(models.Model):
     def verify_submitter(self, user):
         return (len(self.org.managers.filter(pk=user.pk)) == 1)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.org.name
 
     class Meta:
index acc42e09d35c568d542c05b35a4dbaddfb2fa866..c811297cae5c77cf7bb79497aeafdf9cab0be14f 100644 (file)
@@ -16,5 +16,5 @@ class PUG(models.Model):
     purge_urls = ('/community/user-groups/', )
     send_notification = True
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
index dbfa59ffc022a2c5e31a1105e21f207db78a2197..ec7b1ed30d90b4c333091e5f5bd35cbf7dd3fc0a 100644 (file)
@@ -12,7 +12,7 @@ class Quote(models.Model):
 
     purge_urls = ('/about/quotesarchive/', '/$', )
 
-    def __unicode__(self):
+    def __str__(self):
         if len(self.quote) > 75:
             return "%s..." % self.quote[:75]
         else:
index 6d88282cb5bdbc482d6cf2357a3209c13ae87a45..659e568a9d8fbd4a4e1f508b05fac8e17299b05d 100644 (file)
@@ -86,7 +86,7 @@ class SecurityPatch(models.Model):
             self.cvenumber = 100000 * int(m.groups(0)[0]) + int(m.groups(0)[1])
         super(SecurityPatch, self).save(force_insert, force_update)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.cve
 
     @property
index 378d789e96516a56c54b7cd0bf18140cd9e62dfd..215612b281cff033b8b26cfb26ac91aa2bd89837 100644 (file)
@@ -11,7 +11,7 @@ class SponsorType(models.Model):
 
     purge_urls = ('/about/servers/', '/about/sponsors/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.typename
 
     class Meta:
@@ -27,7 +27,7 @@ class Sponsor(models.Model):
 
     purge_urls = ('/about/sponsors/', '/about/servers/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     class Meta:
@@ -45,7 +45,7 @@ class Server(models.Model):
 
     purge_urls = ('/about/servers/', )
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     class Meta:
index ad4cd62bfd6152293b69f19f0b6c1c61cc32634e..e593da0aba0a4b5c4ec32bfbfc082b6647df10b3 100644 (file)
@@ -30,7 +30,7 @@ class Survey(models.Model):
 
     purge_urls = ('/community/survey', '/community/$')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.question
 
     @property
index 09ff63cf970cdd4bc01118b6355181a1a7f3d6fc..324a14880e67feb6b982562536ad01062d94e15c 100644 (file)
@@ -14,7 +14,7 @@ def _get_unapproved_list(objecttype):
         return None
     return {
         'name': objects[0]._meta.verbose_name_plural,
-        'entries': [{'url': '/admin/%s/%s/%s/' % (x._meta.app_label, x._meta.model_name, x.pk), 'title': unicode(x)} for x in objects]
+        'entries': [{'url': '/admin/%s/%s/%s/' % (x._meta.app_label, x._meta.model_name, x.pk), 'title': str(x)} for x in objects]
     }
 
 
index 02ed8035b2f2c688a9f46d7f2a78614d07d3431f..15179cb682b944b890c99561885c2855240e9087 100644 (file)
@@ -67,7 +67,7 @@ def _get_attr_value(obj, fieldname):
         return ''
 
     # Return the value, or an empty tring if it's NULL (migrated records)
-    return unicode(getattr(obj, fieldname)) or ''
+    return str(getattr(obj, fieldname)) or ''
 
 
 def _get_full_text_representation(obj):
@@ -75,7 +75,7 @@ def _get_full_text_representation(obj):
     if not fieldlist:
         return "This object does not know how to express itself."
 
-    return "\n".join([u'%s: %s' % (n, _get_attr_value(obj, n)) for n in fieldlist])
+    return "\n".join(['%s: %s' % (n, _get_attr_value(obj, n)) for n in fieldlist])
 
 
 def _get_notification_text(obj):
@@ -138,9 +138,9 @@ def my_m2m_changed_handler(sender, **kwargs):
         if not hasattr(instance, '_stored_m2m'):
             instance._stored_m2m = {}
         if kwargs['action'] == 'pre_clear':
-            instance._stored_m2m[f] = set([unicode(t) for t in getattr(instance, f).all()])
+            instance._stored_m2m[f] = set([str(t) for t in getattr(instance, f).all()])
         elif kwargs['action'] == 'post_add':
-            newset = set([unicode(t) for t in getattr(instance, f).all()])
+            newset = set([str(t) for t in getattr(instance, f).all()])
             added = newset.difference(instance._stored_m2m.get(f, set()))
             removed = instance._stored_m2m.get(f, set()).difference(newset)
             subj = '{0} id {1} has been modified'.format(instance._meta.verbose_name, instance.id)
@@ -150,8 +150,8 @@ def my_m2m_changed_handler(sender, **kwargs):
                                  "%s by %s" % (subj, get_current_user()),
                                  "The following values for {0} were changed:\n\n{1}\n{2}\n\n".format(
                                      instance._meta.get_field(f).verbose_name,
-                                     "\n".join([u"Added: %s" % a for a in added]),
-                                     "\n".join([u"Removed: %s" % r for r in removed]),
+                                     "\n".join(["Added: %s" % a for a in added]),
+                                     "\n".join(["Removed: %s" % r for r in removed]),
                                  ))
 
 
index 3a61391f863d994f1a71437b0c27fd2c28c758bc..1e4d08f3a678b75c0f517ef11644c93b91f29c91 100755 (executable)
@@ -48,7 +48,7 @@ def load_doc_file(filename, f):
     if float(ver) < 11 and float(ver) > 0:
         tidyopts['indent'] = 'no'
 
-    contents = unicode(rawcontents, encoding)
+    contents = str(rawcontents, encoding)
 
     tm = re_titlematch.search(contents)
     if tm:
index b176edd3b9f44c08996f0f35a31dc54972fce62c..369350ea222c41a7a805a4ca476f8535b8448748 100644 (file)
@@ -129,12 +129,12 @@ class ArchivesParser(object):
     # Semi-hacked rot13, because the one used by mhonarc is broken.
     # So we copy the brokenness here.
     # This code is from MHonArc/ewhutil.pl, mrot13()
-    _arot13_trans = dict(zip(map(ord,
-                                 u'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[abcdefghijklmnopqrstuvwxyz'),
-                             u'NOPQRSTUVWXYZ[@ABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'))
+    _arot13_trans = dict(list(zip(list(map(ord,
+                                           '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[abcdefghijklmnopqrstuvwxyz')),
+                                  'NOPQRSTUVWXYZ[@ABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm')))
 
     def almost_rot13(self, s):
-        return unicode(s).translate(self._arot13_trans)
+        return str(s).translate(self._arot13_trans)
 
 
 class RobotsParser(object):
@@ -168,9 +168,9 @@ class RobotsParser(object):
 # up and do a best-effort utf8.
 def lossy_unicode(s):
     try:
-        return unicode(s, 'utf8')
+        return str(s, 'utf8')
     except UnicodeDecodeError:
         try:
-            return unicode(s, 'latin1')
+            return str(s, 'latin1')
         except UnicodeDecodeError:
-            return unicode(s, 'utf8', 'replace')
+            return str(s, 'utf8', 'replace')