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,11 +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
import os
import re
from glob import glob
from urllib import quote, unquote
from six import string_types
from six.moves.urllib.parse import quote
from django.db import models
from django.db.models import Max
from django.contrib.auth.models import User
@ -18,8 +20,8 @@ from item.models import Item
from archive.extract import resize_image
from archive.chunk import save_chunk
import managers
import utils
from . import managers
from . import utils
def get_path(f, x): return f.path(x)
@ -174,7 +176,7 @@ class Document(models.Model):
elif hasattr(self, _map.get(key, key)):
response[key] = getattr(self, _map.get(key,key)) or ''
if item:
if isinstance(item, basestring):
if isinstance(item, string_types):
item = Item.objects.get(public_id=item)
d = self.descriptions.filter(item=item)
if d.exists():
@ -228,7 +230,7 @@ class Document(models.Model):
elif self.extension in ('jpg', 'png', 'gif'):
if os.path.exists(src):
if size and page:
crop = map(int, page.split(','))
crop = list(map(int, page.split(',')))
if len(crop) == 4:
path = os.path.join(folder, '%s.jpg' % ','.join(map(str, crop)))
if not os.path.exists(path):

View file

@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
from __future__ import division, print_function, absolute_import
import os
from glob import glob
from six import string_types
import ox
from ox.utils import json
from oxdjango.api import actions
@ -20,7 +22,7 @@ from entity.models import Entity
from archive.chunk import process_chunk
from changelog.models import add_changelog
import models
from . import models
def get_document_or_404_json(id):
try:
@ -49,7 +51,7 @@ def addDocument(request, data):
else:
ids = [data['id']]
if 'item' in data:
if isinstance(data['item'], basestring):
if isinstance(data['item'], string_types):
item = Item.objects.get(public_id=data['item'])
if item.editable(request.user):
for id in ids:
@ -66,7 +68,7 @@ def addDocument(request, data):
document.add(item)
add_changelog(request, data, data['item'])
elif 'entity' in data:
if isinstance(data['entity'], basestring):
if isinstance(data['entity'], string_types):
entity = Entity.get(data['entity'])
if entity.editable(request.user):
for id in ids: