forked from 0x2620/pandora
add option to add documents to all items in list
This commit is contained in:
parent
8be4b16e48
commit
3ff178ed83
2 changed files with 46 additions and 21 deletions
|
@ -12,6 +12,7 @@ from django.db.models import Sum
|
||||||
|
|
||||||
from item import utils
|
from item import utils
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
from itemlist.models import List
|
||||||
import models
|
import models
|
||||||
|
|
||||||
def get_document_or_404_json(id):
|
def get_document_or_404_json(id):
|
||||||
|
@ -23,6 +24,9 @@ def addDocument(request):
|
||||||
add document(s) to item
|
add document(s) to item
|
||||||
takes {
|
takes {
|
||||||
item: string
|
item: string
|
||||||
|
or:
|
||||||
|
list: string
|
||||||
|
|
||||||
id: string
|
id: string
|
||||||
or
|
or
|
||||||
ids: [string]
|
ids: [string]
|
||||||
|
@ -36,6 +40,7 @@ def addDocument(request):
|
||||||
ids = data['ids']
|
ids = data['ids']
|
||||||
else:
|
else:
|
||||||
ids = [data['id']]
|
ids = [data['id']]
|
||||||
|
if 'item' in data:
|
||||||
item = Item.objects.get(itemId=data['item'])
|
item = Item.objects.get(itemId=data['item'])
|
||||||
if item.editable(request.user):
|
if item.editable(request.user):
|
||||||
for id in ids:
|
for id in ids:
|
||||||
|
@ -43,6 +48,13 @@ def addDocument(request):
|
||||||
document.add(item)
|
document.add(item)
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
|
elif 'list' in data:
|
||||||
|
list = List.get(data['list'])
|
||||||
|
for item in list.get_items(request.user):
|
||||||
|
if item.editable(request.user):
|
||||||
|
for id in ids:
|
||||||
|
document = models.Document.get(id)
|
||||||
|
document.add(item)
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(addDocument, cache=False)
|
actions.register(addDocument, cache=False)
|
||||||
|
|
||||||
|
@ -258,6 +270,7 @@ def upload(request):
|
||||||
if 'id' in request.GET:
|
if 'id' in request.GET:
|
||||||
file = models.Document.get(request.GET['id'])
|
file = models.Document.get(request.GET['id'])
|
||||||
else:
|
else:
|
||||||
|
file = None
|
||||||
extension = request.POST['filename'].split('.')
|
extension = request.POST['filename'].split('.')
|
||||||
name = '.'.join(extension[:-1])
|
name = '.'.join(extension[:-1])
|
||||||
extension = extension[-1].lower()
|
extension = extension[-1].lower()
|
||||||
|
@ -279,6 +292,7 @@ def upload(request):
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
#init upload
|
#init upload
|
||||||
else:
|
else:
|
||||||
|
if not file:
|
||||||
created = False
|
created = False
|
||||||
num = 1
|
num = 1
|
||||||
_name = name
|
_name = name
|
||||||
|
@ -292,6 +306,11 @@ def upload(request):
|
||||||
file.extension = extension
|
file.extension = extension
|
||||||
file.uploading = True
|
file.uploading = True
|
||||||
file.save()
|
file.save()
|
||||||
|
else:
|
||||||
|
#replace existing file
|
||||||
|
file.file.delete()
|
||||||
|
file.uploading = True
|
||||||
|
file.save()
|
||||||
upload_url = request.build_absolute_uri('/api/upload/document?id=%s' % file.get_id())
|
upload_url = request.build_absolute_uri('/api/upload/document?id=%s' % file.get_id())
|
||||||
return render_to_json_response({
|
return render_to_json_response({
|
||||||
'uploadUrl': upload_url,
|
'uploadUrl': upload_url,
|
||||||
|
|
|
@ -17,7 +17,6 @@ from ox.django.fields import DictField, TupleField
|
||||||
from archive import extract
|
from archive import extract
|
||||||
import managers
|
import managers
|
||||||
|
|
||||||
|
|
||||||
class List(models.Model):
|
class List(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -59,6 +58,13 @@ class List(models.Model):
|
||||||
self.numberofitems = self.get_numberofitems(self.user)
|
self.numberofitems = self.get_numberofitems(self.user)
|
||||||
super(List, self).save(*args, **kwargs)
|
super(List, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get(cls, id):
|
||||||
|
id = id.split(':')
|
||||||
|
username = id[0]
|
||||||
|
listname = ":".join(id[1:])
|
||||||
|
return cls.objects.get(user__username=username, name=listname)
|
||||||
|
|
||||||
def get_items(self, user=None):
|
def get_items(self, user=None):
|
||||||
if self.query.get('static', False):
|
if self.query.get('static', False):
|
||||||
return self.items
|
return self.items
|
||||||
|
|
Loading…
Reference in a new issue