Compare commits
4 commits
723c4e3f42
...
af65750363
| Author | SHA1 | Date | |
|---|---|---|---|
| af65750363 | |||
| 5cfe392e22 | |||
| 79c5d948b5 | |||
| e4133ffa1d |
3 changed files with 17 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ from glob import glob
|
||||||
|
|
||||||
from celery.task import task
|
from celery.task import task
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
|
@ -248,6 +249,7 @@ def move_media(data, user):
|
||||||
if old_item and old_item.files.count() == 0 and i.files.count() == len(data['ids']):
|
if old_item and old_item.files.count() == 0 and i.files.count() == len(data['ids']):
|
||||||
for a in old_item.annotations.all().order_by('id'):
|
for a in old_item.annotations.all().order_by('id'):
|
||||||
a.item = i
|
a.item = i
|
||||||
|
with transaction.atomic():
|
||||||
a.set_public_id()
|
a.set_public_id()
|
||||||
Annotation.objects.filter(id=a.id).update(item=i, public_id=a.public_id)
|
Annotation.objects.filter(id=a.id).update(item=i, public_id=a.public_id)
|
||||||
old_item.clips.all().update(item=i, sort=i.sort)
|
old_item.clips.all().update(item=i, sort=i.sort)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
@ -18,10 +19,11 @@ def extract_text(pdf, page=None):
|
||||||
# split page from pdf and ocr
|
# split page from pdf and ocr
|
||||||
fd, page_pdf = tempfile.mkstemp('.pdf')
|
fd, page_pdf = tempfile.mkstemp('.pdf')
|
||||||
cmd = ['pdfseparate', '-f', page, '-l', page, pdf, page_pdf]
|
cmd = ['pdfseparate', '-f', page, '-l', page, pdf, page_pdf]
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
text = ocr_image(page_pdf)
|
text = ocr_image(page_pdf)
|
||||||
os.unlink(page_pdf)
|
os.unlink(page_pdf)
|
||||||
|
os.close(fd)
|
||||||
return text
|
return text
|
||||||
else:
|
else:
|
||||||
return ocr_image(pdf)
|
return ocr_image(pdf)
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,7 @@ class Item(models.Model):
|
||||||
|
|
||||||
for a in self.annotations.all().order_by('id'):
|
for a in self.annotations.all().order_by('id'):
|
||||||
a.item = other
|
a.item = other
|
||||||
|
with transaction.atomic():
|
||||||
a.set_public_id()
|
a.set_public_id()
|
||||||
Annotation.objects.filter(id=a.id).update(item=other, public_id=a.public_id)
|
Annotation.objects.filter(id=a.id).update(item=other, public_id=a.public_id)
|
||||||
try:
|
try:
|
||||||
|
|
@ -522,6 +523,7 @@ class Item(models.Model):
|
||||||
cmd, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'), close_fds=True)
|
cmd, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'), close_fds=True)
|
||||||
p.wait()
|
p.wait()
|
||||||
os.unlink(tmp_output_txt)
|
os.unlink(tmp_output_txt)
|
||||||
|
os.close(fd)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
@ -1909,7 +1911,6 @@ class AnnotationSequence(models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def nextid(cls, item):
|
def nextid(cls, item):
|
||||||
with transaction.atomic():
|
|
||||||
s, created = cls.objects.get_or_create(item=item)
|
s, created = cls.objects.get_or_create(item=item)
|
||||||
if created:
|
if created:
|
||||||
nextid = s.value
|
nextid = s.value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue