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.models import Item
|
||||
from itemlist.models import List
|
||||
import models
|
||||
|
||||
def get_document_or_404_json(id):
|
||||
|
@ -23,6 +24,9 @@ def addDocument(request):
|
|||
add document(s) to item
|
||||
takes {
|
||||
item: string
|
||||
or:
|
||||
list: string
|
||||
|
||||
id: string
|
||||
or
|
||||
ids: [string]
|
||||
|
@ -36,6 +40,7 @@ def addDocument(request):
|
|||
ids = data['ids']
|
||||
else:
|
||||
ids = [data['id']]
|
||||
if 'item' in data:
|
||||
item = Item.objects.get(itemId=data['item'])
|
||||
if item.editable(request.user):
|
||||
for id in ids:
|
||||
|
@ -43,6 +48,13 @@ def addDocument(request):
|
|||
document.add(item)
|
||||
else:
|
||||
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)
|
||||
actions.register(addDocument, cache=False)
|
||||
|
||||
|
@ -258,6 +270,7 @@ def upload(request):
|
|||
if 'id' in request.GET:
|
||||
file = models.Document.get(request.GET['id'])
|
||||
else:
|
||||
file = None
|
||||
extension = request.POST['filename'].split('.')
|
||||
name = '.'.join(extension[:-1])
|
||||
extension = extension[-1].lower()
|
||||
|
@ -279,6 +292,7 @@ def upload(request):
|
|||
return render_to_json_response(response)
|
||||
#init upload
|
||||
else:
|
||||
if not file:
|
||||
created = False
|
||||
num = 1
|
||||
_name = name
|
||||
|
@ -292,6 +306,11 @@ def upload(request):
|
|||
file.extension = extension
|
||||
file.uploading = True
|
||||
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())
|
||||
return render_to_json_response({
|
||||
'uploadUrl': upload_url,
|
||||
|
|
|
@ -17,7 +17,6 @@ from ox.django.fields import DictField, TupleField
|
|||
from archive import extract
|
||||
import managers
|
||||
|
||||
|
||||
class List(models.Model):
|
||||
|
||||
class Meta:
|
||||
|
@ -59,6 +58,13 @@ class List(models.Model):
|
|||
self.numberofitems = self.get_numberofitems(self.user)
|
||||
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):
|
||||
if self.query.get('static', False):
|
||||
return self.items
|
||||
|
|
Loading…
Reference in a new issue