forked from 0x2620/pandora
run bulk update as task
This commit is contained in:
parent
2d8a3f24dc
commit
ca7741f92c
2 changed files with 24 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import ox
|
||||
from celery.task import task
|
||||
|
||||
@task(queue="encoding")
|
||||
|
@ -6,3 +6,20 @@ def extract_fulltext(id):
|
|||
from . import models
|
||||
d = models.Document.objects.get(id=id)
|
||||
d.update_fulltext()
|
||||
|
||||
|
||||
@task(queue='default')
|
||||
def builk_edit(data, username):
|
||||
from django.db import transaction
|
||||
from . import models
|
||||
from item.models import Item
|
||||
user = models.User.objects.get(username=username)
|
||||
item = 'item' in data and Item.objects.get(public_id=data['item']) or None
|
||||
documents = models.Document.objects.filter(pk__in=map(ox.fromAZ, data['id']))
|
||||
for document in documents:
|
||||
if document.editable(user, item):
|
||||
with transaction.atomic():
|
||||
document.refresh_from_db()
|
||||
document.edit(data, user, item)
|
||||
document.save()
|
||||
return {}
|
||||
|
|
|
@ -23,6 +23,7 @@ from archive.chunk import process_chunk
|
|||
from changelog.models import add_changelog
|
||||
|
||||
from . import models
|
||||
from . import tasks
|
||||
|
||||
def get_document_or_404_json(request, id):
|
||||
response = {'status': {'code': 404,
|
||||
|
@ -131,12 +132,12 @@ def editDocument(request, data):
|
|||
item = 'item' in data and Item.objects.get(public_id=data['item']) or None
|
||||
if data['id']:
|
||||
if isinstance(data['id'], list):
|
||||
documents = models.Document.objects.filter(pk__in=map(ox.fromAZ, data['id']))
|
||||
add_changelog(request, data)
|
||||
t = tasks.builk_edit.delay(data, request.user.username)
|
||||
response['data']['taskId'] = t.task_id
|
||||
else:
|
||||
documents = [models.Document.get(data['id'])]
|
||||
for document in documents:
|
||||
document = models.Document.get(data['id'])
|
||||
if document.editable(request.user, item):
|
||||
if document == documents[0]:
|
||||
add_changelog(request, data)
|
||||
document.edit(data, request.user, item)
|
||||
document.save()
|
||||
|
|
Loading…
Reference in a new issue