drop python2 support, upgrade to django 3

This commit is contained in:
j 2020-05-29 00:20:18 +02:00
parent 80390a1f9b
commit 844382b1e8
124 changed files with 413 additions and 563 deletions

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.conf import settings
from django.contrib.auth import get_user_model

View file

@ -158,7 +158,7 @@ class AnnotationManager(Manager):
#anonymous can only see public items
public_layers = self.model.public_layers()
if user.is_anonymous():
if user.is_anonymous:
qs = qs.filter(layer__in=public_layers)
#users can see public and own
else:

View file

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
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 import get_user_model
@ -83,16 +81,15 @@ 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()
#FIXME: here having a item,start index would be good
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='annotations')
item = models.ForeignKey('item.Item', related_name='annotations')
clip = models.ForeignKey('clip.Clip', null=True, related_name='annotations')
user = models.ForeignKey(User, related_name='annotations', on_delete=models.CASCADE)
item = models.ForeignKey('item.Item', related_name='annotations', on_delete=models.CASCADE)
clip = models.ForeignKey('clip.Clip', null=True, related_name='annotations', on_delete=models.CASCADE)
public_id = models.CharField(max_length=128, unique=True)
#seconds
@ -107,7 +104,7 @@ class Annotation(models.Model):
languages = models.CharField(max_length=255, null=True, blank=True)
def editable(self, user):
if user.is_authenticated():
if user.is_authenticated:
if user.profile.capability('canEditAnnotations') or \
self.user == user or \
user.groups.filter(id__in=self.item.groups.all()).count() > 0:
@ -400,7 +397,7 @@ class Annotation(models.Model):
return j
def __str__(self):
return u"%s %s-%s" % (self.public_id, self.start, self.end)
return "%s %s-%s" % (self.public_id, self.start, self.end)
def cleanup_related(sender, **kwargs):
kwargs['instance'].cleanup_undefined_relations()

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.conf import settings
from django.contrib.auth import get_user_model

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.conf import settings
from django.db.models import Count, Sum, F, Value

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import codecs
import os
@ -38,7 +37,7 @@ def get_version():
version = settings.VERSION_EPOCH + version
return version
else:
return u'unknown'
return 'unknown'
def load_config(init=False):
with open(settings.SITE_CONFIG) as f:

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import re
import ox.jsonc

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.conf import settings

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.conf import settings
from ... import documentation

View file

@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
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)
@ -20,7 +17,6 @@ class Page(models.Model):
def __str__(self):
return self.name
@python_2_unicode_compatible
class Settings(models.Model):
created = models.DateTimeField(auto_now_add=True)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import datetime

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import copy
from datetime import datetime

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import json
import subprocess

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
from os.path import exists

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.conf import settings

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import re

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.conf import settings

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import json
import os.path
@ -12,7 +11,6 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models.signals import pre_delete
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
from oxdjango import fields
@ -36,7 +34,6 @@ 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',
@ -55,7 +52,7 @@ class File(models.Model):
modified = models.DateTimeField(auto_now=True)
oshash = models.CharField(max_length=16, unique=True)
item = models.ForeignKey("item.Item", related_name='files', null=True)
item = models.ForeignKey("item.Item", related_name='files', null=True, on_delete=models.CASCADE)
path = models.CharField(max_length=2048, default="") # canoncial path/file
sort_path = models.CharField(max_length=2048, default="") # sort name
@ -483,7 +480,7 @@ class File(models.Model):
if k not in keys:
del data[k]
can_see_media = False
if user and not user.is_anonymous():
if user and not user.is_anonymous:
can_see_media = user.profile.capability('canSeeMedia') or \
user.is_staff or \
self.item.user == user or \
@ -598,15 +595,15 @@ class File(models.Model):
status = {}
if self.encoding:
for s in self.streams.all():
status[s.name()] = u'done' if s.available else u'encoding'
status[s.name()] = 'done' if s.available else 'encoding'
config = settings.CONFIG['video']
max_resolution = self.streams.get(source=None).resolution
for resolution in sorted(config['resolutions'], reverse=True):
if resolution <= max_resolution:
for f in config['formats']:
name = u'%sp.%s' % (resolution, f)
name = '%sp.%s' % (resolution, f)
if name not in status:
status[name] = u'queued'
status[name] = 'queued'
return status
def delete_frames(self):
@ -627,7 +624,6 @@ 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:
@ -636,11 +632,11 @@ class Volume(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='volumes')
user = models.ForeignKey(User, related_name='volumes', on_delete=models.CASCADE)
name = models.CharField(max_length=1024)
def __str__(self):
return u"%s's %s" % (self.user, self.name)
return "%s's %s" % (self.user, self.name)
def json(self):
return {
@ -652,7 +648,6 @@ class Volume(models.Model):
def inttime():
return int(time.time())
@python_2_unicode_compatible
class Instance(models.Model):
class Meta:
@ -668,11 +663,11 @@ class Instance(models.Model):
path = models.CharField(max_length=2048)
ignore = models.BooleanField(default=False)
file = models.ForeignKey(File, related_name='instances')
volume = models.ForeignKey(Volume, related_name='files')
file = models.ForeignKey(File, related_name='instances', on_delete=models.CASCADE)
volume = models.ForeignKey(Volume, related_name='files', on_delete=models.CASCADE)
def __str__(self):
return u"%s's %s <%s>" % (self.volume.user, self.path, self.file.oshash)
return "%s's %s <%s>" % (self.volume.user, self.path, self.file.oshash)
@property
def public_id(self):
@ -691,14 +686,13 @@ 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:
unique_together = ("file", "position")
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
file = models.ForeignKey(File, related_name="frames")
file = models.ForeignKey(File, related_name="frames", on_delete=models.CASCADE)
position = models.FloatField()
frame = models.ImageField(default=None, null=True, upload_to=frame_path)
width = models.IntegerField(default=0)
@ -711,7 +705,7 @@ class Frame(models.Model):
super(Frame, self).save(*args, **kwargs)
def __str__(self):
return u'%s/%s' % (self.file, self.position)
return '%s/%s' % (self.file, self.position)
def delete_frame(sender, **kwargs):
f = kwargs['instance']
@ -722,18 +716,17 @@ 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:
unique_together = ("file", "resolution", "format")
file = models.ForeignKey(File, related_name='streams')
file = models.ForeignKey(File, related_name='streams', on_delete=models.CASCADE)
resolution = models.IntegerField(default=96)
format = models.CharField(max_length=255, default='webm')
media = models.FileField(default=None, blank=True, upload_to=stream_path)
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True, on_delete=models.CASCADE)
available = models.BooleanField(default=False)
oshash = models.CharField(max_length=16, null=True, db_index=True)
info = JSONField(default=dict, editable=False)
@ -753,10 +746,10 @@ class Stream(models.Model):
return os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline')
def name(self):
return u"%sp.%s" % (self.resolution, self.format)
return "%sp.%s" % (self.resolution, self.format)
def __str__(self):
return u"%s/%s" % (self.file, self.name())
return "%s/%s" % (self.file, self.name())
def get(self, resolution, format):
streams = []

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function
from datetime import datetime
from time import time

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from glob import glob

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os.path
from datetime import datetime

View file

@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from datetime import datetime
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
import ox
@ -19,14 +17,13 @@ User = get_user_model()
'''
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 = JSONField(default=dict, editable=False)
def __str__(self):
return u'%s %s' % (self.type, self.created)
return '%s %s' % (self.type, self.created)
def json(self):
return self.value
@ -50,19 +47,18 @@ 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)
data = JSONField(default=dict, editable=False)
created = models.DateTimeField(db_index=True)
user = models.ForeignKey(User, null=True, related_name='changelog')
user = models.ForeignKey(User, null=True, related_name='changelog', on_delete=models.CASCADE)
changeid = models.TextField()
objects = managers.LogManager()
def __str__(self):
return u'%s %s %s' % (self.created, self.action, self.changeid)
return '%s %s %s' % (self.created, self.action, self.changeid)
def get_id(self):
return ox.toAZ(self.id)

View file

@ -1,4 +1,3 @@
from __future__ import print_function
import models
import item.models
@ -18,33 +17,33 @@ def recover_item(id):
created = old.value['created']
i.user = user.models.User.objects.get(username=i.data['user'])
for key in [
u'rendered',
u'random',
u'cuts',
u'duration',
u'id',
u'size',
u'posterFrame',
u'parts',
u'cutsperminute',
u'hue',
u'numberofcuts',
u'durations',
u'volume',
u'user',
u'words',
u'videoRatio',
u'aspectratio',
u'bitrate',
u'pixels',
u'created',
u'numberoffiles',
u'modified',
u'timesaccessed',
u'accessed',
u'resolution',
u'wordsperminute',
u'posterRatio'
'rendered',
'random',
'cuts',
'duration',
'id',
'size',
'posterFrame',
'parts',
'cutsperminute',
'hue',
'numberofcuts',
'durations',
'volume',
'user',
'words',
'videoRatio',
'aspectratio',
'bitrate',
'pixels',
'created',
'numberoffiles',
'modified',
'timesaccessed',
'accessed',
'resolution',
'wordsperminute',
'posterRatio'
]:
if key in i.data:
del i.data[key]

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import ox

View file

@ -215,7 +215,7 @@ class ClipManager(Manager):
for l in list(filter(lambda k: k in layer_ids, data['keys'])):
qs = qs.filter(**{l: True})
#anonymous can only see public clips
if not user or user.is_anonymous():
if not user or user.is_anonymous:
allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest']
qs = qs.filter(sort__rightslevel__lte=allowed_level)
#users can see public clips, there own clips and clips of there groups

View file

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
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
@ -15,7 +13,7 @@ from . import managers
def get_layers(item, interval=None, user=None):
from annotation.models import Annotation
if user and user.is_anonymous():
if user and user.is_anonymous:
user = None
layers = {}
@ -45,7 +43,6 @@ 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
@ -184,7 +181,7 @@ class MetaClip(object):
@property
def public_id(self):
return u"%s/%0.03f-%0.03f" % (self.item.public_id, float(self.start), float(self.end))
return "%s/%0.03f-%0.03f" % (self.item.public_id, float(self.start), float(self.end))
def __str__(self):
return self.public_id
@ -200,8 +197,8 @@ attrs = {
'modified': models.DateTimeField(auto_now=True),
'aspect_ratio': models.FloatField(default=0),
'item': models.ForeignKey('item.Item', related_name='clips'),
'sort': models.ForeignKey('item.ItemSort', related_name='matching_clips'),
'item': models.ForeignKey('item.Item', related_name='clips', on_delete=models.CASCADE),
'sort': models.ForeignKey('item.ItemSort', related_name='matching_clips', on_delete=models.CASCADE),
'user': models.IntegerField(db_index=True, null=True),
#seconds
@ -226,4 +223,4 @@ Clip = type('Clip', (MetaClip, models.Model), attrs)
class ClipRandom(models.Model):
id = models.BigIntegerField(primary_key=True)
clip = models.OneToOneField(Clip)
clip = models.OneToOneField(Clip, on_delete=models.CASCADE)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.conf import settings
import ox
@ -154,7 +153,7 @@ def findClips(request, data):
add_annotations(layer, aqs)
elif 'position' in query:
qs = order_query(qs, query['sort'])
ids = [u'%s/%0.03f-%0.03f' % (c['item__public_id'], c['start'], c['end'])
ids = ['%s/%0.03f-%0.03f' % (c['item__public_id'], c['start'], c['end'])
for c in qs.values('item__public_id', 'start', 'end')]
data['conditions'] = data['conditions'] + {
'value': data['position'],
@ -167,7 +166,7 @@ def findClips(request, data):
response['data']['position'] = utils.get_positions(ids, [qs[0].public_id])[0]
elif 'positions' in data:
qs = order_query(qs, query['sort'])
ids = [u'%s/%0.03f-%0.03f' % (c['item__public_id'], c['start'], c['end'])
ids = ['%s/%0.03f-%0.03f' % (c['item__public_id'], c['start'], c['end'])
for c in qs.values('item__public_id', 'start', 'end')]
response['data']['positions'] = utils.get_positions(ids, data['positions'])
else:

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -283,7 +283,7 @@ class DocumentManager(Manager):
qs = qs.distinct()
#anonymous can only see public items
if not user or user.is_anonymous():
if not user or user.is_anonymous:
level = 'guest'
allowed_level = settings.CONFIG['capabilities']['canSeeDocument'][level]
qs = qs.filter(rightslevel__lte=allowed_level)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -13,7 +12,6 @@ from django.db.models import Q, Sum, Max
from django.contrib.auth import get_user_model
from django.db.models.signals import pre_delete
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
from PIL import Image
@ -42,13 +40,12 @@ if not PY2:
def get_path(f, x):
return f.path(x)
@python_2_unicode_compatible
class Document(models.Model, FulltextMixin):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='documents')
user = models.ForeignKey(User, related_name='documents', on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, blank=True, related_name='documents')
extension = models.CharField(max_length=255)
@ -74,7 +71,7 @@ class Document(models.Model, FulltextMixin):
data = JSONField(default=dict, editable=False)
def update_access(self, user):
if not user.is_authenticated():
if not user.is_authenticated:
user = None
access, created = Access.objects.get_or_create(document=self, user=user)
if not created:
@ -161,7 +158,7 @@ class Document(models.Model, FulltextMixin):
elif i not in ('*', 'dimensions') and i not in self.facet_keys:
value = data.get(i)
if isinstance(value, list):
value = u'\n'.join(value)
value = '\n'.join(value)
save(i, value)
base_keys = ('id', 'size', 'dimensions', 'extension', 'matches')
@ -192,11 +189,11 @@ class Document(models.Model, FulltextMixin):
s.dimensions = ox.sort_string('%d' % prefix) + ox.sort_string('%d' % value)
def sortNames(values):
sort_value = u''
sort_value = ''
if values:
sort_value = u'; '.join([get_name_sort(name) for name in values])
sort_value = '; '.join([get_name_sort(name) for name in values])
if not sort_value:
sort_value = u''
sort_value = ''
return sort_value.lower()
def set_value(s, name, value):
@ -229,7 +226,7 @@ class Document(models.Model, FulltextMixin):
if isinstance(sort_type, list):
sort_type = sort_type[0]
if sort_type == 'title':
value = self.get_value(source, u'Untitled')
value = self.get_value(source, 'Untitled')
value = utils.sort_title(value)[:955]
set_value(s, name, value)
elif sort_type == 'person':
@ -237,9 +234,9 @@ class Document(models.Model, FulltextMixin):
value = utils.sort_string(value)[:955]
set_value(s, name, value)
elif sort_type == 'string':
value = self.get_value(source, u'')
value = self.get_value(source, '')
if isinstance(value, list):
value = u','.join(value)
value = ','.join(value)
if not isinstance(value, str):
value = str(value)
value = utils.sort_string(value)[:955]
@ -319,7 +316,7 @@ class Document(models.Model, FulltextMixin):
return ox.toAZ(self.id)
def access(self, user):
if user.is_anonymous():
if user.is_anonymous:
level = 'guest'
else:
level = user.profile.get_level()
@ -332,7 +329,7 @@ class Document(models.Model, FulltextMixin):
return False
def editable(self, user, item=None):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
if self.user == user or \
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
@ -693,8 +690,8 @@ class ItemProperties(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
item = models.ForeignKey(Item)
document = models.ForeignKey(Document, related_name='descriptions')
item = models.ForeignKey(Item, on_delete=models.CASCADE)
document = models.ForeignKey(Document, related_name='descriptions', on_delete=models.CASCADE)
description = models.TextField(default="")
index = models.IntegerField(default=0)
@ -709,14 +706,13 @@ class ItemProperties(models.Model):
super(ItemProperties, self).save(*args, **kwargs)
@python_2_unicode_compatible
class Access(models.Model):
class Meta:
unique_together = ("document", "user")
access = models.DateTimeField(auto_now=True)
document = models.ForeignKey(Document, related_name='accessed')
user = models.ForeignKey(User, null=True, related_name='accessed_documents')
document = models.ForeignKey(Document, related_name='accessed', on_delete=models.CASCADE)
user = models.ForeignKey(User, null=True, related_name='accessed_documents', on_delete=models.CASCADE)
accessed = models.IntegerField(default=0)
def save(self, *args, **kwargs):
@ -729,10 +725,9 @@ class Access(models.Model):
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)
return "%s/%s/%s" % (self.user, self.document, self.access)
return "%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.
@ -743,13 +738,13 @@ class Facet(models.Model):
class Meta:
unique_together = ("document", "key", "value")
document = models.ForeignKey('Document', related_name='facets')
document = models.ForeignKey('Document', related_name='facets', on_delete=models.CASCADE)
key = models.CharField(max_length=200, db_index=True)
value = models.CharField(max_length=1000, db_index=True)
sortvalue = models.CharField(max_length=1000, db_index=True)
def __str__(self):
return u"%s=%s" % (self.key, self.value)
return "%s=%s" % (self.key, self.value)
def save(self, *args, **kwargs):
if not self.sortvalue:
@ -768,18 +763,17 @@ 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:
unique_together = ('document', 'key')
document = models.ForeignKey('Document', related_name='find', db_index=True)
document = models.ForeignKey('Document', related_name='find', db_index=True, on_delete=models.CASCADE)
key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM)
def __str__(self):
return u'%s=%s' % (self.key, self.value)
return '%s=%s' % (self.key, self.value)
'''
Sort
@ -787,7 +781,7 @@ table constructed based on info in settings.CONFIG['documentKeys']
'''
attrs = {
'__module__': 'document.models',
'document': models.OneToOneField('Document', related_name='sort', primary_key=True),
'document': models.OneToOneField('Document', related_name='sort', primary_key=True, on_delete=models.CASCADE),
'created': models.DateTimeField(null=True, blank=True, db_index=True),
}
for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['documentKeys'])):

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re

View file

@ -124,7 +124,7 @@ class CollectionManager(Manager):
if conditions:
qs = qs.filter(conditions)
if user.is_anonymous():
if user.is_anonymous:
qs = qs.filter(Q(status='public') | Q(status='featured'))
else:
qs = qs.filter(Q(status='public') | Q(status='featured') | Q(user=user))

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -10,7 +9,6 @@ from django.db import models
from django.db.models import Max
from django.contrib.auth import get_user_model
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
import ox
@ -36,7 +34,6 @@ def get_collectionview():
def get_collectionsort():
return tuple(settings.CONFIG['user']['ui']['collectionSort'])
@python_2_unicode_compatible
class Collection(models.Model):
class Meta:
@ -44,7 +41,7 @@ class Collection(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='collections')
user = models.ForeignKey(User, related_name='collections', on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, blank=True, related_name='collections')
name = models.CharField(max_length=255)
status = models.CharField(max_length=20, default='private')
@ -58,7 +55,7 @@ class Collection(models.Model):
view = models.TextField(default=get_collectionview)
sort = JSONField(default=get_collectionsort, editable=False)
poster_frames = JSONField(default=[], editable=False)
poster_frames = JSONField(default=list, editable=False)
#is through table still required?
documents = models.ManyToManyField('document.Document', related_name='collections',
@ -117,13 +114,13 @@ class Collection(models.Model):
return self.get_id()
def get_id(self):
return u'%s:%s' % (self.user.username, self.name)
return '%s:%s' % (self.user.username, self.name)
def accessible(self, user):
return self.user == user or self.status in ('public', 'featured')
def editable(self, user):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
if self.user == user or \
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
@ -251,7 +248,7 @@ class Collection(models.Model):
elif key == 'subscribers':
response[key] = self.subscribed_users.all().count()
elif key == 'subscribed':
if user and not user.is_anonymous():
if user and not user.is_anonymous:
response[key] = self.subscribed_users.filter(id=user.id).exists()
else:
response[key] = getattr(self, {
@ -318,28 +315,26 @@ 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)
collection = models.ForeignKey(Collection)
collection = models.ForeignKey(Collection, on_delete=models.CASCADE)
index = models.IntegerField(default=0)
document = models.ForeignKey('document.Document')
document = models.ForeignKey('document.Document', on_delete=models.CASCADE)
def __str__(self):
return u'%s in %s' % (self.document, self.collection)
return '%s in %s' % (self.document, self.collection)
@python_2_unicode_compatible
class Position(models.Model):
class Meta:
unique_together = ("user", "collection", "section")
collection = models.ForeignKey(Collection, related_name='position')
user = models.ForeignKey(User, related_name='collection_positions')
collection = models.ForeignKey(Collection, related_name='position', on_delete=models.CASCADE)
user = models.ForeignKey(User, related_name='collection_positions', on_delete=models.CASCADE)
section = models.CharField(max_length=255)
position = models.IntegerField(default=0)
def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.collection)
return '%s/%s/%s' % (self.section, self.position, self.collection)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -75,7 +74,7 @@ def findCollections(request, data):
query = parse_query(data, request.user)
#order
is_section_request = query['sort'] == [{u'operator': u'+', u'key': u'position'}]
is_section_request = query['sort'] == [{'operator': '+', 'key': 'position'}]
def is_featured_condition(x):
return x['key'] == 'status' and \
@ -89,7 +88,7 @@ def findCollections(request, data):
if is_section_request:
qs = query['qs']
if not is_featured and not request.user.is_anonymous():
if not is_featured and not request.user.is_anonymous:
qs = qs.filter(position__in=models.Position.objects.filter(user=request.user))
qs = qs.order_by('position__position')
else:

View file

@ -124,7 +124,7 @@ class EditManager(Manager):
if conditions:
qs = qs.filter(conditions)
if user.is_anonymous():
if user.is_anonymous:
qs = qs.filter(Q(status='public') | Q(status='featured'))
else:
qs = qs.filter(Q(status='public') | Q(status='featured') | Q(user=user))

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import re
import os
@ -15,7 +14,6 @@ from django.db import models, transaction
from django.db.models import Max
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
from annotation.models import Annotation
@ -35,7 +33,6 @@ User = get_user_model()
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:
@ -45,7 +42,7 @@ class Edit(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='edits')
user = models.ForeignKey(User, related_name='edits', on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, blank=True, related_name='edits')
name = models.CharField(max_length=255)
@ -59,11 +56,11 @@ class Edit(models.Model):
icon = models.ImageField(default=None, blank=True, null=True, upload_to=get_icon_path)
poster_frames = JSONField(default=[], editable=False)
poster_frames = JSONField(default=list, editable=False)
subscribed_users = models.ManyToManyField(User, related_name='subscribed_edits')
def __str__(self):
return u'%s (%s)' % (self.name, self.user)
return '%s (%s)' % (self.name, self.user)
@classmethod
def get(cls, id):
@ -73,7 +70,7 @@ class Edit(models.Model):
return cls.objects.get(user__username=username, name=name)
def get_id(self):
return u'%s:%s' % (self.user.username, self.name)
return '%s:%s' % (self.user.username, self.name)
def get_absolute_url(self):
return ('/edits/%s' % quote(self.get_id())).replace('%3A', ':')
@ -137,7 +134,7 @@ class Edit(models.Model):
return self.user == user or self.status in ('public', 'featured')
def editable(self, user):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
if self.user == user or \
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
@ -403,7 +400,7 @@ class Edit(models.Model):
elif key == 'subscribers':
response[key] = self.subscribed_users.all().count()
elif key == 'subscribed':
if user and not user.is_anonymous():
if user and not user.is_anonymous:
response[key] = self.subscribed_users.filter(id=user.id).exists()
elif hasattr(self, _map.get(key, key)):
response[key] = getattr(self, _map.get(key, key))
@ -430,15 +427,14 @@ 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)
edit = models.ForeignKey(Edit, related_name='clips')
edit = models.ForeignKey(Edit, related_name='clips', on_delete=models.CASCADE)
index = models.IntegerField(default=0)
item = models.ForeignKey(Item, null=True, default=None, related_name='editclip')
annotation = models.ForeignKey(Annotation, null=True, default=None, related_name='editclip')
item = models.ForeignKey(Item, null=True, default=None, related_name='editclip', on_delete=models.CASCADE)
annotation = models.ForeignKey(Annotation, null=True, default=None, related_name='editclip', on_delete=models.CASCADE)
start = models.FloatField(default=0)
end = models.FloatField(default=0)
duration = models.FloatField(default=0)
@ -454,8 +450,8 @@ class Clip(models.Model):
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)
return '%s' % self.annotation.public_id
return '%s/%0.3f-%0.3f' % (self.item.public_id, self.start, self.end)
def get_id(self):
return ox.toAZ(self.id)
@ -541,17 +537,16 @@ 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:
unique_together = ("user", "edit", "section")
edit = models.ForeignKey(Edit, related_name='position')
user = models.ForeignKey(User, related_name='edit_position')
edit = models.ForeignKey(Edit, related_name='position', on_delete=models.CASCADE)
user = models.ForeignKey(User, related_name='edit_position', on_delete=models.CASCADE)
section = models.CharField(max_length=255)
position = models.IntegerField(default=0)
def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.edit)
return '%s/%s/%s' % (self.section, self.position, self.edit)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -404,7 +403,8 @@ def findEdits(request, data):
query = parse_query(data, request.user)
#order
is_section_request = query['sort'] == [{u'operator': u'+', u'key': u'position'}]
is_section_request = query['sort'] == [{'operator': '+', 'key': 'position'}]
def is_featured_condition(x):
return x['key'] == 'status' and \
x['value'] == 'featured' and \
@ -414,7 +414,7 @@ def findEdits(request, data):
if is_section_request:
qs = query['qs']
if not is_featured and not request.user.is_anonymous():
if not is_featured and not request.user.is_anonymous:
qs = qs.filter(position__in=models.Position.objects.filter(user=request.user))
qs = qs.order_by('position__position')
else:

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -14,7 +13,6 @@ from django.contrib.auth import get_user_model
from django.db.models.signals import pre_delete, post_init
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
import ox
@ -28,7 +26,6 @@ from . import managers
User = get_user_model()
@python_2_unicode_compatible
class Entity(models.Model):
class ValueError(ValueError):
'''Raised if a field name or value is invalid (based on the "entities"
@ -38,7 +35,7 @@ class Entity(models.Model):
class Meta:
unique_together = ("type", "name")
user = models.ForeignKey(User, related_name='entities', null=True, default=None)
user = models.ForeignKey(User, related_name='entities', null=True, default=None, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
@ -64,7 +61,7 @@ class Entity(models.Model):
self.name = self.name.decode('utf-8')
self.name_sort = get_name_sort(self.name)[:255].lower()
else:
self.name_sort = ox.sort_string(self.name or u'')[:255].lower() or None
self.name_sort = ox.sort_string(self.name or '')[:255].lower() or None
self.name_find = '||' + '||'.join((self.name,) + self.alternativeNames) + '||'
self.name_find = self.name_find.lower()
super(Entity, self).save(*args, **kwargs)
@ -88,11 +85,11 @@ class Entity(models.Model):
@classmethod
def get_by_name(cls, name, type):
return cls.objects.get(name_find__contains=u'|%s|' % name.lower(), type=type)
return cls.objects.get(name_find__contains='|%s|' % name.lower(), type=type)
@classmethod
def get_or_create(model, name):
qs = model.objects.filter(name_find__contains=u'|%s|' % name.lower())
qs = model.objects.filter(name_find__contains='|%s|' % name.lower())
if qs.count() == 0:
instance = model(name=name)
instance.save()
@ -117,7 +114,7 @@ class Entity(models.Model):
DocumentProperties.objects.filter(document=document, entity=self).delete()
def editable(self, user, item=None):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
if user.is_staff or \
user.profile.capability('canEditEntities') == True or \
@ -140,7 +137,7 @@ class Entity(models.Model):
data['name'] = "Unnamed"
name = data['name']
n = 1
while Entity.objects.filter(name_find__contains=u'|%s|' % name.lower()).exclude(id=self.id).count() > 0:
while Entity.objects.filter(name_find__contains='|%s|' % name.lower()).exclude(id=self.id).count() > 0:
n += 1
name = data['name'] + ' [%d]' % n
self.name = name
@ -155,7 +152,7 @@ class Entity(models.Model):
name_ = name
n = 1
while name in used_names or \
Entity.objects.filter(name_find__contains=u'|%s|' % name.lower()).exclude(id=self.id).count() > 0:
Entity.objects.filter(name_find__contains='|%s|' % name.lower()).exclude(id=self.id).count() > 0:
n += 1
name = name_ + ' [%d]' % n
names.append(name)
@ -268,7 +265,7 @@ class Entity(models.Model):
return response
def annotation_value(self):
#return u'<a href="/entities/%s">%s</a>' % (self.get_id(), ox.escape_html(self.name))
#return '<a href="/entities/%s">%s</a>' % (self.get_id(), ox.escape_html(self.name))
return ox.escape_html(self.name)
def update_find(self):
@ -292,10 +289,10 @@ class Entity(models.Model):
for key in entity['keys']:
value = self.data.get(key['id'])
if isinstance(value, list):
value = u'\n'.join(value)
value = '\n'.join(value)
save(key['id'], value)
ids.append(key['id'])
save('name', u'\n'.join([self.name] + list(self.alternativeNames)))
save('name', '\n'.join([self.name] + list(self.alternativeNames)))
self.find.exclude(key__in=ids).delete()
def update_matches(self):
@ -344,7 +341,6 @@ post_init.connect(
)
@python_2_unicode_compatible
class DocumentProperties(models.Model):
class Meta:
@ -353,42 +349,40 @@ class DocumentProperties(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
document = models.ForeignKey(Document, related_name='documentproperties')
entity = models.ForeignKey(Entity, related_name='documentproperties')
document = models.ForeignKey(Document, related_name='documentproperties', on_delete=models.CASCADE)
entity = models.ForeignKey(Entity, related_name='documentproperties', on_delete=models.CASCADE)
index = models.IntegerField(default=0)
data = JSONField(default=dict, editable=False)
def __str__(self):
return u"%r-%r" % (self.document, self.entity)
return "%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:
unique_together = ("entity", "key")
entity = models.ForeignKey('Entity', related_name='find', db_index=True)
entity = models.ForeignKey('Entity', related_name='find', db_index=True, on_delete=models.CASCADE)
key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM)
def __str__(self):
return u"%s=%s" % (self.key, self.value)
return "%s=%s" % (self.key, self.value)
@python_2_unicode_compatible
class Link(models.Model):
'''Models entity fields of type "entity".'''
class Meta:
unique_together = ("source", "key", "target")
source = models.ForeignKey(Entity, related_name='links')
source = models.ForeignKey(Entity, related_name='links', on_delete=models.CASCADE)
key = models.CharField(max_length=200)
target = models.ForeignKey(Entity, related_name='backlinks')
target = models.ForeignKey(Entity, related_name='backlinks', on_delete=models.CASCADE)
def __str__(self):
return u"%s-[%s]->%s" % (self.source, self.key, self.target)
return "%s-[%s]->%s" % (self.source, self.key, self.target)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from six import string_types
import ox
@ -60,7 +59,7 @@ def addEntity(request, data):
for name in names:
name = ox.decode_html(name)
if models.Entity.objects.filter(type=data['type'],
name_find__icontains=u'|%s|'%name).count() != 0:
name_find__icontains='|%s|'%name).count() != 0:
exists = True
existing_names.append(name)
if not exists:
@ -87,7 +86,7 @@ def addEntity(request, data):
type = data['type']
name = 'Unnamed'
num = 1
while models.Entity.objects.filter(name_find__icontains=u'|%s|'%name).count() > 0:
while models.Entity.objects.filter(name_find__icontains='|%s|'%name).count() > 0:
num += 1
name = 'Unnamed [%d]' % num
entity = models.Entity(name=name, type=type)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db import models, transaction
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible
import ox
from oxdjango import fields
@ -19,7 +17,6 @@ from . import managers
User = get_user_model()
@python_2_unicode_compatible
class Event(models.Model):
'''
Events are events in time that can be once or recurring,
@ -33,7 +30,7 @@ class Event(models.Model):
modified = models.DateTimeField(auto_now=True)
defined = models.BooleanField(default=False)
user = models.ForeignKey(User, null=True, related_name='events')
user = models.ForeignKey(User, null=True, related_name='events', on_delete=models.CASCADE)
name = models.CharField(null=True, max_length=255, unique=True)
name_sort = models.CharField(null=True, max_length=255, db_index=True)
@ -66,7 +63,7 @@ class Event(models.Model):
@classmethod
def get_or_create(model, name):
qs = model.objects.filter(name_find__contains=u'|%s|' % name.lower())
qs = model.objects.filter(name_find__contains='|%s|' % name.lower())
if qs.count() == 0:
instance = model(name=name)
instance.save()
@ -75,7 +72,7 @@ class Event(models.Model):
return instance
def editable(self, user):
if user and not user.is_anonymous() \
if user and not user.is_anonymous \
and (not self.user or \
self.user == user or \
user.profile.capability('canEditEvents')):

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from celery.task import task

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db.models import Count
from django.conf import settings
@ -37,7 +36,7 @@ def addEvent(request, data):
for name in names:
name = ox.decode_html(name)
if models.Event.objects.filter(defined=True,
name_find__icontains=u'|%s|'%name).count() != 0:
name_find__icontains='|%s|'%name).count() != 0:
exists = True
existing_names.append(name)
if not exists:
@ -93,7 +92,7 @@ def editEvent(request, data):
names = [data.get('name', event.name)] + data.get('alternativeNames', [])
for name in names:
if models.Event.objects.filter(defined=True,
name_find__icontains=u'|%s|'%name).exclude(id=event.id).count() != 0:
name_find__icontains='|%s|'%name).exclude(id=event.id).count() != 0:
conflict = True
conflict_names.append(name)
if not conflict:

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from six import string_types
from six.moves.urllib.parse import quote
@ -7,7 +6,6 @@ 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
from oxdjango.fields import JSONField
import ox
@ -17,7 +15,6 @@ 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)
@ -27,7 +24,7 @@ class Item(models.Model):
data = JSONField(default=dict, editable=False)
def editable(self, user):
return user.is_authenticated() and user.profile.capability("canManageHome")
return user.is_authenticated and user.profile.capability("canManageHome")
def edit(self, data):
changed = False
@ -153,7 +150,7 @@ class Item(models.Model):
return j
def __str__(self):
return u"%s" % (self.get_id())
return "%s" % (self.get_id())
def delete_item(type, contentid):
for home in Item.objects.all():

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.conf import settings

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
from glob import glob

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import time

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
@ -44,7 +43,13 @@ class Command(BaseCommand):
(document.models.Find._meta.db_table, 'value'), # Document Find
):
cursor = connection.cursor()
indexes = connection.introspection.get_indexes(cursor, table)
contraints = connection.introspection.get_constraints(cursor, table)
indexes = {
','.join(c['columns']): {'primary_key': c['primary_key'], 'unique': c['unique']}
for k, c in contraints.items()
if c['index'] or c['primary_key'] or c['unique']
}
#indexes = connection.introspection.get_indexes(cursor, table)
drop = []
if column in indexes:
for sql in (

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from django.core.management.base import BaseCommand

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
@ -38,10 +37,10 @@ class Command(BaseCommand):
versions = os.path.join(prefix, os.path.dirname(path), 'Versions')
s = f.streams.filter(source=None)[0]
basename = os.path.basename(path).rsplit('.', 1)[0]
target = os.path.join(versions, u'%s.%s' % (basename, s.format))
target = os.path.join(versions, '%s.%s' % (basename, s.format))
link(s.media.path, target)
else:
s = f.streams.filter(source=None)[0]
basename = path.rsplit('.', 1)[0]
target = os.path.join(prefix, u'%s.%s' % (basename, s.format))
target = os.path.join(prefix, '%s.%s' % (basename, s.format))
link(s.media.path, target)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from datetime import datetime
import unicodedata
@ -81,7 +80,7 @@ def parseCondition(condition, user, owner=None):
if (not exclude and op == '=' or op in ('$', '^')) and v == '':
return Q()
elif k == 'filename' and (user.is_anonymous() or not user.profile.capability('canSeeMedia')):
elif k == 'filename' and (user.is_anonymous or not user.profile.capability('canSeeMedia')):
return Q(id=0)
elif k == 'oshash':
return Q(files__oshash=v)
@ -100,7 +99,7 @@ def parseCondition(condition, user, owner=None):
q = ~q
return q
elif k in ('canplayvideo', 'canplayclips'):
level = user.is_anonymous() and 'guest' or user.profile.get_level()
level = user.is_anonymous and 'guest' or user.profile.get_level()
allowed_level = settings.CONFIG['capabilities'][{
'canplayvideo': 'canPlayVideo',
'canplayclips': 'canPlayClips'
@ -249,7 +248,7 @@ class ItemManager(Manager):
if l != "*":
l = l.split(":")
only_public = True
if not user.is_anonymous():
if not user.is_anonymous:
if len(l) == 1:
l = [user.username] + l
if user.username == l[0]:
@ -305,7 +304,7 @@ class ItemManager(Manager):
qs = qs.distinct()
#anonymous can only see public items
if not user or user.is_anonymous():
if not user or user.is_anonymous:
level = 'guest'
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][level]
qs = qs.filter(level__lte=allowed_level)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import json
import os
@ -21,7 +20,6 @@ from django.core.files.temp import NamedTemporaryFile
from django.db import models, transaction, connection
from django.db.models import Q, Sum, Max
from django.db.models.signals import pre_delete
from django.utils.encoding import python_2_unicode_compatible
from django.utils import datetime_safe
import ox
@ -164,12 +162,11 @@ 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)
user = models.ForeignKey(User, null=True, related_name='items')
user = models.ForeignKey(User, null=True, related_name='items', on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, blank=True, related_name='items')
# while metadata is updated, files are set to rendered=False
@ -221,7 +218,7 @@ class Item(models.Model):
return default
def access(self, user):
if user.is_anonymous():
if user.is_anonymous:
level = 'guest'
else:
level = user.profile.get_level()
@ -236,7 +233,7 @@ class Item(models.Model):
return False
def editable(self, user):
if user.is_anonymous():
if user.is_anonymous:
return False
if user.profile.capability('canEditMetadata') or \
user.is_staff or \
@ -350,10 +347,10 @@ class Item(models.Model):
def __str__(self):
year = self.get('year')
if year:
string = u'%s (%s)' % (ox.decode_html(self.get('title', 'Untitled')), self.get('year'))
string = '%s (%s)' % (ox.decode_html(self.get('title', 'Untitled')), self.get('year'))
else:
string = self.get('title', u'Untitled')
return u'[%s] %s' % (self.public_id, string)
string = self.get('title', 'Untitled')
return '[%s] %s' % (self.public_id, string)
def get_absolute_url(self):
return '/%s' % self.public_id
@ -400,7 +397,7 @@ class Item(models.Model):
title = self.get(key, 'Untitled')
while q.count() != 0:
n += 1
self.data[key] = u'%s [%d]' % (title, n)
self.data[key] = '%s [%d]' % (title, n)
oxdbId = self.oxdb_id()
q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id)
self.oxdbId = oxdbId
@ -821,7 +818,7 @@ class Item(models.Model):
for key in settings.CONFIG['itemKeys']:
i = key['id']
if i == 'title':
save(i, u'\n'.join(get_titles()))
save(i, '\n'.join(get_titles()))
elif i == 'rightslevel':
save(i, self.level)
elif i == 'filename':
@ -830,17 +827,17 @@ class Item(models.Model):
qs = Annotation.objects.filter(item=self)
qs = qs.filter(layer__in=Annotation.public_layers()).exclude(findvalue=None)
qs = qs.order_by('start')
save(i, u'\n'.join([l.findvalue for l in qs]))
save(i, '\n'.join([l.findvalue for l in qs]))
elif key['type'] == 'layer':
qs = Annotation.objects.filter(item=self).exclude(findvalue=None)
qs = qs.filter(layer=i)
qs = qs.order_by('start')
save(i, u'\n'.join(list(filter(None, [l.findvalue for l in qs]))))
save(i, '\n'.join(list(filter(None, [l.findvalue for l in qs]))))
layer_keys.append(i)
elif i != '*' and i not in self.facet_keys:
value = self.get(i)
if isinstance(value, list):
value = u'\n'.join(value)
value = '\n'.join(value)
save(i, value)
for key in self.facet_keys:
@ -911,11 +908,11 @@ class Item(models.Model):
s = ItemSort(item=self)
def sortNames(values):
sort_value = u''
sort_value = ''
if values:
sort_value = u'; '.join([get_name_sort(name) for name in values])
sort_value = '; '.join([get_name_sort(name) for name in values])
if not sort_value:
sort_value = u''
sort_value = ''
return sort_value.lower()
def set_value(s, name, value):
@ -1019,7 +1016,7 @@ class Item(models.Model):
sort_type = sort_type[0]
if name not in self.base_keys:
if sort_type == 'title':
value = get_title_sort(self.get(source, u'Untitled'))
value = get_title_sort(self.get(source, 'Untitled'))
value = utils.sort_title(value)[:955]
set_value(s, name, value)
elif sort_type == 'person':
@ -1027,9 +1024,9 @@ class Item(models.Model):
value = utils.sort_string(value)[:955]
set_value(s, name, value)
elif sort_type == 'string':
value = self.get(source, u'')
value = self.get(source, '')
if isinstance(value, list):
value = u','.join(value)
value = ','.join(value)
value = utils.sort_string(value)[:955]
set_value(s, name, value)
elif sort_type == 'words':
@ -1784,7 +1781,6 @@ 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,
@ -1795,19 +1791,19 @@ class ItemFind(models.Model):
class Meta:
unique_together = ("item", "key")
item = models.ForeignKey('Item', related_name='find', db_index=True)
item = models.ForeignKey('Item', related_name='find', db_index=True, on_delete=models.CASCADE)
key = models.CharField(max_length=200, db_index=True)
value = models.TextField(blank=True, db_index=settings.DB_GIN_TRGM)
def __str__(self):
return u"%s=%s" % (self.key, self.value)
return "%s=%s" % (self.key, self.value)
'''
ItemSort
table constructed based on info in settings.CONFIG['itemKeys']
'''
attrs = {
'__module__': 'item.models',
'item': models.OneToOneField('Item', related_name='sort', primary_key=True),
'item': models.OneToOneField('Item', related_name='sort', primary_key=True, on_delete=models.CASCADE),
'duration': models.FloatField(null=True, blank=True, db_index=True),
'width': models.BigIntegerField(null=True, blank=True, db_index=True),
'height': models.BigIntegerField(null=True, blank=True, db_index=True),
@ -1826,14 +1822,13 @@ 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")
access = models.DateTimeField(auto_now=True)
item = models.ForeignKey(Item, related_name='accessed')
user = models.ForeignKey(User, null=True, related_name='accessed_items')
item = models.ForeignKey(Item, related_name='accessed', on_delete=models.CASCADE)
user = models.ForeignKey(User, null=True, related_name='accessed_items', on_delete=models.CASCADE)
accessed = models.IntegerField(default=0)
def save(self, *args, **kwargs):
@ -1846,10 +1841,9 @@ class Access(models.Model):
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)
return "%s/%s/%s" % (self.user, self.item, self.access)
return "%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.
@ -1860,13 +1854,13 @@ class Facet(models.Model):
class Meta:
unique_together = ("item", "key", "value")
item = models.ForeignKey('Item', related_name='facets')
item = models.ForeignKey('Item', related_name='facets', on_delete=models.CASCADE)
key = models.CharField(max_length=200, db_index=True)
value = models.CharField(max_length=1000, db_index=True)
sortvalue = models.CharField(max_length=1000, db_index=True)
def __str__(self):
return u"%s=%s" % (self.key, self.value)
return "%s=%s" % (self.key, self.value)
def save(self, *args, **kwargs):
if not self.sortvalue:
@ -1886,7 +1880,7 @@ class Description(models.Model):
class AnnotationSequence(models.Model):
item = models.OneToOneField('Item', related_name='_annotation_sequence')
item = models.OneToOneField('Item', related_name='_annotation_sequence', on_delete=models.CASCADE)
value = models.BigIntegerField(default=1)
@classmethod

51
pandora/item/site.py Normal file
View file

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
from django.urls import path, re_path
from . import views
urls = [
[
#frames
re_path(r'^(?P<id>[A-Z0-9].*)/(?P<size>\d+)p(?P<position>[\d\.]*)\.jpg$', views.frame),
#timelines
re_path(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p(?P<position>\d+)\.(?P<format>png|jpg)$', views.timeline),
re_path(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p\.(?P<format>png|jpg)$', views.timeline),
#download
re_path(r'^(?P<id>[A-Z0-9].*)/download$', views.download),
re_path(r'^(?P<id>[A-Z0-9].*)/download/$', views.download),
re_path(r'^(?P<id>[A-Z0-9].*)/download/source/(?P<part>\d+)?$', views.download_source),
re_path(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p(?P<part>\d+)\.(?P<format>webm|ogv|mp4)$', views.download),
re_path(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p\.(?P<format>webm|ogv|mp4)$', views.download),
#video
re_path(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', views.video),
re_path(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<track>.+)\.(?P<format>webm|ogv|mp4)$', views.video),
#torrent
re_path(r'^(?P<id>[A-Z0-9].*)/torrent$', views.torrent),
re_path(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', views.torrent),
#export
re_path(r'^(?P<id>[A-Z0-9].*)/json$', views.item_json),
re_path(r'^(?P<id>[A-Z0-9].*)/xml$', views.item_xml),
#srt export
re_path(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.(?:(?P<language>.{2})\.)?(?P<ext>srt|vtt)$', views.srt),
#icon
re_path(r'^(?P<id>[A-Z0-9].*)/icon(?P<size>\d*)\.jpg$', views.icon),
#poster
re_path(r'^(?P<id>[A-Z0-9].*)/posterframe(?P<position>\d+).jpg$', views.poster_frame),
re_path(r'^(?P<id>[A-Z0-9].*)/poster(?P<size>\d+)\.jpg$', views.poster),
re_path(r'^(?P<id>[A-Z0-9].*)/siteposter(?P<size>\d*)\.jpg$', views.siteposter),
re_path(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', views.siteposter),
re_path(r'^random$', views.random_annotation),
],
'item',
'item',
]

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
from datetime import timedelta, datetime

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, with_statement, print_function
import math
import os

View file

@ -1,47 +0,0 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url
from . import views
urlpatterns = [
#frames
url(r'^(?P<id>[A-Z0-9].*)/(?P<size>\d+)p(?P<position>[\d\.]*)\.jpg$', views.frame),
#timelines
url(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p(?P<position>\d+)\.(?P<format>png|jpg)$', views.timeline),
url(r'^(?P<id>[A-Z0-9].*)/timeline(?P<mode>[a-z]*)(?P<size>\d+)p\.(?P<format>png|jpg)$', views.timeline),
#download
url(r'^(?P<id>[A-Z0-9].*)/download$', views.download),
url(r'^(?P<id>[A-Z0-9].*)/download/$', views.download),
url(r'^(?P<id>[A-Z0-9].*)/download/source/(?P<part>\d+)?$', views.download_source),
url(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p(?P<part>\d+)\.(?P<format>webm|ogv|mp4)$', views.download),
url(r'^(?P<id>[A-Z0-9].*)/download/(?P<resolution>\d+)p\.(?P<format>webm|ogv|mp4)$', views.download),
#video
url(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', views.video),
url(r'^(?P<id>[A-Z0-9].*)/(?P<resolution>\d+)p(?P<index>\d*)\.(?P<track>.+)\.(?P<format>webm|ogv|mp4)$', views.video),
#torrent
url(r'^(?P<id>[A-Z0-9].*)/torrent$', views.torrent),
url(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', views.torrent),
#export
url(r'^(?P<id>[A-Z0-9].*)/json$', views.item_json),
url(r'^(?P<id>[A-Z0-9].*)/xml$', views.item_xml),
#srt export
url(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.(?:(?P<language>.{2})\.)?(?P<ext>srt|vtt)$', views.srt),
#icon
url(r'^(?P<id>[A-Z0-9].*)/icon(?P<size>\d*)\.jpg$', views.icon),
#poster
url(r'^(?P<id>[A-Z0-9].*)/posterframe(?P<position>\d+).jpg$', views.poster_frame),
url(r'^(?P<id>[A-Z0-9].*)/poster(?P<size>\d+)\.jpg$', views.poster),
url(r'^(?P<id>[A-Z0-9].*)/siteposter(?P<size>\d*)\.jpg$', views.siteposter),
url(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', views.siteposter),
url(r'^random$', views.random_annotation),
]

View file

@ -55,14 +55,14 @@ def plural_key(term):
def sort_title(title):
title = title.replace(u'Æ', 'Ae')
title = title.replace('Æ', 'Ae')
if isinstance(title, bytes):
title = title.decode('utf-8')
title = ox.decode_html(title)
title = sort_string(title)
#title
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
title = re.sub('[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
return title.strip()
def get_positions(ids, pos, decode_id=False):

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os.path
import mimetypes
@ -144,7 +143,7 @@ def get_positions(request, query):
return utils.get_positions(ids, query['positions'])
def is_editable(request, item):
if request.user.is_anonymous():
if request.user.is_anonymous:
return False
if not hasattr(request, 'user_group_names'):
request.user_group_names = {g.name for g in request.user.groups.all()}
@ -1097,7 +1096,7 @@ def video(request, id, resolution, format, index=None, track=None):
ext = '.%s' % format
duration = stream.info['duration']
filename = u"Clip of %s - %s-%s - %s %s%s" % (
filename = "Clip of %s - %s-%s - %s %s%s" % (
item.get('title'),
ox.format_duration(t[0] * 1000).replace(':', '.')[:-4],
ox.format_duration(t[1] * 1000).replace(':', '.')[:-4],
@ -1166,9 +1165,9 @@ def srt(request, id, layer, language=None, index=None, ext='srt'):
content_type, encoder = _subtitle_formats[ext]
response = HttpResponse()
if language:
filename = u"%s.%s.%s" % (item.get('title'), language, ext)
filename = "%s.%s.%s" % (item.get('title'), language, ext)
else:
filename = u"%s.%s" % (item.get('title'), ext)
filename = "%s.%s" % (item.get('title'), ext)
response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
response['Content-Type'] = content_type
response.write(item.srt(layer, language, encoder=encoder))
@ -1206,7 +1205,7 @@ def atom_xml(request):
el.text = atom_link
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
if not request.user.is_anonymous():
if not request.user.is_anonymous:
level = request.user.profile.level
for item in models.Item.objects.filter(level__lte=level, rendered=True).order_by('-created')[:7]:
if add_updated:
@ -1232,7 +1231,7 @@ def atom_xml(request):
if item.get('director'):
el = ET.SubElement(entry, "author")
name = ET.SubElement(el, "name")
name.text = ox.decode_html(u', '.join(item.get('director')))
name.text = ox.decode_html(', '.join(item.get('director')))
elif item.user:
el = ET.SubElement(entry, "author")
name = ET.SubElement(el, "name")
@ -1283,7 +1282,7 @@ def atom_xml(request):
el = ET.SubElement(format, key)
el.text = unicode(value)
el = ET.SubElement(format, 'pixel_aspect_ratio')
el.text = u"1:1"
el.text = "1:1"
if has_capability(request.user, 'canDownloadVideo'):
if item.torrent:
@ -1386,7 +1385,7 @@ def sitemap_part_xml(request, part):
def item_json(request, id):
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
if not request.user.is_anonymous():
if not request.user.is_anonymous:
level = request.user.profile.level
qs = models.Item.objects.filter(public_id=id, level__lte=level)
if qs.count() == 0:
@ -1399,7 +1398,7 @@ def item_json(request, id):
def item_xml(request, id):
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
if not request.user.is_anonymous():
if not request.user.is_anonymous:
level = request.user.profile.level
qs = models.Item.objects.filter(public_id=id, level__lte=level)
if qs.count() == 0:
@ -1439,7 +1438,7 @@ def item(request, id):
view = None
template = 'index.html'
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
if not request.user.is_anonymous():
if not request.user.is_anonymous:
level = request.user.profile.level
qs = models.Item.objects.filter(public_id=id, level__lte=level)
if qs.count() == 0:
@ -1484,7 +1483,7 @@ def item(request, id):
else:
title = key['title'] if key else k.capitalize()
if isinstance(value, list):
value = value = u', '.join([unicode(v) for v in value])
value = value = ', '.join([unicode(v) for v in value])
elif key and key.get('type') == 'float':
value = '%0.3f' % value
elif key and key.get('type') == 'time':
@ -1493,7 +1492,7 @@ def item(request, id):
clips = []
clip = {'in': 0, 'annotations': []}
# logged in users should have javascript. not adding annotations makes load faster
if not settings.USE_IMDB and request.user.is_anonymous():
if not settings.USE_IMDB and request.user.is_anonymous:
for a in item.annotations.exclude(
layer='subtitles'
).exclude(
@ -1513,13 +1512,13 @@ def item(request, id):
head_title = item.get('title', '')
title = item.get('title', '')
if item.get('director'):
head_title += u' (%s)' % u', '.join(item.get('director', []))
head_title += ' (%s)' % ', '.join(item.get('director', []))
if item.get('year'):
head_title += u' %s' % item.get('year')
title += u' (%s)' % item.get('year')
head_title += ' %s' % item.get('year')
title += ' (%s)' % item.get('year')
if view:
head_title += u' %s' % view
head_title += u' %s' % settings.SITENAME
head_title += ' %s' % view
head_title += ' %s' % settings.SITENAME
head_title = ox.decode_html(head_title)
title = ox.decode_html(title)
ctx = {

View file

@ -124,7 +124,7 @@ class ListManager(Manager):
if conditions:
qs = qs.filter(conditions)
if user.is_anonymous():
if user.is_anonymous:
qs = qs.filter(Q(status='public') | Q(status='featured'))
else:
qs = qs.filter(Q(status='public') | Q(status='featured') | Q(user=user))

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -10,7 +9,6 @@ from django.db import models
from django.db.models import Max
from django.contrib.auth import get_user_model
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from oxdjango.fields import JSONField
import ox
@ -28,7 +26,6 @@ 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:
@ -36,7 +33,7 @@ class List(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, related_name='lists')
user = models.ForeignKey(User, related_name='lists', on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, blank=True, related_name='lists')
name = models.CharField(max_length=255)
status = models.CharField(max_length=20, default='private')
@ -50,7 +47,7 @@ class List(models.Model):
view = models.TextField(default=get_listview)
sort = JSONField(default=get_listsort, editable=False)
poster_frames = JSONField(default=[], editable=False)
poster_frames = JSONField(default=list, editable=False)
#is through table still required?
items = models.ManyToManyField('item.Item', related_name='lists',
@ -110,13 +107,13 @@ class List(models.Model):
return self.get_id()
def get_id(self):
return u'%s:%s' % (self.user.username, self.name)
return '%s:%s' % (self.user.username, self.name)
def accessible(self, user):
return self.user == user or self.status in ('public', 'featured')
def editable(self, user):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
if self.user == user or \
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
@ -244,7 +241,7 @@ class List(models.Model):
elif key == 'subscribers':
response[key] = self.subscribed_users.all().count()
elif key == 'subscribed':
if user and not user.is_anonymous():
if user and not user.is_anonymous:
response[key] = self.subscribed_users.filter(id=user.id).exists()
else:
response[key] = getattr(self, {
@ -314,29 +311,27 @@ 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)
list = models.ForeignKey(List)
list = models.ForeignKey(List, on_delete=models.CASCADE)
index = models.IntegerField(default=0)
item = models.ForeignKey('item.Item')
item = models.ForeignKey('item.Item', on_delete=models.CASCADE)
def __str__(self):
return u'%s in %s' % (self.item, self.list)
return '%s in %s' % (self.item, self.list)
@python_2_unicode_compatible
class Position(models.Model):
class Meta:
unique_together = ("user", "list", "section")
list = models.ForeignKey(List, related_name='position')
user = models.ForeignKey(User)
list = models.ForeignKey(List, related_name='position', on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
section = models.CharField(max_length=255)
position = models.IntegerField(default=0)
def __str__(self):
return u'%s/%s/%s' % (self.section, self.position, self.list)
return '%s/%s/%s' % (self.section, self.position, self.list)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import re
@ -75,7 +74,7 @@ def findLists(request, data):
query = parse_query(data, request.user)
#order
is_section_request = query['sort'] == [{u'operator': u'+', u'key': u'position'}]
is_section_request = query['sort'] == [{'operator': '+', 'key': 'position'}]
def is_featured_condition(x):
return x['key'] == 'status' and \
x['value'] == 'featured' and \
@ -87,7 +86,7 @@ def findLists(request, data):
if is_section_request:
qs = query['qs']
if not is_featured and not request.user.is_anonymous():
if not is_featured and not request.user.is_anonymous:
qs = qs.filter(position__in=models.Position.objects.filter(user=request.user))
qs = qs.order_by('position__position')
else:

View file

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db import models
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible
import ox
@ -12,11 +10,10 @@ from . import managers
User = get_user_model()
@python_2_unicode_compatible
class Log(models.Model):
created = models.DateTimeField(auto_now_add=True, db_index=True)
modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, default=None, blank=True, null=True)
user = models.ForeignKey(User, default=None, blank=True, null=True, on_delete=models.CASCADE)
url = models.CharField(max_length=1000, default='')
line = models.IntegerField(default=0)
text = models.TextField(blank=True)
@ -24,7 +21,7 @@ class Log(models.Model):
objects = managers.LogManager()
def __str__(self):
return u"%s" % self.id
return "%s" % self.id
def json(self, keys=None):
j = {

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from datetime import timedelta, datetime

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import logging
import sys
@ -34,7 +33,7 @@ class ErrorHandler(logging.Handler):
request = record.request
request_repr = repr(request)
if request.user.is_authenticated():
if request.user.is_authenticated:
user = request.user
url = request.META.get('PATH_INFO', '')
except:

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import ox
from ox.utils import json
@ -25,7 +24,7 @@ def logError(request, data):
returns {}
see: findErrorLogs, removeErrorLogs
'''
if request.user.is_authenticated():
if request.user.is_authenticated:
user = request.user
else:
user = None

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
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()
@ -20,7 +17,7 @@ class News(models.Model):
text = models.TextField()
def editable(self, user):
return user.is_authenticated() and user.profile.capability("canEditSitePages")
return user.is_authenticated and user.profile.capability("canEditSitePages")
def save(self, *args, **kwargs):
super(News, self).save(*args, **kwargs)
@ -42,5 +39,5 @@ class News(models.Model):
return j
def __str__(self):
return u"%s/%s" % (self.date, self.title)
return "%s/%s" % (self.date, self.title)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import ox
from ox.utils import json

View file

@ -111,10 +111,10 @@ class ApiActions(dict):
f = fc[len(fc)-1].cell_contents
if PY2:
info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:]
info = u'%s:%s' % (info, f.func_code.co_firstlineno)
info = '%s:%s' % (info, f.func_code.co_firstlineno)
else:
info = f.__code__.co_filename[len(settings.PROJECT_ROOT)+1:]
info = u'%s:%s' % (info, f.__code__.co_firstlineno)
info = '%s:%s' % (info, f.__code__.co_firstlineno)
return info, trim(inspect.getsource(f))
def register(self, method, action=None, cache=True, version=None):

View file

@ -1,13 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.conf.urls import url
from django.urls import path
from . import views
from . import actions
actions.autodiscover()
urlpatterns = [
url(r'^$', views.api),
urls = [
[
path(r'', views.api),
],
'api',
'api'
]

View file

@ -3,7 +3,7 @@ from __future__ import division, absolute_import
import json
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.conf import settings
from ..shortcuts import render_to_json_response, json_response, HttpErrorJson
@ -31,7 +31,7 @@ def api(request):
'settings': settings,
'sitename': settings.SITENAME
}
response = render_to_response('api.html', context)
response = render(request, 'api.html', context)
response['Access-Control-Allow-Origin'] = '*'
return response
if request.META.get('CONTENT_TYPE') == 'application/json':

View file

@ -12,7 +12,7 @@ def login_required_json(function=None):
"""
def _wrapped_view(request, *args, **kwargs):
if request.user.is_authenticated():
if request.user.is_authenticated:
return function(request, *args, **kwargs)
return render_to_json_response({'status': {'code': 401, 'text': 'login required'}})
return wraps(function)(_wrapped_view)
@ -24,7 +24,7 @@ def admin_required_json(function=None):
"""
def _wrapped_view(request, *args, **kwargs):
if request.user.is_authenticated() and request.user.profile.get_level() == 'admin':
if request.user.is_authenticated and request.user.profile.get_level() == 'admin':
return function(request, *args, **kwargs)
return render_to_json_response({'status': {'code': 403, 'text': 'permission denied'}})
return wraps(function)(_wrapped_view)

View file

@ -64,7 +64,7 @@ class DictField(models.TextField):
def dumps(cls, obj):
return json.dumps(obj, default=to_json, ensure_ascii=False)
def from_db_value(self, value, expression, connection, context):
def from_db_value(self, value, expression, connection, context=None):
if value is None:
return value
if isinstance(value, self._type):

View file

@ -1,14 +1,17 @@
# -*- coding: utf-8 -*-
from django.utils.deprecation import MiddlewareMixin
from .shortcuts import HttpErrorJson, render_to_json_response
class ExceptionMiddleware(object):
class ExceptionMiddleware(MiddlewareMixin):
def process_exception(self, request, exception):
if isinstance(exception, HttpErrorJson):
return render_to_json_response(exception.response)
return None
class ChromeFrameMiddleware(object):
class ChromeFrameMiddleware(MiddlewareMixin):
def process_response(self, request, response):
response['X-UA-Compatible'] = 'chrome=1'
return response

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import datetime
from django.utils import datetime_safe
from django.http import HttpResponse, Http404
@ -23,7 +22,7 @@ def _to_json(python_object):
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
if isinstance(python_object, datetime_safe.datetime):
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
raise TypeError('%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
def json_dump(data, fp, indent=4):
return json.dump(data, fp, indent=indent, default=_to_json, ensure_ascii=False)

View file

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
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
@ -24,10 +22,9 @@ def get_name_sort(name, sortname=None):
person.save()
sortname = unicodedata.normalize('NFKD', person.sortname)
else:
sortname = u''
sortname = ''
return sortname
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=200, unique=True)
sortname = models.CharField(max_length=200)

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from celery.task import task

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import ox
from ox.utils import json

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.contrib import admin

View file

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db import models, transaction
from django.contrib.auth import get_user_model
from django.utils.encoding import python_2_unicode_compatible
import ox
from oxdjango import fields
@ -15,7 +13,6 @@ from . import managers
User = get_user_model()
@python_2_unicode_compatible
class Place(models.Model):
'''
Places are named locations, they should have geographical information attached to them.
@ -24,7 +21,7 @@ class Place(models.Model):
modified = models.DateTimeField(auto_now=True)
defined = models.BooleanField(default=True)
user = models.ForeignKey(User, null=True, related_name='places')
user = models.ForeignKey(User, null=True, related_name='places', on_delete=models.CASCADE)
name = models.CharField(max_length=1024)
alternativeNames = fields.TupleField(default=())
@ -60,7 +57,7 @@ class Place(models.Model):
@classmethod
def get_or_create(model, name):
qs = model.objects.filter(name_find__contains=u'|%s|' % name.lower())
qs = model.objects.filter(name_find__contains='|%s|' % name.lower())
if qs.count() == 0:
instance = model(name=name)
instance.save()
@ -69,7 +66,7 @@ class Place(models.Model):
return instance
def editable(self, user):
if user and not user.is_anonymous() \
if user and not user.is_anonymous \
and (not self.user or \
self.user == user or \
user.profile.capability('canEditPlaces')):

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from celery.task import task

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db.models import Max, Min, Count
from django.conf import settings
@ -50,7 +49,7 @@ def addPlace(request, data):
n = 0
while _exists:
_exists = models.Place.objects.filter(defined=True,
name_find__contains=u'|%s|' % name.lower()).count() > 0
name_find__contains='|%s|' % name.lower()).count() > 0
if _exists:
name = 'Untitled [%s]' %n
n += 1
@ -61,7 +60,7 @@ def addPlace(request, data):
for n in names:
n = ox.decode_html(name)
if models.Place.objects.filter(defined=True,
name_find__contains=u'|%s|' % n.lower()).count() != 0:
name_find__contains='|%s|' % n.lower()).count() != 0:
exists = True
existing_names.append(n)
'''
@ -130,7 +129,7 @@ def editPlace(request, data):
for name in names + alternative_names:
name = ox.decode_html(name)
if models.Place.objects.filter(defined=True,
name_find__contains=u'|%s|' % name.lower()).exclude(id=place.id).count() != 0:
name_find__contains='|%s|' % name.lower()).exclude(id=place.id).count() != 0:
conflict = True
conflict_names.append(name)
'''

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from django.db.models import Q, Manager

View file

@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
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,7 +13,6 @@ 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")
@ -25,7 +22,7 @@ class Sequence(models.Model):
'color': 1
}
mode = models.IntegerField(choices=sorted(zip(MODE.values(), list(MODE)), key=lambda k: k[0]), default=0)
sort = models.ForeignKey(ItemSort, null=True, related_name='sequences')
sort = models.ForeignKey(ItemSort, null=True, related_name='sequences', on_delete=models.CASCADE)
hash = models.BigIntegerField(db_index=True, default=-9223372036854775808)
start = models.FloatField(default=-1)
@ -40,7 +37,7 @@ class Sequence(models.Model):
@property
def public_id(self):
return u"%s/%0.03f-%0.03f" % (self.sort.item.public_id, float(self.start), float(self.end))
return "%s/%0.03f-%0.03f" % (self.sort.item.public_id, float(self.start), float(self.end))
def __str__(self):
return self.public_id

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from six import string_types
from django.db import connection, transaction

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
from ox.utils import json
from oxdjango.shortcuts import render_to_json_response, json_response

View file

@ -96,7 +96,7 @@ TEMPLATES = [
},
]
MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',

Some files were not shown because too many files have changed in this diff Show more