示例#1
0
    def post(self):
        if not self.validate_user():
            return

        user_id = users.get_current_user().email()
        # Allow to take the role of another user
        if self.request.get('user', None) in access_control.get_all_users():
            user_id = self.request.get('user', None)

        if self.request.path == '/argunit/annotate/store':
            try:
                decodedRequest = urllib.unquote(self.request.body);
                # Ugyl bugfix, sometimes the client sends a trailing extra '='
                if (decodedRequest.endswith("=")):
                    decodedRequest = decodedRequest[0:-1]
                json_req = json.loads(decodedRequest)
                self.store_annotations(user_id, json_req)
                result = 0
            except Exception as e:
                log("Request: " + str(decodedRequest))
                log("Saving failed! Reason: %s" % str(e.message))
                result = 1
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({'message': str(result)}))
        elif self.request.path == '/argunit/annotate/nextdoc':
            json_req = json.loads(self.request.body)
            self.respond_with_next_document(user_id, json_req)
        elif self.request.path == '/argunit/annotate/previousdoc':
            json_req = json.loads(self.request.body)
            self.respond_with_previous_document(user_id, json_req)
示例#2
0
    def post(self):
        if not self.validate_user():
            return

        user_id = users.get_current_user().email()
        # Allow to take the role of another user
        if self.request.get('user', None) in access_control.get_all_users():
            user_id = self.request.get('user', None)

        if self.request.path == '/argunit/annotate/store':
            try:
                decodedRequest = urllib.unquote(self.request.body)
                # Ugyl bugfix, sometimes the client sends a trailing extra '='
                if (decodedRequest.endswith("=")):
                    decodedRequest = decodedRequest[0:-1]
                json_req = json.loads(decodedRequest)
                self.store_annotations(user_id, json_req)
                result = 0
            except Exception as e:
                log("Request: " + str(decodedRequest))
                log("Saving failed! Reason: %s" % str(e.message))
                result = 1
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({'message': str(result)}))
        elif self.request.path == '/argunit/annotate/nextdoc':
            json_req = json.loads(self.request.body)
            self.respond_with_next_document(user_id, json_req)
        elif self.request.path == '/argunit/annotate/previousdoc':
            json_req = json.loads(self.request.body)
            self.respond_with_previous_document(user_id, json_req)
示例#3
0
    def store_annotations(self, user_id, data):
        doc_filename = data['doc']
        doc = Document.all().filter("filename =", doc_filename).get()

        doc_annotation = DocumentAnnotation.all().filter(
            "user_id =", user_id).filter("document =", doc.filename).get()
        if not doc_annotation:
            doc_annotation = DocumentAnnotation(user_id=user_id,
                                                document=doc.filename)

        doc_annotation.approved = data["approved"]

        doc_annotation.concepts = [Text(item) for item in data["concepts"]]
        doc_annotation.relations = [Text(item) for item in data["relations"]]
        doc_annotation.arg_units = [Text(item) for item in data["arg_units"]]

        doc_annotation.notes = Text(data['notes'])

        log("Storing annotations " +
            ("[Approved]" if doc_annotation.approved else "") + " for " +
            str(doc.filename) + ": " + str(doc_annotation.arg_units) +
            " - notes: " +
            doc_annotation.notes.encode("utf-8").replace("\n", " NL "))

        db.get(doc_annotation.put())
示例#4
0
    def store_annotations(self, user_id, data):
        doc_filename = data['doc']
        doc = Document.all().filter("filename =", doc_filename).get()

        doc_annotation = DocumentAnnotation.all().filter("user_id =", user_id).filter("document =",
                                                                                      doc.filename).get()
        if not doc_annotation:
            doc_annotation = DocumentAnnotation(user_id=user_id, document=doc.filename)

        doc_annotation.approved = data["approved"]

        doc_annotation.concepts = [Text(item) for item in data["concepts"]]
        doc_annotation.relations = [Text(item) for item in data["relations"]]
        doc_annotation.arg_units = [Text(item) for item in data["arg_units"]]

        doc_annotation.notes = Text(data['notes'])

        log("Storing annotations " + (
        "[Approved]" if doc_annotation.approved else "") + " for " + str(doc.filename) + ": " + str(
            doc_annotation.arg_units) + " - notes: " + doc_annotation.notes.encode("utf-8").replace(
            "\n", " NL "))

        db.get(doc_annotation.put())