コード例 #1
0
ファイル: gameraXML.py プロジェクト: lexpar/Rodan
    def add_uuids_and_sort_glyphs(self):
        """Gives ids to all of the glyphs in the XML file."""
        xml = Glyph.xml_from_file(self.file_path)

        glyphs = xml.xpath("//glyphs")[0]
        glyphs[:] = sorted(glyphs, key=lambda glyph: Glyph.name_from_xml(glyph))

        for glyph in glyphs:
            if 'uuid' not in glyph.keys():
                glyph.set('uuid', Glyph.make_uuid())

        self.write_xml_to_file(xml)
コード例 #2
0
ファイル: gameraXML.py プロジェクト: agpar/Rodan
    def add_uuids_and_sort_glyphs(self):
        """Gives ids to all of the glyphs in the XML file."""
        xml = Glyph.xml_from_file(self.file_path)

        glyphs = xml.xpath("//glyphs")[0]
        glyphs[:] = sorted(glyphs,
                           key=lambda glyph: Glyph.name_from_xml(glyph))

        for glyph in glyphs:
            if 'uuid' not in glyph.keys():
                glyph.set('uuid', Glyph.make_uuid())

        self.write_xml_to_file(xml)
コード例 #3
0
ファイル: gameraXML.py プロジェクト: agpar/Rodan
    def write_json_glyphs_to_xml(self, json_glyphs):
        """ Called when a PATCH is received.  Rewrite xml with new glyphs."""

        gamera_database = etree.XML(r'<gamera-database version="2.0" />')
        glyphs_element = etree.SubElement(gamera_database, "glyphs")

        for json_glyph in json_glyphs:
            glyph_element = Glyph.xml_from_json(json_glyph)
            glyphs_element.append(glyph_element)

        self.write_xml_to_file(gamera_database)
コード例 #4
0
ファイル: gameraXML.py プロジェクト: lexpar/Rodan
    def write_json_glyphs_to_xml(self, json_glyphs):
        """ Called when a PATCH is received.  Rewrite xml with new glyphs."""

        gamera_database = etree.XML(r'<gamera-database version="2.0" />')
        glyphs_element = etree.SubElement(gamera_database, "glyphs")

        for json_glyph in json_glyphs:
            glyph_element = Glyph.xml_from_json(json_glyph)
            glyphs_element.append(glyph_element)

        self.write_xml_to_file(gamera_database)
コード例 #5
0
    def patch(self, request, pk, *args, **kwargs):
        glyph_id = pk
        classifier_url = request.DATA.get('classifier_url')
        pageglyphs_url = request.DATA.get('pageglyphs_url')

        if classifier_url is None and pageglyphs_url is None:
            return Response({"message": "You must supply a url for a classifier or pageglyphs model that contains the glyph."}, status=status.HTTP_400_BAD_REQUEST)
        else:
            if classifier_url is not None:
                classifier_pk = get_uuid_from_url(classifier_url)
                classifier = Classifier.objects.get(pk=classifier_pk)
                xml_file = classifier.file_path
                g = Glyph.update(request.DATA, xml_file, glyph_id)

            if pageglyphs_url is not None:
                pageglyphs_pk = get_uuid_from_url(pageglyphs_url)
                pageglyphs = PageGlyphs.objects.get(pk=pageglyphs_pk)
                xml_file = pageglyphs.file_path
                g = Glyph.update(request.DATA, xml_file, glyph_id)

            return JsonResponse(g.__dict__)
コード例 #6
0
    def post(self, request, *args, **kwargs):
        print "Glyph Post!"
        classifier_url = request.DATA.get('classifier_url')

        if classifier_url is None:
            return Response({"message": "You must supply a url for a classifier to which the glyph should be added."}, status=status.HTTP_400_BAD_REQUEST)
        else:
            classifier_pk = get_uuid_from_url(classifier_url)
            classifier = Classifier.objects.get(pk=classifier_pk)
            xml_file = classifier.file_path
            json_glyph = request.DATA.get('glyph')
            g = Glyph.create(json_glyph, xml_file)

        return JsonResponse(g.__dict__)
コード例 #7
0
    def get(self, request, pk, *args, **kwargs):
        print "Glyph Get!"
        glyph_id = pk
        classifier_url = request.DATA.get('classifier_url')
        pageglyphs_url = request.DATA.get('pageglyphs_url')

        if classifier_url is not None:
            classifier_pk = get_uuid_from_url(classifier_url)
            gameraXML = Classifier.objects.get(pk=classifier_pk)
        elif pageglyphs_url is not None:
            pageglyphs_pk = get_uuid_from_url(pageglyphs_url)
            gameraXML = PageGlyphs.objects.get(pk=pageglyphs_pk)
        else:
            return Response({"message": "You must supply a url for a classifier or pageglyphs model that contains the glyph."}, status=status.HTTP_400_BAD_REQUEST)

        xml_file = gameraXML.file_path
        g = Glyph.from_file_with_id(xml_file, glyph_id)

        return JsonResponse(g.__dict__)  # Also try the glyph serializer.  (Try using super... although that wouldn't quite do it)
コード例 #8
0
ファイル: gameraXML.py プロジェクト: agpar/Rodan
 def glyphs(self):
     xml = Glyph.xml_from_file(self.file_path)
     return [Glyph(g).__dict__ for g in xml.xpath("//glyph")]
コード例 #9
0
ファイル: gameraXML.py プロジェクト: lexpar/Rodan
 def glyphs(self):
     xml = Glyph.xml_from_file(self.file_path)
     return [Glyph(g).__dict__ for g in xml.xpath("//glyph")]