use python_2_unicode_compatible

This commit is contained in:
j 2017-03-03 08:56:35 +01:00
parent 72fdc8ed4d
commit f0a4aba751
24 changed files with 130 additions and 53 deletions

View file

@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import
import re import re
import unicodedata import unicodedata
from django.utils.encoding import python_2_unicode_compatible
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Q from django.db.models import Q
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -81,6 +82,7 @@ def get_matches(obj, model, layer_type, qs=None):
matches = [-1] matches = [-1]
return Annotation.objects.filter(id__in=matches) return Annotation.objects.filter(id__in=matches)
@python_2_unicode_compatible
class Annotation(models.Model): class Annotation(models.Model):
objects = managers.AnnotationManager() objects = managers.AnnotationManager()
@ -380,7 +382,7 @@ class Annotation(models.Model):
return j return j
def __unicode__(self): def __str__(self):
return u"%s %s-%s" % (self.public_id, self.start, self.end) return u"%s %s-%s" % (self.public_id, self.start, self.end)
def cleanup_related(sender, **kwargs): def cleanup_related(sender, **kwargs):

View file

@ -5,20 +5,23 @@ from __future__ import division, print_function, absolute_import
import json import json
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from . import monkey_patch from . import monkey_patch
from . import tasks from . import tasks
@python_2_unicode_compatible
class Page(models.Model): class Page(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=1024, unique=True) name = models.CharField(max_length=1024, unique=True)
text = models.TextField(blank=True) text = models.TextField(blank=True)
def __unicode__(self): def __str__(self):
return self.name return self.name
@python_2_unicode_compatible
class Settings(models.Model): class Settings(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
@ -26,7 +29,7 @@ class Settings(models.Model):
key = models.CharField(max_length=1024, unique=True) key = models.CharField(max_length=1024, unique=True)
value = models.TextField(blank=True) value = models.TextField(blank=True)
def __unicode__(self): def __str__(self):
return self.key return self.key
@classmethod @classmethod

View file

@ -13,6 +13,7 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.utils.encoding import python_2_unicode_compatible
from oxdjango import fields from oxdjango import fields
import ox import ox
@ -33,6 +34,7 @@ if not PY2:
def data_path(f, x): def data_path(f, x):
return f.get_path('data.bin') return f.get_path('data.bin')
@python_2_unicode_compatible
class File(models.Model): class File(models.Model):
AV_INFO = ( AV_INFO = (
'duration', 'video', 'audio', 'oshash', 'size', 'duration', 'video', 'audio', 'oshash', 'size',
@ -103,7 +105,7 @@ class File(models.Model):
objects = managers.FileManager() objects = managers.FileManager()
def __unicode__(self): def __str__(self):
return self.path return self.path
def parse_info(self): def parse_info(self):
@ -562,6 +564,7 @@ def delete_file(sender, **kwargs):
f.delete_files() f.delete_files()
pre_delete.connect(delete_file, sender=File) pre_delete.connect(delete_file, sender=File)
@python_2_unicode_compatible
class Volume(models.Model): class Volume(models.Model):
class Meta: class Meta:
@ -573,7 +576,7 @@ class Volume(models.Model):
user = models.ForeignKey(User, related_name='volumes') user = models.ForeignKey(User, related_name='volumes')
name = models.CharField(max_length=1024) name = models.CharField(max_length=1024)
def __unicode__(self): def __str__(self):
return u"%s's %s" % (self.user, self.name) return u"%s's %s" % (self.user, self.name)
def json(self): def json(self):
@ -586,6 +589,7 @@ class Volume(models.Model):
def inttime(): def inttime():
return int(time.time()) return int(time.time())
@python_2_unicode_compatible
class Instance(models.Model): class Instance(models.Model):
class Meta: class Meta:
@ -604,7 +608,7 @@ class Instance(models.Model):
file = models.ForeignKey(File, related_name='instances') file = models.ForeignKey(File, related_name='instances')
volume = models.ForeignKey(Volume, related_name='files') 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) return u"%s's %s <%s>" % (self.volume.user, self.path, self.file.oshash)
@property @property
@ -624,7 +628,7 @@ def frame_path(frame, name):
name = "%s%s" % (frame.position, ext) name = "%s%s" % (frame.position, ext)
return frame.file.get_path(name) return frame.file.get_path(name)
@python_2_unicode_compatible
class Frame(models.Model): class Frame(models.Model):
class Meta: class Meta:
@ -643,7 +647,7 @@ class Frame(models.Model):
self.height = self.frame.height self.height = self.frame.height
super(Frame, self).save(*args, **kwargs) super(Frame, self).save(*args, **kwargs)
def __unicode__(self): def __str__(self):
return u'%s/%s' % (self.file, self.position) return u'%s/%s' % (self.file, self.position)
def delete_frame(sender, **kwargs): def delete_frame(sender, **kwargs):
@ -655,6 +659,7 @@ pre_delete.connect(delete_frame, sender=Frame)
def stream_path(f, x): def stream_path(f, x):
return f.path(x) return f.path(x)
@python_2_unicode_compatible
class Stream(models.Model): class Stream(models.Model):
class Meta: class Meta:
@ -686,7 +691,7 @@ class Stream(models.Model):
def name(self): def name(self):
return u"%sp.%s" % (self.resolution, self.format) return u"%sp.%s" % (self.resolution, self.format)
def __unicode__(self): def __str__(self):
return u"%s/%s" % (self.file, self.name()) return u"%s/%s" % (self.file, self.name())
def get(self, resolution, format): def get(self, resolution, format):

View file

@ -6,6 +6,8 @@ from datetime import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from oxdjango import fields from oxdjango import fields
import ox import ox
@ -16,12 +18,13 @@ from . import managers
''' '''
FIXME: remove this table more migrate to new ChangeLog FIXME: remove this table more migrate to new ChangeLog
''' '''
@python_2_unicode_compatible
class Changelog(models.Model): class Changelog(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
type = models.CharField(max_length=255, db_index=True) type = models.CharField(max_length=255, db_index=True)
value = fields.DictField(default={}) value = fields.DictField(default={})
def __unicode__(self): def __str__(self):
return u'%s %s' % (self.type, self.created) return u'%s %s' % (self.type, self.created)
def json(self): def json(self):
@ -46,6 +49,7 @@ def add_changelog(request, data, id=None):
'user': c.user.username, 'user': c.user.username,
}) })
@python_2_unicode_compatible
class Log(models.Model): class Log(models.Model):
action = models.CharField(max_length=255, db_index=True) action = models.CharField(max_length=255, db_index=True)
@ -56,7 +60,7 @@ class Log(models.Model):
objects = managers.LogManager() objects = managers.LogManager()
def __unicode__(self): def __str__(self):
return u'%s %s %s' % (self.created, self.action, self.changeid) return u'%s %s %s' % (self.created, self.action, self.changeid)
def get_id(self): def get_id(self):

View file

@ -4,6 +4,7 @@ from __future__ import division, print_function, absolute_import
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
@ -45,6 +46,7 @@ def get_layers(item, interval=None, user=None):
return layers return layers
@python_2_unicode_compatible
class MetaClip(object): class MetaClip(object):
def update_calculated_values(self): def update_calculated_values(self):
start = self.start start = self.start
@ -182,7 +184,7 @@ class MetaClip(object):
def public_id(self): def public_id(self):
return u"%s/%0.03f-%0.03f" % (self.item.public_id, float(self.start), float(self.end)) 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 return self.public_id
class Meta: class Meta:
@ -218,7 +220,7 @@ attrs = {
for name in [k['id'] for k in settings.CONFIG['layers']]: for name in [k['id'] for k in settings.CONFIG['layers']]:
attrs[name] = models.BooleanField(default=False, db_index=True) 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): class ClipRandom(models.Model):
id = models.BigIntegerField(primary_key=True) id = models.BigIntegerField(primary_key=True)

View file

@ -14,6 +14,7 @@ from django.db.models import Q, Sum, Max
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from PIL import Image from PIL import Image
import ox import ox
@ -36,6 +37,7 @@ if not PY2:
def get_path(f, x): def get_path(f, x):
return f.path(x) return f.path(x)
@python_2_unicode_compatible
class Document(models.Model): class Document(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
@ -283,7 +285,7 @@ class Document(models.Model):
self.update_matches() self.update_matches()
self.update_linked_documents() self.update_linked_documents()
def __unicode__(self): def __str__(self):
return self.get_id() return self.get_id()
def add(self, item): def add(self, item):
@ -659,6 +661,7 @@ class ItemProperties(models.Model):
super(ItemProperties, self).save(*args, **kwargs) super(ItemProperties, self).save(*args, **kwargs)
@python_2_unicode_compatible
class Access(models.Model): class Access(models.Model):
class Meta: class Meta:
unique_together = ("document", "user") unique_together = ("document", "user")
@ -676,11 +679,12 @@ class Access(models.Model):
timesaccessed = Access.objects.filter(document=self.document).aggregate(Sum('accessed'))['accessed__sum'] timesaccessed = Access.objects.filter(document=self.document).aggregate(Sum('accessed'))['accessed__sum']
Sort.objects.filter(document=self.document).update(timesaccessed=timesaccessed, accessed=self.access) Sort.objects.filter(document=self.document).update(timesaccessed=timesaccessed, accessed=self.access)
def __unicode__(self): def __str__(self):
if self.user: if self.user:
return u"%s/%s/%s" % (self.user, self.document, self.access) return u"%s/%s/%s" % (self.user, self.document, self.access)
return u"%s/%s" % (self.item, self.access) return u"%s/%s" % (self.item, self.access)
@python_2_unicode_compatible
class Facet(models.Model): class Facet(models.Model):
''' '''
used for keys that can have multiple values like people, languages etc. 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) value = models.CharField(max_length=1000, db_index=True)
sortvalue = 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) return u"%s=%s" % (self.key, self.value)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
@ -716,6 +720,7 @@ for key in settings.CONFIG['itemKeys']:
if key.get('sortType') == 'person': if key.get('sortType') == 'person':
Document.person_keys.append(key['id']) Document.person_keys.append(key['id'])
@python_2_unicode_compatible
class Find(models.Model): class Find(models.Model):
class Meta: class Meta:
@ -725,7 +730,7 @@ class Find(models.Model):
key = models.CharField(max_length=200, db_index=True) key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) 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) return u'%s=%s' % (self.key, self.value)
''' '''

View file

@ -11,6 +11,8 @@ from django.db import models
from django.db.models import Max from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango.fields import DictField, TupleField from oxdjango.fields import DictField, TupleField
@ -32,6 +34,7 @@ def get_collectionview():
def get_collectionsort(): def get_collectionsort():
return tuple(settings.CONFIG['user']['ui']['collectionSort']) return tuple(settings.CONFIG['user']['ui']['collectionSort'])
@python_2_unicode_compatible
class Collection(models.Model): class Collection(models.Model):
class Meta: class Meta:
@ -107,7 +110,7 @@ class Collection(models.Model):
if documents: if documents:
CollectionDocument.objects.all().filter(document__id__in=documents, collection=self).delete() CollectionDocument.objects.all().filter(document__id__in=documents, collection=self).delete()
def __unicode__(self): def __str__(self):
return self.get_id() return self.get_id()
def get_id(self): def get_id(self):
@ -306,6 +309,7 @@ class Collection(models.Model):
path = source path = source
return path return path
@python_2_unicode_compatible
class CollectionDocument(models.Model): class CollectionDocument(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -313,9 +317,10 @@ class CollectionDocument(models.Model):
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
document = models.ForeignKey('document.Document') document = models.ForeignKey('document.Document')
def __unicode__(self): def __str__(self):
return u'%s in %s' % (self.document, self.collection) return u'%s in %s' % (self.document, self.collection)
@python_2_unicode_compatible
class Position(models.Model): class Position(models.Model):
class Meta: class Meta:
@ -326,6 +331,6 @@ class Position(models.Model):
section = models.CharField(max_length=255) section = models.CharField(max_length=255)
position = models.IntegerField(default=0) position = models.IntegerField(default=0)
def __unicode__(self): def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.collection) return u'%s/%s/%s' % (self.section, self.position, self.collection)

View file

@ -16,6 +16,7 @@ from django.conf import settings
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.encoding import python_2_unicode_compatible
from annotation.models import Annotation from annotation.models import Annotation
from item.models import Item from item.models import Item
@ -29,6 +30,7 @@ from . import managers
def get_path(f, x): return f.path(x) def get_path(f, x): return f.path(x)
def get_icon_path(f, x): return get_path(f, 'icon.jpg') def get_icon_path(f, x): return get_path(f, 'icon.jpg')
@python_2_unicode_compatible
class Edit(models.Model): class Edit(models.Model):
class Meta: class Meta:
@ -54,7 +56,7 @@ class Edit(models.Model):
poster_frames = TupleField(default=[], editable=False) poster_frames = TupleField(default=[], editable=False)
subscribed_users = models.ManyToManyField(User, related_name='subscribed_edits') subscribed_users = models.ManyToManyField(User, related_name='subscribed_edits')
def __unicode__(self): def __str__(self):
return u'%s (%s)' % (self.name, self.user) return u'%s (%s)' % (self.name, self.user)
@classmethod @classmethod
@ -413,6 +415,7 @@ class Edit(models.Model):
#p.wait() #p.wait()
shutil.rmtree(tmp) shutil.rmtree(tmp)
@python_2_unicode_compatible
class Clip(models.Model): class Clip(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -433,7 +436,7 @@ class Clip(models.Model):
objects = managers.ClipManager() objects = managers.ClipManager()
def __unicode__(self): def __str__(self):
if self.annotation: if self.annotation:
return u'%s' % self.annotation.public_id return u'%s' % self.annotation.public_id
return u'%s/%0.3f-%0.3f' % (self.item.public_id, self.start, self.end) 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) return clip.models.get_layers(item=item, interval=(start, end), user=user)
@python_2_unicode_compatible
class Position(models.Model): class Position(models.Model):
class Meta: class Meta:
@ -531,6 +535,6 @@ class Position(models.Model):
section = models.CharField(max_length=255) section = models.CharField(max_length=255)
position = models.IntegerField(default=0) position = models.IntegerField(default=0)
def __unicode__(self): def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.edit) return u'%s/%s/%s' % (self.section, self.position, self.edit)

View file

@ -14,6 +14,7 @@ from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db.models.signals import pre_delete, post_init from django.db.models.signals import pre_delete, post_init
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango import fields from oxdjango import fields
@ -25,6 +26,7 @@ from document.models import Document
from . import managers from . import managers
@python_2_unicode_compatible
class Entity(models.Model): class Entity(models.Model):
class Meta: class Meta:
@ -64,7 +66,7 @@ class Entity(models.Model):
self.update_annotations() self.update_annotations()
self.update_find() self.update_find()
def __unicode__(self): def __str__(self):
return self.get_id() return self.get_id()
@classmethod @classmethod
@ -253,6 +255,7 @@ post_init.connect(
) )
@python_2_unicode_compatible
class DocumentProperties(models.Model): class DocumentProperties(models.Model):
class Meta: class Meta:
@ -266,13 +269,14 @@ class DocumentProperties(models.Model):
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
data = fields.DictField(default={}) data = fields.DictField(default={})
def __unicode__(self): def __str__(self):
return u"%r-%r" % (self.document, self.entity) return u"%r-%r" % (self.document, self.entity)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(DocumentProperties, self).save(*args, **kwargs) super(DocumentProperties, self).save(*args, **kwargs)
@python_2_unicode_compatible
class Find(models.Model): class Find(models.Model):
class Meta: class Meta:
@ -282,5 +286,5 @@ class Find(models.Model):
key = models.CharField(max_length=200, db_index=True) key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) 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) return u"%s=%s" % (self.key, self.value)

View file

@ -4,6 +4,8 @@ from __future__ import division, print_function, absolute_import
from django.db import models, transaction from django.db import models, transaction
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango import fields from oxdjango import fields
@ -16,6 +18,7 @@ from title.models import get_title_sort
from . import managers from . import managers
@python_2_unicode_compatible
class Event(models.Model): class Event(models.Model):
''' '''
Events are events in time that can be once or recurring, 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') items = models.ManyToManyField(Item, blank=True, related_name='events')
annotations = models.ManyToManyField(Annotation, blank=True, related_name='events') annotations = models.ManyToManyField(Annotation, blank=True, related_name='events')
def __unicode__(self): def __str__(self):
return self.name return self.name
@classmethod @classmethod

View file

@ -8,6 +8,8 @@ from six.moves.urllib.parse import quote
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango import fields from oxdjango import fields
@ -16,6 +18,7 @@ from edit.models import Edit
from documentcollection.models import Collection from documentcollection.models import Collection
@python_2_unicode_compatible
class Item(models.Model): class Item(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -150,7 +153,7 @@ class Item(models.Model):
del j[key] del j[key]
return j return j
def __unicode__(self): def __str__(self):
return u"%s" % (self.get_id()) return u"%s" % (self.get_id())
def delete_item(type, contentid): def delete_item(type, contentid):

View file

@ -21,6 +21,7 @@ from django.conf import settings
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.utils import datetime_safe from django.utils import datetime_safe
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango import fields from oxdjango import fields
@ -158,6 +159,7 @@ def get_poster_path(f, x):
def get_torrent_path(f, x): def get_torrent_path(f, x):
return get_path(f, 'torrent.torrent') return get_path(f, 'torrent.torrent')
@python_2_unicode_compatible
class Item(models.Model): class Item(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -337,7 +339,7 @@ class Item(models.Model):
del c[t] del c[t]
return c return c
def __unicode__(self): def __str__(self):
year = self.get('year') year = self.get('year')
if year: if year:
string = u'%s (%s)' % (ox.decode_html(self.get('title', 'Untitled')), self.get('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': if key.get('sortType') == 'person':
Item.person_keys.append(key['id']) Item.person_keys.append(key['id'])
@python_2_unicode_compatible
class ItemFind(models.Model): class ItemFind(models.Model):
""" """
used to find items, used to find items,
@ -1722,7 +1725,7 @@ class ItemFind(models.Model):
key = models.CharField(max_length=200, db_index=True) key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM) 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) return u"%s=%s" % (self.key, self.value)
''' '''
ItemSort 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 = type('ItemSort', (models.Model,), attrs)
ItemSort.fields = [f.name for f in ItemSort._meta.fields] ItemSort.fields = [f.name for f in ItemSort._meta.fields]
@python_2_unicode_compatible
class Access(models.Model): class Access(models.Model):
class Meta: class Meta:
unique_together = ("item", "user") unique_together = ("item", "user")
@ -1766,11 +1770,12 @@ class Access(models.Model):
timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum'] timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum']
ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed, accessed=self.access) ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed, accessed=self.access)
def __unicode__(self): def __str__(self):
if self.user: if self.user:
return u"%s/%s/%s" % (self.user, self.item, self.access) return u"%s/%s/%s" % (self.user, self.item, self.access)
return u"%s/%s" % (self.item, self.access) return u"%s/%s" % (self.item, self.access)
@python_2_unicode_compatible
class Facet(models.Model): class Facet(models.Model):
''' '''
used for keys that can have multiple values like people, languages etc. 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) value = models.CharField(max_length=1000, db_index=True)
sortvalue = 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) return u"%s=%s" % (self.key, self.value)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -11,6 +11,7 @@ from django.db import models
from django.db.models import Max from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango.fields import DictField, TupleField 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_listview(): return settings.CONFIG['user']['ui']['listView']
def get_listsort(): return tuple(settings.CONFIG['user']['ui']['listSort']) def get_listsort(): return tuple(settings.CONFIG['user']['ui']['listSort'])
@python_2_unicode_compatible
class List(models.Model): class List(models.Model):
class Meta: class Meta:
@ -101,7 +103,7 @@ class List(models.Model):
if items: if items:
ListItem.objects.all().filter(item__public_id__in=items, list=self).delete() ListItem.objects.all().filter(item__public_id__in=items, list=self).delete()
def __unicode__(self): def __str__(self):
return self.get_id() return self.get_id()
def get_id(self): def get_id(self):
@ -287,6 +289,7 @@ class List(models.Model):
path = source path = source
return path return path
@python_2_unicode_compatible
class ListItem(models.Model): class ListItem(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -294,10 +297,11 @@ class ListItem(models.Model):
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
item = models.ForeignKey('item.Item') item = models.ForeignKey('item.Item')
def __unicode__(self): def __str__(self):
return u'%s in %s' % (self.item, self.list) return u'%s in %s' % (self.item, self.list)
@python_2_unicode_compatible
class Position(models.Model): class Position(models.Model):
class Meta: class Meta:
@ -308,6 +312,6 @@ class Position(models.Model):
section = models.CharField(max_length=255) section = models.CharField(max_length=255)
position = models.IntegerField(default=0) position = models.IntegerField(default=0)
def __unicode__(self): def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.list) return u'%s/%s/%s' % (self.section, self.position, self.list)

View file

@ -4,10 +4,12 @@ from __future__ import division, print_function, absolute_import
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from . import managers from . import managers
@python_2_unicode_compatible
class Log(models.Model): class Log(models.Model):
created = models.DateTimeField(auto_now_add=True, db_index=True) created = models.DateTimeField(auto_now_add=True, db_index=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -18,7 +20,7 @@ class Log(models.Model):
objects = managers.LogManager() objects = managers.LogManager()
def __unicode__(self): def __str__(self):
return u"%s" % self.id return u"%s" % self.id
def json(self, keys=None): def json(self, keys=None):

View file

@ -3,11 +3,13 @@
from __future__ import division, print_function, absolute_import from __future__ import division, print_function, absolute_import
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from . import managers from . import managers
@python_2_unicode_compatible
class News(models.Model): class News(models.Model):
objects = managers.NewsManager() objects = managers.NewsManager()
@ -40,6 +42,6 @@ class News(models.Model):
del j[key] del j[key]
return j return j
def __unicode__(self): def __str__(self):
return u"%s/%s" %(self.date, self.title) return u"%s/%s" % (self.date, self.title)

View file

@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import
import unicodedata import unicodedata
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from oxdjango import fields from oxdjango import fields
import ox import ox
@ -27,6 +28,7 @@ def get_name_sort(name, sortname=None):
sortname = u'' sortname = u''
return sortname return sortname
@python_2_unicode_compatible
class Person(models.Model): class Person(models.Model):
name = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200, unique=True)
sortname = models.CharField(max_length=200) sortname = models.CharField(max_length=200)
@ -42,7 +44,7 @@ class Person(models.Model):
objects = managers.PersonManager() objects = managers.PersonManager()
def __unicode__(self): def __str__(self):
return self.name return self.name
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -4,6 +4,7 @@ from __future__ import division, print_function, absolute_import
from django.db import models, transaction from django.db import models, transaction
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango import fields from oxdjango import fields
@ -13,6 +14,7 @@ from item.models import Item
from . import managers from . import managers
@python_2_unicode_compatible
class Place(models.Model): class Place(models.Model):
''' '''
Places are named locations, they should have geographical information attached to them. Places are named locations, they should have geographical information attached to them.
@ -52,7 +54,7 @@ class Place(models.Model):
class Meta: class Meta:
ordering = ('name_sort', ) ordering = ('name_sort', )
def __unicode__(self): def __str__(self):
return self.name return self.name
@classmethod @classmethod

View file

@ -3,6 +3,7 @@
from __future__ import division, print_function, absolute_import from __future__ import division, print_function, absolute_import
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from item.models import ItemSort from item.models import ItemSort
@ -15,6 +16,7 @@ def parse_hash(value):
def format_hash(value): def format_hash(value):
return hex(value + 9223372036854775808)[2:-1].upper() return hex(value + 9223372036854775808)[2:-1].upper()
@python_2_unicode_compatible
class Sequence(models.Model): class Sequence(models.Model):
class Meta: class Meta:
unique_together = ("sort", "start", "end", "mode") unique_together = ("sort", "start", "end", "mode")
@ -41,7 +43,7 @@ class Sequence(models.Model):
def public_id(self): def public_id(self):
return u"%s/%0.03f-%0.03f" % (self.sort.item.public_id, float(self.start), float(self.end)) 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 return self.public_id
def json(self, keys=None, user=None): def json(self, keys=None, user=None):

View file

@ -11,6 +11,7 @@ from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.utils.encoding import python_2_unicode_compatible
import celery.task.control import celery.task.control
import kombu.five import kombu.five
import ox import ox
@ -40,6 +41,7 @@ def get_tasks(username):
tasks.append(task.json()) tasks.append(task.json())
return tasks return tasks
@python_2_unicode_compatible
class Task(models.Model): class Task(models.Model):
DONE = ['finished', 'failed', 'canceled'] DONE = ['finished', 'failed', 'canceled']
@ -53,7 +55,7 @@ class Task(models.Model):
item = models.ForeignKey("item.Item", related_name='tasks') item = models.ForeignKey("item.Item", related_name='tasks')
user = models.ForeignKey(User, related_name='tasks', null=True) user = models.ForeignKey(User, related_name='tasks', null=True)
def __unicode__(self): def __str__(self):
return "%s [%s]" % (self.item.public_id, self.status) return "%s [%s]" % (self.item.public_id, self.status)
@property @property

View file

@ -13,6 +13,7 @@ from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango.fields import TupleField from oxdjango.fields import TupleField
@ -25,6 +26,7 @@ from . import managers
def get_path(i, x): return i.path(x) def get_path(i, x): return i.path(x)
def get_icon_path(i, x): return get_path(i, 'icon.jpg') def get_icon_path(i, x): return get_path(i, 'icon.jpg')
@python_2_unicode_compatible
class Text(models.Model): class Text(models.Model):
class Meta: class Meta:
@ -55,7 +57,7 @@ class Text(models.Model):
self.rightslevel = min(self.rightslevel, len(settings.CONFIG['textRightsLevels']) - 1) self.rightslevel = min(self.rightslevel, len(settings.CONFIG['textRightsLevels']) - 1)
super(Text, self).save(*args, **kwargs) super(Text, self).save(*args, **kwargs)
def __unicode__(self): def __str__(self):
return self.get_id() return self.get_id()
@classmethod @classmethod
@ -302,6 +304,7 @@ def delete_file(sender, **kwargs):
t.file.delete(save=False) t.file.delete(save=False)
pre_delete.connect(delete_file, sender=Text) pre_delete.connect(delete_file, sender=Text)
@python_2_unicode_compatible
class Position(models.Model): class Position(models.Model):
class Meta: class Meta:
@ -312,6 +315,6 @@ class Position(models.Model):
section = models.CharField(max_length=255) section = models.CharField(max_length=255)
position = models.IntegerField(default=0) position = models.IntegerField(default=0)
def __unicode__(self): def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.text) return u'%s/%s/%s' % (self.section, self.position, self.text)

View file

@ -5,6 +5,7 @@ from __future__ import division, print_function, absolute_import
import unicodedata import unicodedata
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
@ -25,6 +26,7 @@ def get_title_sort(title):
sorttitle = u'' sorttitle = u''
return sorttitle return sorttitle
@python_2_unicode_compatible
class Title(models.Model): class Title(models.Model):
title = models.CharField(max_length=1000, unique=True) title = models.CharField(max_length=1000, unique=True)
sorttitle = models.CharField(max_length=1000) sorttitle = models.CharField(max_length=1000)
@ -35,7 +37,7 @@ class Title(models.Model):
objects = managers.TitleManager() objects = managers.TitleManager()
def __unicode__(self): def __str__(self):
return self.title return self.title
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -8,10 +8,12 @@ from random import randint
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
from django.conf import settings from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from item.models import Item from item.models import Item
@python_2_unicode_compatible
class Channel(models.Model): class Channel(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=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.OneToOneField('itemlist.List', related_name='channel', null=True, blank=True)
#list = models.ForeignKey('itemlist.List', related_name='channel', null=True, unique=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) return u"%s %s" % (self.list or 'All', self.run)
def update_program(self, now=None): def update_program(self, now=None):
@ -72,6 +74,7 @@ class Channel(models.Model):
else: else:
return program.json(user, now) return program.json(user, now)
@python_2_unicode_compatible
class Program(models.Model): class Program(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -81,7 +84,7 @@ class Program(models.Model):
item = models.ForeignKey('item.Item', related_name='program') item = models.ForeignKey('item.Item', related_name='program')
channel = models.ForeignKey(Channel, related_name='program') channel = models.ForeignKey(Channel, related_name='program')
def __unicode__(self): def __str__(self):
return u"%s %s" % (self.item, self.start) return u"%s %s" % (self.item, self.start)
def json(self, user, current=False): def json(self, user, current=False):

View file

@ -1,32 +1,37 @@
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class IDAlias(models.Model): class IDAlias(models.Model):
old = models.CharField(max_length=255, unique=True) old = models.CharField(max_length=255, unique=True)
new = models.CharField(max_length=255) new = models.CharField(max_length=255)
def __unicode__(self): def __str__(self):
return u"%s=%s" % (self.old, self.new) return u"%s=%s" % (self.old, self.new)
@python_2_unicode_compatible
class LayerAlias(models.Model): class LayerAlias(models.Model):
old = models.CharField(max_length=255, unique=True) old = models.CharField(max_length=255, unique=True)
new = models.CharField(max_length=255) new = models.CharField(max_length=255)
def __unicode__(self): def __str__(self):
return u"%s=%s" % (self.old, self.new) return u"%s=%s" % (self.old, self.new)
@python_2_unicode_compatible
class ListAlias(models.Model): class ListAlias(models.Model):
old = models.CharField(max_length=255, unique=True) old = models.CharField(max_length=255, unique=True)
new = models.CharField(max_length=255) new = models.CharField(max_length=255)
def __unicode__(self): def __str__(self):
return u"%s=%s" % (self.old, self.new) return u"%s=%s" % (self.old, self.new)
@python_2_unicode_compatible
class Alias(models.Model): class Alias(models.Model):
url = models.CharField(max_length=255, unique=True) url = models.CharField(max_length=255, unique=True)
target = models.CharField(max_length=255) target = models.CharField(max_length=255)
def __unicode__(self): def __str__(self):
return u"%s=%s" % (self.url, self.target) return u"%s=%s" % (self.url, self.target)

View file

@ -10,6 +10,7 @@ from django.db import models
from django.db.models import Max from django.db.models import Max
from django.conf import settings from django.conf import settings
from django.contrib.gis.geoip2 import GeoIP2 from django.contrib.gis.geoip2 import GeoIP2
from django.utils.encoding import python_2_unicode_compatible
import ox import ox
from oxdjango.fields import DictField from oxdjango.fields import DictField
@ -24,6 +25,7 @@ from . import managers
from . import tasks from . import tasks
@python_2_unicode_compatible
class SessionData(models.Model): class SessionData(models.Model):
session_key = models.CharField(max_length=40, primary_key=True) session_key = models.CharField(max_length=40, primary_key=True)
user = models.OneToOneField(User, null=True, blank=True, related_name='data') 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) groupssort = models.CharField(default=None, blank=True, null=True, max_length=255)
def __unicode__(self): def __str__(self):
return u"%s" % self.session_key return u"%s" % self.session_key
def parse_useragent(self): def parse_useragent(self):
@ -184,6 +186,7 @@ class SessionData(models.Model):
del j[key] del j[key]
return j return j
@python_2_unicode_compatible
class UserProfile(models.Model): class UserProfile(models.Model):
reset_code = models.CharField(max_length=255, blank=True, null=True, unique=True) reset_code = models.CharField(max_length=255, blank=True, null=True, unique=True)
user = models.OneToOneField(User, related_name='profile') user = models.OneToOneField(User, related_name='profile')
@ -196,7 +199,7 @@ class UserProfile(models.Model):
notes = models.TextField(default='') notes = models.TextField(default='')
def __unicode__(self): def __str__(self):
return self.user.username return self.user.username
def get_ui(self): def get_ui(self):