towards supporting python 2 and 3

- use absolute_imports
- make use of six.moves
- use exec instead of execfile
- use list(dict) instead if dict.keys()
This commit is contained in:
j 2016-08-23 12:27:06 +02:00
commit 1468ddbecb
89 changed files with 400 additions and 265 deletions

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, print_function, absolute_import
from django.db.models import Q, Manager
@ -7,8 +9,6 @@ from item.utils import decode_id
from oxdjango.managers import get_operator
from oxdjango.query import QuerySet
import models
keymap = {
'in': 'start',
'out': 'end'
@ -29,6 +29,7 @@ def parseCondition(condition, user):
operator: "!="
}
'''
from . import models
k = condition.get('key', default_key)
k = keymap.get(k, k)
if not k:

View file

@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, with_statement
from __future__ import division, print_function, absolute_import
from django.db import models
import managers
from item.models import ItemSort
from . import managers
def parse_hash(value):
return int(value, 16) - 9223372036854775808
@ -22,7 +23,7 @@ class Sequence(models.Model):
'shape': 0,
'color': 1
}
mode = models.IntegerField(choices=sorted(zip(MODE.values(), MODE.keys()), key=lambda k: k[0]), default=0)
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')
hash = models.BigIntegerField(db_index=True, default=-9223372036854775808)

View file

@ -1,14 +1,17 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, print_function, absolute_import
from six import string_types
from django.db import connection, transaction
from celery.task import task
import models
import item.models
import extract
from . import extract
@task(ignore_results=True, queue='encoding')
def get_sequences(public_id):
from . import models
i = item.models.Item.objects.get(public_id=public_id)
models.Sequence.objects.filter(sort=i.sort).delete()
position = 0
@ -29,7 +32,7 @@ def get_sequences(public_id):
sequence['duration'] = sequence['end'] - sequence['start']
if not keys:
keys = ', '.join(['"%s"'%k for k in sequence.keys()])
v = ', '.join([isinstance(v, basestring) and "'%s'"%v or str(v)
v = ', '.join([isinstance(v, string_types) and "'%s'"%v or str(v)
for v in sequence.values()])
values.append('(%s)'%v)
if values:

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
from __future__ import division, print_function, absolute_import
from ox.utils import json
from oxdjango.shortcuts import render_to_json_response, json_response
@ -11,7 +11,7 @@ from item.models import Item
from item import utils
from changelog.models import add_changelog
import models
from . import models
def parse_query(data, user):