def notes(recid): """Note page.""" """View for the record notes extracted from comments""" if not cfg['ANNOTATIONS_NOTES_ENABLED']: return redirect(url_for('comments.comments', recid=recid)) from invenio.modules.access.local_config import VIEWRESTRCOLL from invenio.modules.access.mailcookie import \ mail_cookie_create_authorize_action from invenio.modules.comments.api import check_user_can_view_comments auth_code, auth_msg = check_user_can_view_comments(current_user, recid) if auth_code and current_user.is_guest: cookie = mail_cookie_create_authorize_action( VIEWRESTRCOLL, {'collection': g.collection}) url_args = {'action': cookie, 'ln': g.ln, 'referer': request.referrer} flash(_("Authorization failure"), 'error') return redirect(url_for('webaccount.login', **url_args)) elif auth_code: flash(auth_msg, 'error') abort(401) from invenio.modules.annotations.api import get_annotations page = request.args.get('page', type=int) if cfg["ANNOTATIONS_PREVIEW_ENABLED"] and not request.is_xhr: # the notes will be requested again via AJAX notes = [] elif page is None or page == -1: notes = prepare_notes(get_annotations({"where.record": recid})) else: import re rgx = re.compile("^P\.([0-9]*?\,)*?" + str(page) + "(,|$|[_]\.*)") notes = prepare_notes( get_annotations({ "where.marker": rgx, "where.record": recid })) if request.is_xhr: template = 'annotations/notes_fragment.html' else: template = 'annotations/notes.html' flash( _('This is a summary of all the comments that includes only the \ existing annotations. The full discussion is available \ <a href="' + url_for('comments.comments', recid=recid) + '">here</a>.'), "info") from invenio.utils.washers import wash_html_id return render_template(template, notes=notes, option='notes', get_note_title=get_note_title, note_is_collapsed=note_is_collapsed, get_original_comment=get_original_comment, wash_html_id=wash_html_id)
def view(): return render_template('annotations/view.html', public_annotations=get_annotations( {"where": request.args.get("target"), "perm": {"public": True, "groups": []}}), private_annotations=get_annotations( {"where": request.args.get("target"), "who": current_user.get_id(), "perm": {"public": False, "groups": []}}))
def view(): """View page.""" return render_template('annotations/view.html', public_annotations=get_annotations( {"where": request.args.get("target"), "perm": {"public": True, "groups": []}}), private_annotations=get_annotations( {"where": request.args.get("target"), "who": current_user.get_id(), "perm": {"public": False, "groups": []}}))
def notes(recid): """Note page.""" """View for the record notes extracted from comments""" if not cfg['ANNOTATIONS_NOTES_ENABLED']: return redirect(url_for('comments.comments', recid=recid)) from invenio.modules.access.local_config import VIEWRESTRCOLL from invenio.modules.access.mailcookie import \ mail_cookie_create_authorize_action from invenio.modules.comments.api import check_user_can_view_comments auth_code, auth_msg = check_user_can_view_comments(current_user, recid) if auth_code and current_user.is_guest: cookie = mail_cookie_create_authorize_action(VIEWRESTRCOLL, { 'collection': g.collection}) url_args = {'action': cookie, 'ln': g.ln, 'referer': request.referrer} flash(_("Authorization failure"), 'error') return redirect(url_for('webaccount.login', **url_args)) elif auth_code: flash(auth_msg, 'error') abort(401) from invenio.modules.annotations.api import get_annotations page = request.args.get('page', type=int) if cfg["ANNOTATIONS_PREVIEW_ENABLED"] and not request.is_xhr: # the notes will be requested again via AJAX notes = [] elif page is None or page == -1: notes = prepare_notes(get_annotations({"where.record": recid})) else: import re rgx = re.compile("^P\.([0-9]*?\,)*?" + str(page) + "(,|$|[_]\.*)") notes = prepare_notes(get_annotations({"where.marker": rgx, "where.record": recid})) if request.is_xhr: template = 'annotations/notes_fragment.html' else: template = 'annotations/notes.html' flash(_('This is a summary of all the comments that includes only the \ existing annotations. The full discussion is available \ <a href="' + url_for('comments.comments', recid=recid) + '">here</a>.'), "info(html_safe)") from invenio.utils.washers import wash_html_id return render_template(template, notes=notes, option='notes', get_note_title=get_note_title, note_is_collapsed=note_is_collapsed, get_original_comment=get_original_comment, wash_html_id=wash_html_id)
def get(self): """GET method handler. Provides only minimal search query options and no JSON-LD export. Currently used only for IDentifying annotation objects. """ annos = get_annotations(request.args.to_dict()) return get_jsonld_multiple(annos, context={})
def get(self): """GET method handler. Provides only minimal search query options and no JSON-LD export. Currently used only for IDentifying annotation objects. Request parameters are sent to MongoDB as a search query, in dictionary form. """ annos = get_annotations(request.args.to_dict()) return get_jsonld_multiple(annos, context={})
def post(self): """POST method handler. Allows performing complex queries and exporting annotations in JSON-LD format. It accepts a JSON document as input, with the following structure (defaults as values): {"query": {} // Query to send to MongoDB, see // http://docs.mongodb.org/manual/tutorial/query-documents/ "ldexport: "full" // JSON-LD export format, can be: full, inline, // compacted, expanded, flattened, framed, // normalized. "context": "oaf" // JSON-LD context or name/ URL of one to use for // serialisation. Only "oaf" (Open Annotation) is // currently supported "new_context": {} // new context to use for compacted format, tree // tree structure for framed, options for normalised. Example requests: Get all annotation on record 1, full OA JSON-LD: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"where.record": 1}, "ldexport": "full"}' Get specific annotation, compacted JSON-LD with field substitution: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\ "ldexport": "compacted", \ "new_context":{"CUSTOM_BODY": "http://www.w3.org/ns/oa#hasBody"}}' Get specfic annotation, RDF triples in N-Quads format: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\ "new_context":{"format": "application/nquads"}, \ "ldexport": "normalized"}' """ rqj = request.json annos = get_annotations(rqj["query"]) if "ldexport" in rqj: try: return get_jsonld_multiple(annos, context=rqj.get("context", "oaf"), new_context=rqj.get("new_context", {}), format=rqj.get("ldexport", "full")) except: abort(400) return None
def post(self): """POST method handler. Allows performing complex queries and exporting annotations in JSON-LD format. It accepts a JSON document as input, with the following structure (defaults as values): {"query": {} // Query to send to MongoDB, see // http://docs.mongodb.org/manual/tutorial/query-documents/ "ldexport: "full" // JSON-LD export format, can be: full, inline, // compacted, expanded, flattened, framed, // normalized. "context": "oaf" // JSON-LD context or name/ URL of one to use for // serialisation. Only "oaf" (Open Annotation) is // currently supported "new_context": {} // new context to use for compacted format, tree // tree structure for framed, options for normalised. Example requests: Get all annotation on record 1, full OA JSON-LD: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"where.record": 1}, "ldexport": "full"}' Get specific annotation, compacted JSON-LD with field substitution: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\ "ldexport": "compacted", \ "new_context":{"CUSTOM_BODY": "http://www.w3.org/ns/oa#hasBody"}}' Get specfic annotation, RDF triples in N-Quads format: curl invenio/api/annotations/export/ \ -H "Content-Type: application/json" \ --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\ "new_context":{"format": "application/nquads"}, \ "ldexport": "normalized"}' """ rqj = request.json annos = get_annotations(rqj["query"]) if "ldexport" in rqj: try: return get_jsonld_multiple(annos, context=rqj.get("context", "oaf"), new_context=rqj.get( "new_context", {}), format=rqj.get("ldexport", "full")) except: abort(400) return None