示例#1
0
文件: license.py 项目: doigoid/cc.api
    def POST(self, selector):

        try:
            assert selector != 'software'
            if selector == 'publicdomain':
                lclass = cc.license.selectors.choose('zero')
            else:
                lclass = cc.license.selectors.choose(selector)
        except:
            return api_exceptions.invalidclass()

        if not web.input().get('answers'):
            return api_exceptions.missingparam('answers')

        try:
            answers_xml = web.input().get('answers')
            if selector == 'publicdomain':
                answers_xml = answers_xml.replace(
                    '<license-publicdomain>',
                    '<license-zero>').replace(
                    '</license-publicdomain>',
                    '</license-zero>')
            
            # parse the answers argument into an xml tree
            answers = ET.parse(StringIO(answers_xml))
            
        except ET.XMLSyntaxError, e:
            return api_exceptions.invalidanswer()
示例#2
0
    def POST(self, selector):

        lclass = None
        if selector != 'software':
            if selector == 'publicdomain':
                selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        if not lclass:
            return api_exceptions.invalidclass()

        answers_xml = web.input().get('answers')
        if not answers_xml:
            return api_exceptions.missingparam('answers')

        try:
            if selector == 'zero':
                answers_xml = answers_xml.replace(
                    '<license-publicdomain>',
                    '<license-zero>').replace('</license-publicdomain>',
                                              '</license-zero>')

            # parse the answers argument into an xml tree
            answers = ET.parse(StringIO(answers_xml))

        except ET.XMLSyntaxError, e:
            return api_exceptions.invalidanswer()
示例#3
0
文件: license.py 项目: cloe4u/cc.api
    def GET(self, selector):

        lclass = None
        if selector != 'software':
            if selector == 'publicdomain': 
                selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        if not lclass:
            return api_exceptions.invalidclass()

        locale = web.input().get('locale', 'en')
        lang = "{http://www.w3.org/XML/1998/namespace}lang"
        
        root = ET.Element('licenseclass', {'id':selector})
        label = ET.SubElement(root, 'label', {lang:locale})
        label.text = lclass.title(locale)
        
        for question in lclass.questions():

            field = ET.SubElement(root, 'field',  {'id':question.id})

            label = ET.SubElement(field, 'label', {lang:locale})
            label.text = question.label(locale)

            desc = ET.SubElement(field, 'description', {lang:locale})
            desc.text = question.description(locale)
            
            ET.SubElement(field, 'type').text = 'enum'

            for a_label, a_id, a_desc in question.answers():
                
                enum = ET.SubElement(field, 'enum',  {'id':a_id})
                label = ET.SubElement(enum, 'label', {lang:locale})
                label.text = a_label

                if a_desc:
                    ET.SubElement(enum,
                                  'description',
                                  {lang:locale}).text = a_desc
                    

        return root
示例#4
0
文件: license.py 项目: doigoid/cc.api
    def GET(self, selector):
        
        args = web.input()
        locale = str(args.get('locale'))
        if locale not in cc.license.locales():
            locale = 'en'
        
        try:
            assert selector != 'software'
            if selector == 'publicdomain': selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        except:
            return api_exceptions.invalidclass()

        answers = support.build_answers_xml(lclass, args)
        
        try:
            support.validate_answers(lclass, answers)
        except AssertionError, e:
            return api_exceptions.invalidanswer()
示例#5
0
    def GET(self, selector):

        lclass = None
        if selector != 'software':
            if selector == 'publicdomain':
                selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        if not lclass:
            return api_exceptions.invalidclass()

        locale = web.input().get('locale', 'en')
        lang = "{http://www.w3.org/XML/1998/namespace}lang"

        root = ET.Element('licenseclass', {'id': selector})
        label = ET.SubElement(root, 'label', {lang: locale})
        label.text = lclass.title(locale)

        for question in lclass.questions():

            field = ET.SubElement(root, 'field', {'id': question.id})

            label = ET.SubElement(field, 'label', {lang: locale})
            label.text = question.label(locale)

            desc = ET.SubElement(field, 'description', {lang: locale})
            desc.text = question.description(locale)

            ET.SubElement(field, 'type').text = 'enum'

            for a_label, a_id, a_desc in question.answers():

                enum = ET.SubElement(field, 'enum', {'id': a_id})
                label = ET.SubElement(enum, 'label', {lang: locale})
                label.text = a_label

                if a_desc:
                    ET.SubElement(enum, 'description', {
                        lang: locale
                    }).text = a_desc

        return root
示例#6
0
    def GET(self, selector):

        args = web.input()
        locale = str(args.get('locale'))
        if locale not in cc.license.locales():
            locale = 'en'

        lclass = None
        if selector != 'software':
            if selector == 'publicdomain':
                selector = 'zero'
            lclass = cc.license.selectors.choose(selector)
        if not lclass:
            return api_exceptions.invalidclass()

        answers = support.build_answers_xml(lclass, args)

        try:
            support.validate_answers(lclass, answers)
        except AssertionError, e:
            return api_exceptions.invalidanswer()