Updated delete methods, file title update added
This commit is contained in:
parent
8b8bb8a5ce
commit
f34b82309b
@ -38,12 +38,11 @@ def updateDimensionName(id, new_name, user_id):
|
|||||||
result = {"message": "Dimension name changed successfully", "statusCode": 200}
|
result = {"message": "Dimension name changed successfully", "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def deleteDimensions(ids, user_id):
|
def deleteDimensions(dimension_id, user_id):
|
||||||
user = User.objects.get(pk = user_id)
|
user = User.objects.get(pk = user_id)
|
||||||
for id in ids:
|
dimension = Dimension.objects.get(pk = dimension_id, user_id = user)
|
||||||
dimension = Dimension.objects.get(pk = id, user_id = user)
|
dimension.delete()
|
||||||
dimension.delete()
|
result = {"message": "Dimension removed successfully", "statusCode": 200}
|
||||||
result = {"message": "Dimensions removed successfully", "statusCode": 200}
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def addDimensionToFile(id, file_id, user_id):
|
def addDimensionToFile(id, file_id, user_id):
|
||||||
@ -67,11 +66,10 @@ def getDimensionsFromFile(file_id, user_id):
|
|||||||
result = {"data": dimensions, "statusCode": 200}
|
result = {"data": dimensions, "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def removeDimensionsFromFile(file_id, dimension_ids, user_id):
|
def removeDimensionsFromFile(file_id, dimension_id, user_id):
|
||||||
user = User.objects.get(pk = user_id)
|
user = User.objects.get(pk = user_id)
|
||||||
file = Document.objects.get(pk = file_id, user_id = user)
|
file = Document.objects.get(pk = file_id, user_id = user)
|
||||||
for id in dimension_ids:
|
dimension = DimensionToFiles.objects.get(file_id = file, dimension_id = dimension_id).delete()
|
||||||
dimension = DimensionToFiles.objects.get(file_id = file, dimension_id = id).delete()
|
|
||||||
result = {"message": "Dimensions successfuly removed from specified file", "statusCode": 200}
|
result = {"message": "Dimensions successfuly removed from specified file", "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -94,12 +92,11 @@ def addNewCategories(id, categories, user_id):
|
|||||||
result = {"message": "Categories added successfully", "statusCode": 200}
|
result = {"message": "Categories added successfully", "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def deleteCategories(id, categories, user_id):
|
def deleteCategories(dimension_id, category_id, user_id):
|
||||||
user = User.objects.get(pk = user_id)
|
user = User.objects.get(pk = user_id)
|
||||||
dimension = Dimension.objects.get(pk = id, user_id = user)
|
dimension = Dimension.objects.get(pk = dimension_id, user_id = user)
|
||||||
for category_id in categories:
|
cat = Category.objects.get(pk = category_id, dimension_id = dimension)
|
||||||
cat = Category.objects.get(pk = category_id, dimension_id = dimension)
|
cat.delete()
|
||||||
cat.delete()
|
|
||||||
result = {"message": "Categories have been successfuly removed", "statusCode": 200}
|
result = {"message": "Categories have been successfuly removed", "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -46,3 +46,10 @@ def listDiscussionsFromFile(id, user_id):
|
|||||||
out['discussions'] = discussions_
|
out['discussions'] = discussions_
|
||||||
result = {"data": out, "statusCode": 200}
|
result = {"data": out, "statusCode": 200}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def updateFileTitle(file_id, title, user_id):
|
||||||
|
file = Document.objects.get(pk = file_id, user_id = user_id)
|
||||||
|
file.title = title
|
||||||
|
file.save()
|
||||||
|
result = {"result": "Title updated successfully", "statusCode": 200}
|
||||||
|
return result
|
||||||
|
@ -15,7 +15,7 @@ from prototype.filehandler.xmlParser import parseData
|
|||||||
from prototype.filehandler.functions import addToDatabase, listDiscussionsFromFile, listParagraphsFromDiscussion, createLabels, listPostsFromDiscussion, updateLabelsByParagraphId
|
from prototype.filehandler.functions import addToDatabase, listDiscussionsFromFile, listParagraphsFromDiscussion, createLabels, listPostsFromDiscussion, updateLabelsByParagraphId
|
||||||
|
|
||||||
from prototype.filehandler.userModule import registerNewUser, loginUser, logoutUser, checkUserToken
|
from prototype.filehandler.userModule import registerNewUser, loginUser, logoutUser, checkUserToken
|
||||||
from prototype.filehandler.fileModule import addDataToDatabase, listDiscussionsFromFile
|
from prototype.filehandler.fileModule import addDataToDatabase, listDiscussionsFromFile, updateFileTitle
|
||||||
from prototype.filehandler.annotationModule import addNewDimension, getDimensionList, getCategoriesFromDimension, updateDimensionName, updateCategories, addNewCategories, deleteCategories, deleteDimensions, addDimensionToFile, getDimensionsFromFile, removeDimensionsFromFile, addLabelsToParagraphs, removeLabelsFromParagraphs
|
from prototype.filehandler.annotationModule import addNewDimension, getDimensionList, getCategoriesFromDimension, updateDimensionName, updateCategories, addNewCategories, deleteCategories, deleteDimensions, addDimensionToFile, getDimensionsFromFile, removeDimensionsFromFile, addLabelsToParagraphs, removeLabelsFromParagraphs
|
||||||
|
|
||||||
from prototype.filehandler.exceptions import InvalidForm, CouldNotParse, InvalidMethod, KnownError
|
from prototype.filehandler.exceptions import InvalidForm, CouldNotParse, InvalidMethod, KnownError
|
||||||
@ -162,6 +162,8 @@ def file(request):
|
|||||||
if data == False:
|
if data == False:
|
||||||
raise CouldNotParse
|
raise CouldNotParse
|
||||||
file_id = (form.save()).pk
|
file_id = (form.save()).pk
|
||||||
|
if request.POST["title"] is not None:
|
||||||
|
result = updateFileTitle(file_id, request.POST["title"], user_id)
|
||||||
result = addDataToDatabase(data, file_id)
|
result = addDataToDatabase(data, file_id)
|
||||||
if result["statusCode"] != 200:
|
if result["statusCode"] != 200:
|
||||||
raise KnownError
|
raise KnownError
|
||||||
@ -199,6 +201,17 @@ def file(request):
|
|||||||
return JsonResponse({"files": data}, safe=False, status=200)
|
return JsonResponse({"files": data}, safe=False, status=200)
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def fileTitle(request, file_id):
|
||||||
|
if request.method == 'PATCH':
|
||||||
|
result, user_id = checkUserToken(request)
|
||||||
|
if result["statusCode"] != 200:
|
||||||
|
print("niedobrze")
|
||||||
|
data = json.loads(request.body.decode("utf-8"))
|
||||||
|
if "title" in data:
|
||||||
|
result = updateFileTitle(file_id, data["title"], user_id)
|
||||||
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def dimension(request):
|
def dimension(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
@ -229,25 +242,27 @@ def dimension(request):
|
|||||||
result = updateCategories(data["id"], data["categories"], user_id)
|
result = updateCategories(data["id"], data["categories"], user_id)
|
||||||
if result["statusCode"] != 200:
|
if result["statusCode"] != 200:
|
||||||
print("niedobrze3")
|
print("niedobrze3")
|
||||||
|
if "new_categories" in data:
|
||||||
|
result = addNewCategories(data["id"], data["new_categories"], user_id)
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def getDeleteDimension(request, id = 0):
|
||||||
|
if request.method == 'GET':
|
||||||
|
result, user_id = checkUserToken(request)
|
||||||
|
if result["statusCode"] != 200:
|
||||||
|
print("niedobrze")
|
||||||
|
if id != 0:
|
||||||
|
result = getCategoriesFromDimension(id, user_id)
|
||||||
|
return JsonResponse(result, status = result["statusCode"], safe=False, json_dumps_params={'ensure_ascii': False})
|
||||||
|
|
||||||
if request.method == 'DELETE':
|
if request.method == 'DELETE':
|
||||||
result, user_id = checkUserToken(request)
|
result, user_id = checkUserToken(request)
|
||||||
if result["statusCode"] != 200:
|
if result["statusCode"] != 200:
|
||||||
print("niedobrze")
|
print("niedobrze")
|
||||||
data = json.loads(request.body.decode("utf-8"))
|
if id != 0:
|
||||||
if "id" in data:
|
result = deleteDimensions(id, user_id)
|
||||||
result = deleteDimensions(data["id"], user_id)
|
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
def getDimension(request, id):
|
|
||||||
if request.method == 'GET':
|
|
||||||
result, user_id = checkUserToken(request)
|
|
||||||
if result["statusCode"] != 200:
|
|
||||||
print("niedobrze")
|
|
||||||
result = getCategoriesFromDimension(id, user_id)
|
|
||||||
return JsonResponse(result, status = result["statusCode"], safe=False, json_dumps_params={'ensure_ascii': False})
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def dimensionToFile(request):
|
def dimensionToFile(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -259,15 +274,6 @@ def dimensionToFile(request):
|
|||||||
result = addDimensionToFile(data["dimension_id"], data["file_id"], user_id)
|
result = addDimensionToFile(data["dimension_id"], data["file_id"], user_id)
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
if request.method == 'DELETE':
|
|
||||||
result, user_id = checkUserToken(request)
|
|
||||||
if result["statusCode"] != 200:
|
|
||||||
print("niedobrze")
|
|
||||||
data = json.loads(request.body.decode("utf-8"))
|
|
||||||
if "dimension_ids" in data and "file_id" in data:
|
|
||||||
result = removeDimensionsFromFile(data["file_id"], data["dimension_ids"], user_id)
|
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
|
||||||
|
|
||||||
def dimensionsFromFile(request, id):
|
def dimensionsFromFile(request, id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
result, user_id = checkUserToken(request)
|
result, user_id = checkUserToken(request)
|
||||||
@ -275,7 +281,17 @@ def dimensionsFromFile(request, id):
|
|||||||
print("niedobrze")
|
print("niedobrze")
|
||||||
result = getDimensionsFromFile(id, user_id)
|
result = getDimensionsFromFile(id, user_id)
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def deleteDimensionsFromFile(request, file_id = 0, dimension_id = 0):
|
||||||
|
if request.method == 'DELETE':
|
||||||
|
result, user_id = checkUserToken(request)
|
||||||
|
if result["statusCode"] != 200:
|
||||||
|
print("niedobrze")
|
||||||
|
if file_id != 0 and dimension_id != 0:
|
||||||
|
result = removeDimensionsFromFile(file_id, dimension_id, user_id)
|
||||||
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def category(request):
|
def category(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -286,13 +302,14 @@ def category(request):
|
|||||||
result = addNewCategories(data["id"], data["categories"], user_id)
|
result = addNewCategories(data["id"], data["categories"], user_id)
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def deleteCategory(request, dimension_id = 0, category_id = 0):
|
||||||
if request.method == 'DELETE':
|
if request.method == 'DELETE':
|
||||||
result, user_id = checkUserToken(request)
|
result, user_id = checkUserToken(request)
|
||||||
if result["statusCode"] != 200:
|
if result["statusCode"] != 200:
|
||||||
print("niedobrze")
|
print("niedobrze")
|
||||||
data = json.loads(request.body.decode("utf-8"))
|
if dimension_id != 0 and category_id != 0 :
|
||||||
if "categories" in data and "id" in data:
|
result = deleteCategories(dimension_id, category_id, user_id)
|
||||||
result = deleteCategories(data["id"], data["categories"], user_id)
|
|
||||||
return JsonResponse(result, status = result["statusCode"])
|
return JsonResponse(result, status = result["statusCode"])
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -32,11 +32,14 @@ urlpatterns = [
|
|||||||
path('login/', views.login),
|
path('login/', views.login),
|
||||||
path('testToken/', views.testToken),
|
path('testToken/', views.testToken),
|
||||||
path('file/', views.file),
|
path('file/', views.file),
|
||||||
|
path('fileTitle/<int:file_id>', views.fileTitle),
|
||||||
path('dimension/', views.dimension),
|
path('dimension/', views.dimension),
|
||||||
path('dimension/<int:id>', views.getDimension),
|
path('dimension/<int:id>', views.getDeleteDimension),
|
||||||
path('file/dimension/', views.dimensionToFile),
|
path('file/dimension/', views.dimensionToFile),
|
||||||
path('file/dimension/<int:id>', views.dimensionsFromFile),
|
path('file/dimension/<int:id>', views.dimensionsFromFile),
|
||||||
|
path('file/dimension/<int:file_id>/<int:dimension_id>', views.deleteDimensionsFromFile),
|
||||||
path('category/', views.category),
|
path('category/', views.category),
|
||||||
|
path('category/<int:dimension_id>/<int:category_id>', views.deleteCategory),
|
||||||
path('label/', views.label)
|
path('label/', views.label)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user