Python2/3 compatibility: used @python_2_unicode_compatible to provide __unicode__() versions of __str__() methods.

- Legacy-Id: 16455
This commit is contained in:
Henrik Levkowetz 2019-07-15 18:01:26 +00:00
parent 2cfb81fc83
commit ea8c84d2f6
17 changed files with 137 additions and 12 deletions

View file

@ -5,3 +5,4 @@ su - -c "apt-get update \
&& apt-get install -qy graphviz ghostscript apache2-utils \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*"

View file

@ -1,14 +1,21 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.db.models import signals
from django.urls import reverse as urlreverse
from django.utils.encoding import python_2_unicode_compatible
from ietf.doc.models import Document, DocEvent, State
from ietf.group.models import Group
from ietf.person.models import Person, Email
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class CommunityList(models.Model):
user = ForeignKey(User, blank=True, null=True)
group = ForeignKey(Group, blank=True, null=True)
@ -34,6 +41,7 @@ class CommunityList(models.Model):
return ""
@python_2_unicode_compatible
class SearchRule(models.Model):
# these types define the UI for setting up the rule, and also
# helps when interpreting the rule and matching documents
@ -79,6 +87,7 @@ class SearchRule(models.Model):
def __str__(self):
return "%s %s %s/%s/%s/%s" % (self.community_list, self.rule_type, self.state, self.group, self.person, self.text)
@python_2_unicode_compatible
class EmailSubscription(models.Model):
community_list = ForeignKey(CommunityList)
email = ForeignKey(Email)

View file

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright The IETF Trust 2012-2019, All Rights Reserved
from __future__ import absolute_import, print_function, unicode_literals
from django.db import models
from django.core.exceptions import ValidationError
from django.template import Context
from django.utils.encoding import python_2_unicode_compatible
from ietf.group.models import Group
from ietf.name.models import DBTemplateTypeName
@ -19,6 +19,7 @@ TEMPLATE_TYPES = (
)
@python_2_unicode_compatible
class DBTemplate(models.Model):
path = models.CharField( max_length=255, unique=True, blank=False, null=False, )
title = models.CharField( max_length=255, blank=False, null=False, )

View file

@ -1,5 +1,6 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# -*- coding: utf-8 -*-
#
# Portion Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com>
#
@ -32,11 +33,15 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import, print_function, unicode_literals
import datetime
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class TelechatAgendaItem(models.Model):
TYPE_CHOICES = (
(1, "Any Other Business (WG News, New Proposals, etc.)"),
@ -51,7 +56,7 @@ class TelechatAgendaItem(models.Model):
def __str__(self):
type_name = self.TYPE_CHOICES_DICT.get(self.type, str(self.type))
return '%s: %s' % (type_name, self.title or "")
return "%s: %s" % (type_name, self.title or "")
class Telechat(models.Model):
telechat_id = models.IntegerField(primary_key=True)
@ -77,6 +82,7 @@ class TelechatDateManager(models.Manager):
def active(self):
return self.get_queryset().filter(date__gte=datetime.date.today())
@python_2_unicode_compatible
class TelechatDate(models.Model):
objects = TelechatDateManager()

View file

@ -1,10 +1,15 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
from django.conf import settings
from django.urls import reverse
from django.db import models
from django.urls import reverse
from django.utils.encoding import python_2_unicode_compatible
from ietf.doc.models import DocAlias
from ietf.name.models import DocRelationshipName,IprDisclosureStateName,IprLicenseTypeName,IprEventTypeName
@ -12,6 +17,7 @@ from ietf.person.models import Person
from ietf.message.models import Message
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class IprDisclosureBase(models.Model):
by = ForeignKey(Person) # who was logged in, or System if nobody was logged in
compliant = models.BooleanField("Complies to RFC3979", default=True)
@ -148,6 +154,7 @@ class GenericIprDisclosure(IprDisclosureBase):
holder_contact_info = models.TextField(blank=True, help_text="Address, phone, etc.")
statement = models.TextField() # includes licensing info
@python_2_unicode_compatible
class IprDocRel(models.Model):
disclosure = ForeignKey(IprDisclosureBase)
document = ForeignKey(DocAlias)
@ -178,6 +185,7 @@ class IprDocRel(models.Model):
else:
return "%s which applies to %s" % (self.disclosure, self.document.name)
@python_2_unicode_compatible
class RelatedIpr(models.Model):
source = ForeignKey(IprDisclosureBase,related_name='relatedipr_source_set')
target = ForeignKey(IprDisclosureBase,related_name='relatedipr_target_set')
@ -186,6 +194,7 @@ class RelatedIpr(models.Model):
def __str__(self):
return "%s %s %s" % (self.source.title, self.relationship.name.lower(), self.target.title)
@python_2_unicode_compatible
class IprEvent(models.Model):
time = models.DateTimeField(auto_now_add=True)
type = ForeignKey(IprEventTypeName)

View file

@ -1,8 +1,13 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.conf import settings
from django.urls import reverse as urlreverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.text import slugify
from ietf.person.models import Email, Person
@ -24,6 +29,7 @@ STATE_EVENT_MAPPING = {
}
@python_2_unicode_compatible
class LiaisonStatement(models.Model):
title = models.CharField(max_length=255)
from_groups = models.ManyToManyField(Group, blank=True, related_name='liaisonstatement_from_set')
@ -47,7 +53,6 @@ class LiaisonStatement(models.Model):
class Meta:
ordering = ['id']
def __str__(self):
return self.title or "<no title>"
@ -198,6 +203,7 @@ class LiaisonStatement(models.Model):
approval_set.intersection_update(group.liaison_approvers())
return list(set([ r.email.address for r in approval_set ]))
@python_2_unicode_compatible
class LiaisonStatementAttachment(models.Model):
statement = ForeignKey(LiaisonStatement)
document = ForeignKey(Document)
@ -207,6 +213,7 @@ class LiaisonStatementAttachment(models.Model):
return self.document.name
@python_2_unicode_compatible
class RelatedLiaisonStatement(models.Model):
source = ForeignKey(LiaisonStatement, related_name='source_of_set')
target = ForeignKey(LiaisonStatement, related_name='target_of_set')
@ -216,6 +223,7 @@ class RelatedLiaisonStatement(models.Model):
return "%s %s %s" % (self.source.title, self.relationship.name.lower(), self.target.title)
@python_2_unicode_compatible
class LiaisonStatementGroupContacts(models.Model):
group = ForeignKey(Group, unique=True, null=True)
contacts = models.CharField(max_length=255,blank=True)
@ -225,6 +233,7 @@ class LiaisonStatementGroupContacts(models.Model):
return "%s" % self.group.name
@python_2_unicode_compatible
class LiaisonStatementEvent(models.Model):
time = models.DateTimeField(auto_now_add=True)
type = ForeignKey(LiaisonStatementEventTypeName)

View file

@ -1,22 +1,29 @@
# Copyright The IETF Trust 2016-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.conf import settings
from django.core.validators import validate_email
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from ietf.person.models import Person
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class List(models.Model):
name = models.CharField(max_length=32)
description = models.CharField(max_length=256)
advertised = models.BooleanField(default=True)
def __str__(self):
return "<List: %s>" % self.name
def info_url(self):
return settings.MAILING_LIST_INFO_URL % {'list_addr': self.name }
@python_2_unicode_compatible
class Subscribed(models.Model):
time = models.DateTimeField(auto_now_add=True)
email = models.CharField(max_length=64, validators=[validate_email])
@ -26,6 +33,7 @@ class Subscribed(models.Model):
class Meta:
verbose_name_plural = "Subscribed"
@python_2_unicode_compatible
class Whitelisted(models.Model):
time = models.DateTimeField(auto_now_add=True)
email = models.CharField("Email address", max_length=64, validators=[validate_email])

View file

@ -1,7 +1,12 @@
# Copyright The IETF Trust 2015-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.db import models
from django.template import Template, Context
from django.utils.encoding import python_2_unicode_compatible
from email.utils import parseaddr
from ietf.utils.mail import formataddr, get_email_addresses_from_text
@ -28,6 +33,7 @@ def clean_duplicates(addrlist):
addresses.append(addr)
return addresses
@python_2_unicode_compatible
class MailTrigger(models.Model):
slug = models.CharField(max_length=32, primary_key=True)
desc = models.TextField(blank=True)
@ -40,6 +46,7 @@ class MailTrigger(models.Model):
def __str__(self):
return self.slug
@python_2_unicode_compatible
class Recipient(models.Model):
slug = models.CharField(max_length=32, primary_key=True)
desc = models.TextField(blank=True)

View file

@ -1,8 +1,14 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
import email.utils
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import debug # pyflakes:ignore
@ -13,6 +19,7 @@ from ietf.name.models import RoleName
from ietf.utils.models import ForeignKey
from ietf.utils.mail import get_email_addresses_from_text
@python_2_unicode_compatible
class Message(models.Model):
time = models.DateTimeField(default=datetime.datetime.now)
by = ForeignKey(Person)
@ -41,6 +48,7 @@ class Message(models.Model):
return r if isinstance(r, list) else get_email_addresses_from_text(r)
@python_2_unicode_compatible
class MessageAttachment(models.Model):
message = ForeignKey(Message)
filename = models.CharField(max_length=255, db_index=True, blank=True)
@ -53,6 +61,7 @@ class MessageAttachment(models.Model):
return self.filename
@python_2_unicode_compatible
class SendQueue(models.Model):
time = models.DateTimeField(default=datetime.datetime.now)
by = ForeignKey(Person)
@ -71,6 +80,7 @@ class SendQueue(models.Model):
return "'%s' %s -> %s (sent at %s)" % (self.message.subject, self.message.frm, self.message.to, self.sent_at or "<not yet>")
@python_2_unicode_compatible
class AnnouncementFrom(models.Model):
name = ForeignKey(RoleName)
group = ForeignKey(Group)

View file

@ -1,9 +1,15 @@
# Copyright The IETF Trust 2010-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class NameModel(models.Model):
slug = models.CharField(max_length=32, primary_key=True)
name = models.CharField(max_length=255)

View file

@ -1,5 +1,7 @@
# Copyright The IETF Trust 2012-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
from django.db import models
@ -8,6 +10,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.template.defaultfilters import linebreaks
from django.utils.encoding import python_2_unicode_compatible
import debug # pyflakes:ignore
@ -40,6 +43,7 @@ class ReminderDates(models.Model):
nomcom = ForeignKey('NomCom')
@python_2_unicode_compatible
class NomCom(models.Model):
public_key = models.FileField(storage=NoLocationMigrationFileSystemStorage(location=settings.NOMCOM_PUBLIC_KEYS_DIR),
upload_to=upload_path_handler, blank=True, null=True)
@ -82,14 +86,14 @@ class NomCom(models.Model):
def pending_email_count(self):
return self.feedback_set.filter(type__isnull=True).count()
def encrypt(self, cleartext:str) -> bytes:
def encrypt(self, cleartext):
try:
cert_file = self.public_key.path
except ValueError as e:
raise ValueError("Trying to read the NomCom public key: " + str(e))
command = "%s smime -encrypt -in /dev/stdin %s" % (settings.OPENSSL_COMMAND, cert_file)
code, out, error = pipe(command, cleartext.encode())
code, out, error = pipe(command, cleartext.encode('utf-8'))
if code != 0:
log("openssl error: %s:\n Error %s: %s" %(command, code, error))
if not error:
@ -106,6 +110,7 @@ def delete_nomcom(sender, **kwargs):
post_delete.connect(delete_nomcom, sender=NomCom)
@python_2_unicode_compatible
class Nomination(models.Model):
position = ForeignKey('Position')
candidate_name = models.CharField(verbose_name='Candidate name', max_length=255)
@ -130,6 +135,7 @@ class Nomination(models.Model):
return "%s (%s)" % (self.candidate_name, self.candidate_email)
@python_2_unicode_compatible
class Nominee(models.Model):
email = ForeignKey(Email)
@ -147,9 +153,9 @@ class Nominee(models.Model):
def __str__(self):
if self.email.person and self.email.person.name:
return '%s <%s> %s' % (self.email.person.plain_name(), self.email.address, self.nomcom.year())
return "%s <%s> %s" % (self.email.person.plain_name(), self.email.address, self.nomcom.year())
else:
return '%s %s' % (self.email.address, self.nomcom.year())
return "%s %s" % (self.email.address, self.nomcom.year())
def name(self):
if self.email.person and self.email.person.name:
@ -157,6 +163,7 @@ class Nominee(models.Model):
else:
return self.email.address
@python_2_unicode_compatible
class NomineePosition(models.Model):
position = ForeignKey('Position')
@ -186,6 +193,7 @@ class NomineePosition(models.Model):
nominees__in=[self.nominee])
@python_2_unicode_compatible
class Position(models.Model):
nomcom = ForeignKey('NomCom')
name = models.CharField(verbose_name='Name', max_length=255, help_text='This short description will appear on the Nomination and Feedback pages. Be as descriptive as necessary. Past examples: "Transport AD", "IAB Member"')
@ -232,6 +240,7 @@ class Position(models.Model):
rendered = linebreaks(rendered)
return rendered
@python_2_unicode_compatible
class Topic(models.Model):
nomcom = ForeignKey('NomCom')
subject = models.CharField(verbose_name='Name', max_length=255, help_text='This short description will appear on the Feedback pages.')
@ -261,6 +270,7 @@ class Topic(models.Model):
rendered = linebreaks(rendered)
return rendered
@python_2_unicode_compatible
class Feedback(models.Model):
nomcom = ForeignKey('NomCom')
author = models.EmailField(verbose_name='Author', blank=True)

View file

@ -1,9 +1,15 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class Redirect(models.Model):
"""Mapping of CGI script to url. The "rest" is a
sprintf-style string with %(param)s entries to insert
@ -24,6 +30,7 @@ class Redirect(models.Model):
def __str__(self):
return "%s -> %s/%s" % (self.cgi, self.url, self.rest)
@python_2_unicode_compatible
class Suffix(models.Model):
"""This is a "rest" and "remove" (see Redirect class)
for requests with command=.
@ -35,6 +42,7 @@ class Suffix(models.Model):
class Meta:
verbose_name_plural="Suffixes"
@python_2_unicode_compatible
class Command(models.Model):
"""When a request comes in with a command= argument,
the command is looked up in this table to see if there

View file

@ -1,10 +1,15 @@
# Copyright The IETF Trust 2016-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
from simple_history.models import HistoricalRecords
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from ietf.doc.models import Document
from ietf.group.models import Group
@ -13,6 +18,7 @@ from ietf.name.models import ReviewTypeName, ReviewRequestStateName, ReviewResul
from ietf.utils.validators import validate_regular_expression_string
from ietf.utils.models import ForeignKey, OneToOneField
@python_2_unicode_compatible
class ReviewerSettings(models.Model):
"""Keeps track of admin data associated with a reviewer in a team."""
history = HistoricalRecords()
@ -39,6 +45,7 @@ class ReviewerSettings(models.Model):
class Meta:
verbose_name_plural = "reviewer settings"
@python_2_unicode_compatible
class ReviewSecretarySettings(models.Model):
"""Keeps track of admin data associated with a secretary in a team."""
team = ForeignKey(Group, limit_choices_to=~models.Q(reviewteamsettings=None))
@ -51,6 +58,7 @@ class ReviewSecretarySettings(models.Model):
class Meta:
verbose_name_plural = "review secretary settings"
@python_2_unicode_compatible
class UnavailablePeriod(models.Model):
team = ForeignKey(Group, limit_choices_to=~models.Q(reviewteamsettings=None))
person = ForeignKey(Person)
@ -81,6 +89,7 @@ class UnavailablePeriod(models.Model):
def __str__(self):
return "{} is unavailable in {} {} - {}".format(self.person, self.team.acronym, self.start_date or "", self.end_date or "")
@python_2_unicode_compatible
class ReviewWish(models.Model):
"""Reviewer wishes to review a document when it becomes available for review."""
time = models.DateTimeField(default=datetime.datetime.now)
@ -95,6 +104,7 @@ class ReviewWish(models.Model):
verbose_name_plural = "review wishes"
@python_2_unicode_compatible
class NextReviewerInTeam(models.Model):
team = ForeignKey(Group, limit_choices_to=~models.Q(reviewteamsettings=None))
next_reviewer = ForeignKey(Person)
@ -106,6 +116,7 @@ class NextReviewerInTeam(models.Model):
verbose_name = "next reviewer in team setting"
verbose_name_plural = "next reviewer in team settings"
@python_2_unicode_compatible
class ReviewRequest(models.Model):
"""Represents a request for a review and the process it goes through."""
state = ForeignKey(ReviewRequestStateName)
@ -130,6 +141,7 @@ class ReviewRequest(models.Model):
def request_closed_time(self):
return self.doc.request_closed_time(self) or self.time
@python_2_unicode_compatible
class ReviewAssignment(models.Model):
""" One of possibly many reviews assigned in response to a ReviewRequest """
review_request = ForeignKey(ReviewRequest)
@ -152,6 +164,7 @@ def get_default_review_types():
def get_default_review_results():
return ReviewResultName.objects.filter(slug__in=['not-ready', 'right-track', 'almost-ready', 'ready-issues', 'ready-nits', 'ready'])
@python_2_unicode_compatible
class ReviewTeamSettings(models.Model):
"""Holds configuration specific to groups that are review teams"""
group = OneToOneField(Group)

View file

@ -1,8 +1,14 @@
# Copyright The IETF Trust 2013-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from ietf.meeting.models import Meeting
@ -57,6 +63,7 @@ class InterimMeeting(Meeting):
else:
return ''
@python_2_unicode_compatible
class Registration(models.Model):
rsn = models.AutoField(primary_key=True)
fname = models.CharField(max_length=255)

View file

@ -831,6 +831,7 @@ MEETING_VALID_MIME_TYPE_EXTENSIONS = {
INTERNET_DRAFT_DAYS_TO_EXPIRE = 185
FLOORPLAN_MEDIA_DIR = 'floor'
FLOORPLAN_DIR = os.path.join(MEDIA_ROOT, FLOORPLAN_MEDIA_DIR)
# ==============================================================================

View file

@ -1,6 +1,11 @@
# Copyright The IETF Trust 2017-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import debug # pyflakes:ignore
@ -10,6 +15,7 @@ from ietf.person.models import Person
from ietf.utils.models import ForeignKey
@python_2_unicode_compatible
class AffiliationAlias(models.Model):
"""Records that alias should be treated as name for statistical
purposes."""
@ -27,6 +33,7 @@ class AffiliationAlias(models.Model):
class Meta:
verbose_name_plural = "affiliation aliases"
@python_2_unicode_compatible
class AffiliationIgnoredEnding(models.Model):
"""Records that ending should be stripped from the affiliation for statistical purposes."""
@ -35,6 +42,7 @@ class AffiliationIgnoredEnding(models.Model):
def __str__(self):
return self.ending
@python_2_unicode_compatible
class CountryAlias(models.Model):
"""Records that alias should be treated as country for statistical
purposes."""
@ -48,6 +56,7 @@ class CountryAlias(models.Model):
class Meta:
verbose_name_plural = "country aliases"
@python_2_unicode_compatible
class MeetingRegistration(models.Model):
"""Registration attendee records from the IETF registration system"""
meeting = ForeignKey(Meeting)

View file

@ -1,9 +1,15 @@
# Copyright The IETF Trust 2011-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
import email
import jsonfield
from django.db import models
import jsonfield
from django.utils.encoding import python_2_unicode_compatible
import debug # pyflakes:ignore
@ -24,6 +30,7 @@ def parse_email_line(line):
name, addr = email.utils.parseaddr(line) if '@' in line else (line, '')
return dict(name=name, email=addr)
@python_2_unicode_compatible
class Submission(models.Model):
state = ForeignKey(DraftSubmissionStateName)
remote_ip = models.CharField(max_length=100, blank=True)
@ -71,6 +78,7 @@ class Submission(models.Model):
checks = [ self.checks.filter(checker=c).latest('time') for c in self.checks.values_list('checker', flat=True).distinct() ]
return checks
@python_2_unicode_compatible
class SubmissionCheck(models.Model):
time = models.DateTimeField(default=datetime.datetime.now)
submission = ForeignKey(Submission, related_name='checks')
@ -89,6 +97,7 @@ class SubmissionCheck(models.Model):
def has_errors(self):
return self.errors != '[]'
@python_2_unicode_compatible
class SubmissionEvent(models.Model):
submission = ForeignKey(Submission)
time = models.DateTimeField(default=datetime.datetime.now)
@ -102,6 +111,7 @@ class SubmissionEvent(models.Model):
ordering = ("-time", "-id")
@python_2_unicode_compatible
class Preapproval(models.Model):
"""Pre-approved draft submission name."""
name = models.CharField(max_length=255, db_index=True)
@ -111,6 +121,7 @@ class Preapproval(models.Model):
def __str__(self):
return self.name
@python_2_unicode_compatible
class SubmissionEmailEvent(SubmissionEvent):
message = ForeignKey(Message, null=True, blank=True,related_name='manualevents')
msgtype = models.CharField(max_length=25)