Generic unicode updates

This commit is contained in:
Magnus Hagander
2019-01-19 19:48:47 +01:00
parent 7547b6f766
commit a156829375
28 changed files with 62 additions and 62 deletions

View 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

View 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:

View 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

View 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:

View 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)

View 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,

View 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):
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:

View 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

View 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')

View 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:

View 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:

View 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):

View 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 ''

View 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:

View 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)

View 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,
})

View 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):

View 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',)

View 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:

View 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

View 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:

View 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

View 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:

View File

@ -30,7 +30,7 @@ class Survey(models.Model):
purge_urls = ('/community/survey', '/community/$')
def __unicode__(self):
def __str__(self):
return self.question
@property

View 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]
}

View 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]),
))

View File

@ -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:

View 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')