add getAnnotation, fixes #2572
This commit is contained in:
parent
1ac959623e
commit
d6c10eb377
2 changed files with 29 additions and 1 deletions
|
@ -110,6 +110,10 @@ class Annotation(models.Model):
|
|||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def get(cls, id):
|
||||
return cls.objects.get(public_id=id)
|
||||
|
||||
def set_public_id(self):
|
||||
if self.id:
|
||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.conf import settings
|
|||
|
||||
from ox.utils import json
|
||||
from ox.django.decorators import login_required_json
|
||||
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response, HttpErrorJson
|
||||
|
||||
|
||||
from ox.django.api import actions
|
||||
|
@ -17,6 +17,14 @@ from item.models import Item
|
|||
import models
|
||||
from tasks import update_item, add_annotations
|
||||
|
||||
def get_annotation_or_404_json(id):
|
||||
try:
|
||||
return models.Annotation.get(id)
|
||||
except models.Annotation.DoesNotExist:
|
||||
response = {'status': {'code': 404,
|
||||
'text': 'Annotation not found'}}
|
||||
raise HttpErrorJson(response)
|
||||
|
||||
def parse_query(data, user):
|
||||
query = {}
|
||||
query['range'] = [0, 100]
|
||||
|
@ -108,6 +116,22 @@ def findAnnotations(request, data):
|
|||
return render_to_json_response(response)
|
||||
actions.register(findAnnotations)
|
||||
|
||||
def getAnnotation(request, data):
|
||||
'''
|
||||
takes {
|
||||
id: string,
|
||||
keys: [string]
|
||||
}
|
||||
returns {
|
||||
key: value
|
||||
}
|
||||
'''
|
||||
response = json_response({})
|
||||
data['keys'] = data.get('keys', [])
|
||||
annotation = get_annotation_or_404_json(data['id'])
|
||||
response['data'] = annotation.json(keys=data['keys'], user=request.user)
|
||||
return render_to_json_response(response)
|
||||
actions.register(getAnnotation)
|
||||
|
||||
@login_required_json
|
||||
def addAnnotation(request, data):
|
||||
|
|
Loading…
Reference in a new issue