You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
from django.http import HttpResponse
|
|
import json
|
|
from models import UserMark
|
|
from accounts.models import User
|
|
from models import Photo
|
|
from photoreport.models import Photoreport
|
|
|
|
def add_tag(request):
|
|
|
|
user = User.objects.get(id=request.GET['name_id'])
|
|
mark = UserMark(user=user, top=request.GET['top'], left=request.GET['left'],
|
|
width=request.GET['width'], height=request.GET['height'])
|
|
photo = Photo.objects.get(id=request.GET['image_id'])
|
|
mark.save()
|
|
photo.users.add(mark)
|
|
|
|
|
|
response = {"result":True,
|
|
"tag": {
|
|
"id": user.id,
|
|
"text": user.get_full_name(),
|
|
"left": mark.left,
|
|
"top": mark.top,
|
|
"width": mark.height,
|
|
"height": mark.height,
|
|
"url": "/123",
|
|
"isDeleteEnable": True
|
|
}
|
|
}
|
|
|
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
|
|
|
def existing_tags(request):
|
|
photo = Photo.objects.get(id=request.GET['image-id'])
|
|
|
|
tags = [{'id': mark.id, 'text': mark.user.get_full_name(),
|
|
'left': mark.left, 'top': mark.top, 'width': mark.width,
|
|
'height': mark.height, 'url': '/123', 'isDeleteEnable': True} for mark in photo.users.all()]
|
|
|
|
response = {'Image': [
|
|
{
|
|
'id': photo.id,
|
|
'Tags': tags
|
|
}
|
|
],
|
|
"options":{
|
|
"tag":{
|
|
"flashAfterCreation": True
|
|
}
|
|
}
|
|
}
|
|
|
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
|
|
|
def delete_tag(request):
|
|
photo = Photo.objects.get(id=request.GET['image-id'])
|
|
mark = UserMark.objects.get(id=request.GET['tag-id'])
|
|
photo.users.remove(mark)
|
|
d = {"result":True,"message":"ooops"}
|
|
return HttpResponse(json.dumps(d), content_type='application/json')
|
|
|