From f0a4aba751e7c390fe178ffa24b3d10f2022cc9f Mon Sep 17 00:00:00 2001 From: j Date: Fri, 3 Mar 2017 08:56:35 +0100 Subject: [PATCH] use python_2_unicode_compatible --- pandora/annotation/models.py | 4 +++- pandora/app/models.py | 7 +++++-- pandora/archive/models.py | 17 +++++++++++------ pandora/changelog/models.py | 8 ++++++-- pandora/clip/models.py | 6 ++++-- pandora/document/models.py | 13 +++++++++---- pandora/documentcollection/models.py | 11 ++++++++--- pandora/edit/models.py | 10 +++++++--- pandora/entity/models.py | 10 +++++++--- pandora/event/models.py | 5 ++++- pandora/home/models.py | 5 ++++- pandora/item/models.py | 13 +++++++++---- pandora/itemlist/models.py | 10 +++++++--- pandora/log/models.py | 4 +++- pandora/news/models.py | 6 ++++-- pandora/person/models.py | 4 +++- pandora/place/models.py | 4 +++- pandora/sequence/models.py | 4 +++- pandora/taskqueue/models.py | 4 +++- pandora/text/models.py | 7 +++++-- pandora/title/models.py | 4 +++- pandora/tv/models.py | 7 +++++-- pandora/urlalias/models.py | 13 +++++++++---- pandora/user/models.py | 7 +++++-- 24 files changed, 130 insertions(+), 53 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index a31ca1f3..a10a6392 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import import re import unicodedata +from django.utils.encoding import python_2_unicode_compatible from django.db import models, transaction from django.db.models import Q from django.contrib.auth.models import User @@ -81,6 +82,7 @@ def get_matches(obj, model, layer_type, qs=None): matches = [-1] return Annotation.objects.filter(id__in=matches) +@python_2_unicode_compatible class Annotation(models.Model): objects = managers.AnnotationManager() @@ -380,7 +382,7 @@ class Annotation(models.Model): return j - def __unicode__(self): + def __str__(self): return u"%s %s-%s" % (self.public_id, self.start, self.end) def cleanup_related(sender, **kwargs): diff --git a/pandora/app/models.py b/pandora/app/models.py index 05d37987..7b5470b2 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -5,20 +5,23 @@ from __future__ import division, print_function, absolute_import import json from django.db import models +from django.utils.encoding import python_2_unicode_compatible from . import monkey_patch from . import tasks +@python_2_unicode_compatible class Page(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) name = models.CharField(max_length=1024, unique=True) text = models.TextField(blank=True) - def __unicode__(self): + def __str__(self): return self.name +@python_2_unicode_compatible class Settings(models.Model): created = models.DateTimeField(auto_now_add=True) @@ -26,7 +29,7 @@ class Settings(models.Model): key = models.CharField(max_length=1024, unique=True) value = models.TextField(blank=True) - def __unicode__(self): + def __str__(self): return self.key @classmethod diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 9a50524e..00d705e5 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -13,6 +13,7 @@ from django.conf import settings from django.contrib.auth.models import User from django.db import models from django.db.models.signals import pre_delete +from django.utils.encoding import python_2_unicode_compatible from oxdjango import fields import ox @@ -33,6 +34,7 @@ if not PY2: def data_path(f, x): return f.get_path('data.bin') +@python_2_unicode_compatible class File(models.Model): AV_INFO = ( 'duration', 'video', 'audio', 'oshash', 'size', @@ -103,7 +105,7 @@ class File(models.Model): objects = managers.FileManager() - def __unicode__(self): + def __str__(self): return self.path def parse_info(self): @@ -562,6 +564,7 @@ def delete_file(sender, **kwargs): f.delete_files() pre_delete.connect(delete_file, sender=File) +@python_2_unicode_compatible class Volume(models.Model): class Meta: @@ -573,7 +576,7 @@ class Volume(models.Model): user = models.ForeignKey(User, related_name='volumes') name = models.CharField(max_length=1024) - def __unicode__(self): + def __str__(self): return u"%s's %s" % (self.user, self.name) def json(self): @@ -586,6 +589,7 @@ class Volume(models.Model): def inttime(): return int(time.time()) +@python_2_unicode_compatible class Instance(models.Model): class Meta: @@ -604,7 +608,7 @@ class Instance(models.Model): file = models.ForeignKey(File, related_name='instances') volume = models.ForeignKey(Volume, related_name='files') - def __unicode__(self): + def __str__(self): return u"%s's %s <%s>" % (self.volume.user, self.path, self.file.oshash) @property @@ -624,7 +628,7 @@ def frame_path(frame, name): name = "%s%s" % (frame.position, ext) return frame.file.get_path(name) - +@python_2_unicode_compatible class Frame(models.Model): class Meta: @@ -643,7 +647,7 @@ class Frame(models.Model): self.height = self.frame.height super(Frame, self).save(*args, **kwargs) - def __unicode__(self): + def __str__(self): return u'%s/%s' % (self.file, self.position) def delete_frame(sender, **kwargs): @@ -655,6 +659,7 @@ pre_delete.connect(delete_frame, sender=Frame) def stream_path(f, x): return f.path(x) +@python_2_unicode_compatible class Stream(models.Model): class Meta: @@ -686,7 +691,7 @@ class Stream(models.Model): def name(self): return u"%sp.%s" % (self.resolution, self.format) - def __unicode__(self): + def __str__(self): return u"%s/%s" % (self.file, self.name()) def get(self, resolution, format): diff --git a/pandora/changelog/models.py b/pandora/changelog/models.py index a40057a8..112b7351 100644 --- a/pandora/changelog/models.py +++ b/pandora/changelog/models.py @@ -6,6 +6,8 @@ from datetime import datetime from django.contrib.auth.models import User from django.db import models +from django.utils.encoding import python_2_unicode_compatible + from oxdjango import fields import ox @@ -16,12 +18,13 @@ from . import managers ''' FIXME: remove this table more migrate to new ChangeLog ''' +@python_2_unicode_compatible class Changelog(models.Model): created = models.DateTimeField(auto_now_add=True) type = models.CharField(max_length=255, db_index=True) value = fields.DictField(default={}) - def __unicode__(self): + def __str__(self): return u'%s %s' % (self.type, self.created) def json(self): @@ -46,6 +49,7 @@ def add_changelog(request, data, id=None): 'user': c.user.username, }) +@python_2_unicode_compatible class Log(models.Model): action = models.CharField(max_length=255, db_index=True) @@ -56,7 +60,7 @@ class Log(models.Model): objects = managers.LogManager() - def __unicode__(self): + def __str__(self): return u'%s %s %s' % (self.created, self.action, self.changeid) def get_id(self): diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 54e27be8..99c0415c 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -4,6 +4,7 @@ from __future__ import division, print_function, absolute_import from django.db import models from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible import ox @@ -45,6 +46,7 @@ def get_layers(item, interval=None, user=None): return layers +@python_2_unicode_compatible class MetaClip(object): def update_calculated_values(self): start = self.start @@ -182,7 +184,7 @@ class MetaClip(object): def public_id(self): return u"%s/%0.03f-%0.03f" % (self.item.public_id, float(self.start), float(self.end)) - def __unicode__(self): + def __str__(self): return self.public_id class Meta: @@ -218,7 +220,7 @@ attrs = { for name in [k['id'] for k in settings.CONFIG['layers']]: attrs[name] = models.BooleanField(default=False, db_index=True) -Clip = type('Clip', (MetaClip,models.Model), attrs) +Clip = type('Clip', (MetaClip, models.Model), attrs) class ClipRandom(models.Model): id = models.BigIntegerField(primary_key=True) diff --git a/pandora/document/models.py b/pandora/document/models.py index 5d0c8f51..61f1f017 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -14,6 +14,7 @@ from django.db.models import Q, Sum, Max from django.contrib.auth.models import User, Group from django.db.models.signals import pre_delete from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible from PIL import Image import ox @@ -36,6 +37,7 @@ if not PY2: def get_path(f, x): return f.path(x) +@python_2_unicode_compatible class Document(models.Model): created = models.DateTimeField(auto_now_add=True) @@ -283,7 +285,7 @@ class Document(models.Model): self.update_matches() self.update_linked_documents() - def __unicode__(self): + def __str__(self): return self.get_id() def add(self, item): @@ -659,6 +661,7 @@ class ItemProperties(models.Model): super(ItemProperties, self).save(*args, **kwargs) +@python_2_unicode_compatible class Access(models.Model): class Meta: unique_together = ("document", "user") @@ -676,11 +679,12 @@ class Access(models.Model): timesaccessed = Access.objects.filter(document=self.document).aggregate(Sum('accessed'))['accessed__sum'] Sort.objects.filter(document=self.document).update(timesaccessed=timesaccessed, accessed=self.access) - def __unicode__(self): + def __str__(self): if self.user: return u"%s/%s/%s" % (self.user, self.document, self.access) return u"%s/%s" % (self.item, self.access) +@python_2_unicode_compatible class Facet(models.Model): ''' used for keys that can have multiple values like people, languages etc. @@ -696,7 +700,7 @@ class Facet(models.Model): value = models.CharField(max_length=1000, db_index=True) sortvalue = models.CharField(max_length=1000, db_index=True) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.key, self.value) def save(self, *args, **kwargs): @@ -716,6 +720,7 @@ for key in settings.CONFIG['itemKeys']: if key.get('sortType') == 'person': Document.person_keys.append(key['id']) +@python_2_unicode_compatible class Find(models.Model): class Meta: @@ -725,7 +730,7 @@ class Find(models.Model): key = models.CharField(max_length=200, db_index=True) value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) - def __unicode__(self): + def __str__(self): return u'%s=%s' % (self.key, self.value) ''' diff --git a/pandora/documentcollection/models.py b/pandora/documentcollection/models.py index dc88f642..5753619f 100644 --- a/pandora/documentcollection/models.py +++ b/pandora/documentcollection/models.py @@ -11,6 +11,8 @@ from django.db import models from django.db.models import Max from django.contrib.auth.models import User from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible + import ox from oxdjango.fields import DictField, TupleField @@ -32,6 +34,7 @@ def get_collectionview(): def get_collectionsort(): return tuple(settings.CONFIG['user']['ui']['collectionSort']) +@python_2_unicode_compatible class Collection(models.Model): class Meta: @@ -107,7 +110,7 @@ class Collection(models.Model): if documents: CollectionDocument.objects.all().filter(document__id__in=documents, collection=self).delete() - def __unicode__(self): + def __str__(self): return self.get_id() def get_id(self): @@ -306,6 +309,7 @@ class Collection(models.Model): path = source return path +@python_2_unicode_compatible class CollectionDocument(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -313,9 +317,10 @@ class CollectionDocument(models.Model): index = models.IntegerField(default=0) document = models.ForeignKey('document.Document') - def __unicode__(self): + def __str__(self): return u'%s in %s' % (self.document, self.collection) +@python_2_unicode_compatible class Position(models.Model): class Meta: @@ -326,6 +331,6 @@ class Position(models.Model): section = models.CharField(max_length=255) position = models.IntegerField(default=0) - def __unicode__(self): + def __str__(self): return u'%s/%s/%s' % (self.section, self.position, self.collection) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index a0483270..f846d436 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -16,6 +16,7 @@ from django.conf import settings from django.db import models, transaction from django.db.models import Max from django.contrib.auth.models import User +from django.utils.encoding import python_2_unicode_compatible from annotation.models import Annotation from item.models import Item @@ -29,6 +30,7 @@ from . import managers def get_path(f, x): return f.path(x) def get_icon_path(f, x): return get_path(f, 'icon.jpg') +@python_2_unicode_compatible class Edit(models.Model): class Meta: @@ -54,7 +56,7 @@ class Edit(models.Model): poster_frames = TupleField(default=[], editable=False) subscribed_users = models.ManyToManyField(User, related_name='subscribed_edits') - def __unicode__(self): + def __str__(self): return u'%s (%s)' % (self.name, self.user) @classmethod @@ -413,6 +415,7 @@ class Edit(models.Model): #p.wait() shutil.rmtree(tmp) +@python_2_unicode_compatible class Clip(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -433,7 +436,7 @@ class Clip(models.Model): objects = managers.ClipManager() - def __unicode__(self): + def __str__(self): if self.annotation: return u'%s' % self.annotation.public_id return u'%s/%0.3f-%0.3f' % (self.item.public_id, self.start, self.end) @@ -521,6 +524,7 @@ class Clip(models.Model): return clip.models.get_layers(item=item, interval=(start, end), user=user) +@python_2_unicode_compatible class Position(models.Model): class Meta: @@ -531,6 +535,6 @@ class Position(models.Model): section = models.CharField(max_length=255) position = models.IntegerField(default=0) - def __unicode__(self): + def __str__(self): return u'%s/%s/%s' % (self.section, self.position, self.edit) diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 646237e1..2f70dea6 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -14,6 +14,7 @@ from django.db.models import Max from django.contrib.auth.models import User from django.db.models.signals import pre_delete, post_init from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango import fields @@ -25,6 +26,7 @@ from document.models import Document from . import managers +@python_2_unicode_compatible class Entity(models.Model): class Meta: @@ -64,7 +66,7 @@ class Entity(models.Model): self.update_annotations() self.update_find() - def __unicode__(self): + def __str__(self): return self.get_id() @classmethod @@ -253,6 +255,7 @@ post_init.connect( ) +@python_2_unicode_compatible class DocumentProperties(models.Model): class Meta: @@ -266,13 +269,14 @@ class DocumentProperties(models.Model): index = models.IntegerField(default=0) data = fields.DictField(default={}) - def __unicode__(self): + def __str__(self): return u"%r-%r" % (self.document, self.entity) def save(self, *args, **kwargs): super(DocumentProperties, self).save(*args, **kwargs) +@python_2_unicode_compatible class Find(models.Model): class Meta: @@ -282,5 +286,5 @@ class Find(models.Model): key = models.CharField(max_length=200, db_index=True) value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.key, self.value) diff --git a/pandora/event/models.py b/pandora/event/models.py index 7fb74244..0fbb7aac 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -4,6 +4,8 @@ from __future__ import division, print_function, absolute_import from django.db import models, transaction from django.contrib.auth.models import User +from django.utils.encoding import python_2_unicode_compatible + import ox from oxdjango import fields @@ -16,6 +18,7 @@ from title.models import get_title_sort from . import managers +@python_2_unicode_compatible class Event(models.Model): ''' Events are events in time that can be once or recurring, @@ -57,7 +60,7 @@ class Event(models.Model): items = models.ManyToManyField(Item, blank=True, related_name='events') annotations = models.ManyToManyField(Annotation, blank=True, related_name='events') - def __unicode__(self): + def __str__(self): return self.name @classmethod diff --git a/pandora/home/models.py b/pandora/home/models.py index 99ef744d..9d7033ee 100644 --- a/pandora/home/models.py +++ b/pandora/home/models.py @@ -8,6 +8,8 @@ from six.moves.urllib.parse import quote from django.db import models from django.db.models import Max from django.db.models.signals import pre_delete +from django.utils.encoding import python_2_unicode_compatible + import ox from oxdjango import fields @@ -16,6 +18,7 @@ from edit.models import Edit from documentcollection.models import Collection +@python_2_unicode_compatible class Item(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -150,7 +153,7 @@ class Item(models.Model): del j[key] return j - def __unicode__(self): + def __str__(self): return u"%s" % (self.get_id()) def delete_item(type, contentid): diff --git a/pandora/item/models.py b/pandora/item/models.py index f4f89747..49ad5957 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -21,6 +21,7 @@ from django.conf import settings from django.contrib.auth.models import User, Group from django.db.models.signals import pre_delete from django.utils import datetime_safe +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango import fields @@ -158,6 +159,7 @@ def get_poster_path(f, x): def get_torrent_path(f, x): return get_path(f, 'torrent.torrent') +@python_2_unicode_compatible class Item(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -337,7 +339,7 @@ class Item(models.Model): del c[t] return c - def __unicode__(self): + def __str__(self): year = self.get('year') if year: string = u'%s (%s)' % (ox.decode_html(self.get('title', 'Untitled')), self.get('year')) @@ -1708,6 +1710,7 @@ for key in settings.CONFIG['itemKeys']: if key.get('sortType') == 'person': Item.person_keys.append(key['id']) +@python_2_unicode_compatible class ItemFind(models.Model): """ used to find items, @@ -1722,7 +1725,7 @@ class ItemFind(models.Model): key = models.CharField(max_length=200, db_index=True) value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.key, self.value) ''' ItemSort @@ -1749,6 +1752,7 @@ for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer' ItemSort = type('ItemSort', (models.Model,), attrs) ItemSort.fields = [f.name for f in ItemSort._meta.fields] +@python_2_unicode_compatible class Access(models.Model): class Meta: unique_together = ("item", "user") @@ -1766,11 +1770,12 @@ class Access(models.Model): timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum'] ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed, accessed=self.access) - def __unicode__(self): + def __str__(self): if self.user: return u"%s/%s/%s" % (self.user, self.item, self.access) return u"%s/%s" % (self.item, self.access) +@python_2_unicode_compatible class Facet(models.Model): ''' used for keys that can have multiple values like people, languages etc. @@ -1786,7 +1791,7 @@ class Facet(models.Model): value = models.CharField(max_length=1000, db_index=True) sortvalue = models.CharField(max_length=1000, db_index=True) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.key, self.value) def save(self, *args, **kwargs): diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index 00e54087..d6f2e427 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -11,6 +11,7 @@ from django.db import models from django.db.models import Max from django.contrib.auth.models import User from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango.fields import DictField, TupleField @@ -25,6 +26,7 @@ def get_icon_path(f, x): return get_path(f, 'icon.jpg') def get_listview(): return settings.CONFIG['user']['ui']['listView'] def get_listsort(): return tuple(settings.CONFIG['user']['ui']['listSort']) +@python_2_unicode_compatible class List(models.Model): class Meta: @@ -101,7 +103,7 @@ class List(models.Model): if items: ListItem.objects.all().filter(item__public_id__in=items, list=self).delete() - def __unicode__(self): + def __str__(self): return self.get_id() def get_id(self): @@ -287,6 +289,7 @@ class List(models.Model): path = source return path +@python_2_unicode_compatible class ListItem(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -294,10 +297,11 @@ class ListItem(models.Model): index = models.IntegerField(default=0) item = models.ForeignKey('item.Item') - def __unicode__(self): + def __str__(self): return u'%s in %s' % (self.item, self.list) +@python_2_unicode_compatible class Position(models.Model): class Meta: @@ -308,6 +312,6 @@ class Position(models.Model): section = models.CharField(max_length=255) position = models.IntegerField(default=0) - def __unicode__(self): + def __str__(self): return u'%s/%s/%s' % (self.section, self.position, self.list) diff --git a/pandora/log/models.py b/pandora/log/models.py index 8c1c3ee4..a67700de 100644 --- a/pandora/log/models.py +++ b/pandora/log/models.py @@ -4,10 +4,12 @@ from __future__ import division, print_function, absolute_import from django.db import models from django.contrib.auth.models import User +from django.utils.encoding import python_2_unicode_compatible import ox from . import managers +@python_2_unicode_compatible class Log(models.Model): created = models.DateTimeField(auto_now_add=True, db_index=True) modified = models.DateTimeField(auto_now=True) @@ -18,7 +20,7 @@ class Log(models.Model): objects = managers.LogManager() - def __unicode__(self): + def __str__(self): return u"%s" % self.id def json(self, keys=None): diff --git a/pandora/news/models.py b/pandora/news/models.py index 79277c5f..0f10e8e8 100644 --- a/pandora/news/models.py +++ b/pandora/news/models.py @@ -3,11 +3,13 @@ from __future__ import division, print_function, absolute_import from django.db import models +from django.utils.encoding import python_2_unicode_compatible import ox from . import managers +@python_2_unicode_compatible class News(models.Model): objects = managers.NewsManager() @@ -40,6 +42,6 @@ class News(models.Model): del j[key] return j - def __unicode__(self): - return u"%s/%s" %(self.date, self.title) + def __str__(self): + return u"%s/%s" % (self.date, self.title) diff --git a/pandora/person/models.py b/pandora/person/models.py index ecb00b70..18f86584 100644 --- a/pandora/person/models.py +++ b/pandora/person/models.py @@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import import unicodedata from django.db import models +from django.utils.encoding import python_2_unicode_compatible from oxdjango import fields import ox @@ -27,6 +28,7 @@ def get_name_sort(name, sortname=None): sortname = u'' return sortname +@python_2_unicode_compatible class Person(models.Model): name = models.CharField(max_length=200, unique=True) sortname = models.CharField(max_length=200) @@ -42,7 +44,7 @@ class Person(models.Model): objects = managers.PersonManager() - def __unicode__(self): + def __str__(self): return self.name def save(self, *args, **kwargs): diff --git a/pandora/place/models.py b/pandora/place/models.py index 9eb66fc5..4b0eba28 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -4,6 +4,7 @@ from __future__ import division, print_function, absolute_import from django.db import models, transaction from django.contrib.auth.models import User +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango import fields @@ -13,6 +14,7 @@ from item.models import Item from . import managers +@python_2_unicode_compatible class Place(models.Model): ''' Places are named locations, they should have geographical information attached to them. @@ -52,7 +54,7 @@ class Place(models.Model): class Meta: ordering = ('name_sort', ) - def __unicode__(self): + def __str__(self): return self.name @classmethod diff --git a/pandora/sequence/models.py b/pandora/sequence/models.py index e7460d9e..a3e6cb36 100644 --- a/pandora/sequence/models.py +++ b/pandora/sequence/models.py @@ -3,6 +3,7 @@ from __future__ import division, print_function, absolute_import from django.db import models +from django.utils.encoding import python_2_unicode_compatible from item.models import ItemSort @@ -15,6 +16,7 @@ def parse_hash(value): def format_hash(value): return hex(value + 9223372036854775808)[2:-1].upper() +@python_2_unicode_compatible class Sequence(models.Model): class Meta: unique_together = ("sort", "start", "end", "mode") @@ -41,7 +43,7 @@ class Sequence(models.Model): def public_id(self): return u"%s/%0.03f-%0.03f" % (self.sort.item.public_id, float(self.start), float(self.end)) - def __unicode__(self): + def __str__(self): return self.public_id def json(self, keys=None, user=None): diff --git a/pandora/taskqueue/models.py b/pandora/taskqueue/models.py index 03694487..016233b7 100644 --- a/pandora/taskqueue/models.py +++ b/pandora/taskqueue/models.py @@ -11,6 +11,7 @@ from django.contrib.auth.models import User from django.conf import settings from django.db import models from django.db.models import Q +from django.utils.encoding import python_2_unicode_compatible import celery.task.control import kombu.five import ox @@ -40,6 +41,7 @@ def get_tasks(username): tasks.append(task.json()) return tasks +@python_2_unicode_compatible class Task(models.Model): DONE = ['finished', 'failed', 'canceled'] @@ -53,7 +55,7 @@ class Task(models.Model): item = models.ForeignKey("item.Item", related_name='tasks') user = models.ForeignKey(User, related_name='tasks', null=True) - def __unicode__(self): + def __str__(self): return "%s [%s]" % (self.item.public_id, self.status) @property diff --git a/pandora/text/models.py b/pandora/text/models.py index 2c90bb58..e16d4f5d 100644 --- a/pandora/text/models.py +++ b/pandora/text/models.py @@ -13,6 +13,7 @@ from django.db.models import Max from django.contrib.auth.models import User from django.conf import settings from django.db.models.signals import pre_delete +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango.fields import TupleField @@ -25,6 +26,7 @@ from . import managers def get_path(i, x): return i.path(x) def get_icon_path(i, x): return get_path(i, 'icon.jpg') +@python_2_unicode_compatible class Text(models.Model): class Meta: @@ -55,7 +57,7 @@ class Text(models.Model): self.rightslevel = min(self.rightslevel, len(settings.CONFIG['textRightsLevels']) - 1) super(Text, self).save(*args, **kwargs) - def __unicode__(self): + def __str__(self): return self.get_id() @classmethod @@ -302,6 +304,7 @@ def delete_file(sender, **kwargs): t.file.delete(save=False) pre_delete.connect(delete_file, sender=Text) +@python_2_unicode_compatible class Position(models.Model): class Meta: @@ -312,6 +315,6 @@ class Position(models.Model): section = models.CharField(max_length=255) position = models.IntegerField(default=0) - def __unicode__(self): + def __str__(self): return u'%s/%s/%s' % (self.section, self.position, self.text) diff --git a/pandora/title/models.py b/pandora/title/models.py index 077f33d6..53157d7e 100644 --- a/pandora/title/models.py +++ b/pandora/title/models.py @@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import import unicodedata from django.db import models +from django.utils.encoding import python_2_unicode_compatible import ox @@ -25,6 +26,7 @@ def get_title_sort(title): sorttitle = u'' return sorttitle +@python_2_unicode_compatible class Title(models.Model): title = models.CharField(max_length=1000, unique=True) sorttitle = models.CharField(max_length=1000) @@ -35,7 +37,7 @@ class Title(models.Model): objects = managers.TitleManager() - def __unicode__(self): + def __str__(self): return self.title def save(self, *args, **kwargs): diff --git a/pandora/tv/models.py b/pandora/tv/models.py index e31fc315..26599ddd 100644 --- a/pandora/tv/models.py +++ b/pandora/tv/models.py @@ -8,10 +8,12 @@ from random import randint from django.db import models from django.db.models import Max from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible from item.models import Item +@python_2_unicode_compatible class Channel(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -20,7 +22,7 @@ class Channel(models.Model): list = models.OneToOneField('itemlist.List', related_name='channel', null=True, blank=True) #list = models.ForeignKey('itemlist.List', related_name='channel', null=True, unique=True, blank=True) - def __unicode__(self): + def __str__(self): return u"%s %s" % (self.list or 'All', self.run) def update_program(self, now=None): @@ -72,6 +74,7 @@ class Channel(models.Model): else: return program.json(user, now) +@python_2_unicode_compatible class Program(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -81,7 +84,7 @@ class Program(models.Model): item = models.ForeignKey('item.Item', related_name='program') channel = models.ForeignKey(Channel, related_name='program') - def __unicode__(self): + def __str__(self): return u"%s %s" % (self.item, self.start) def json(self, user, current=False): diff --git a/pandora/urlalias/models.py b/pandora/urlalias/models.py index 1e3da09f..c42fa2e1 100644 --- a/pandora/urlalias/models.py +++ b/pandora/urlalias/models.py @@ -1,32 +1,37 @@ from django.db import models +from django.utils.encoding import python_2_unicode_compatible +@python_2_unicode_compatible class IDAlias(models.Model): old = models.CharField(max_length=255, unique=True) new = models.CharField(max_length=255) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.old, self.new) +@python_2_unicode_compatible class LayerAlias(models.Model): old = models.CharField(max_length=255, unique=True) new = models.CharField(max_length=255) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.old, self.new) +@python_2_unicode_compatible class ListAlias(models.Model): old = models.CharField(max_length=255, unique=True) new = models.CharField(max_length=255) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.old, self.new) +@python_2_unicode_compatible class Alias(models.Model): url = models.CharField(max_length=255, unique=True) target = models.CharField(max_length=255) - def __unicode__(self): + def __str__(self): return u"%s=%s" % (self.url, self.target) diff --git a/pandora/user/models.py b/pandora/user/models.py index f86610b0..5ce7000e 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -10,6 +10,7 @@ from django.db import models from django.db.models import Max from django.conf import settings from django.contrib.gis.geoip2 import GeoIP2 +from django.utils.encoding import python_2_unicode_compatible import ox from oxdjango.fields import DictField @@ -24,6 +25,7 @@ from . import managers from . import tasks +@python_2_unicode_compatible class SessionData(models.Model): session_key = models.CharField(max_length=40, primary_key=True) user = models.OneToOneField(User, null=True, blank=True, related_name='data') @@ -51,7 +53,7 @@ class SessionData(models.Model): groupssort = models.CharField(default=None, blank=True, null=True, max_length=255) - def __unicode__(self): + def __str__(self): return u"%s" % self.session_key def parse_useragent(self): @@ -184,6 +186,7 @@ class SessionData(models.Model): del j[key] return j +@python_2_unicode_compatible class UserProfile(models.Model): reset_code = models.CharField(max_length=255, blank=True, null=True, unique=True) user = models.OneToOneField(User, related_name='profile') @@ -196,7 +199,7 @@ class UserProfile(models.Model): notes = models.TextField(default='') - def __unicode__(self): + def __str__(self): return self.user.username def get_ui(self):