示例#1
0
 def get_genre(self, tree):
     elem = tree.find('head/tobject/tobject.property')
     if elem is None:
         raise SkipValue()
     genre = elem.get('tobject.property.type')
     genre_map = superdesk.get_resource_service('vocabularies').find_one(req=None, _id='genre')
     if genre_map is not None:
         return [x for x in genre_map.get('items', []) if x['name'] == genre]
     else:
         raise SkipValue()
示例#2
0
 def get_genre(self, tree):
     elem = tree.find("head/tobject/tobject.property")
     if elem is None:
         raise SkipValue()
     genre = elem.get("tobject.property.type")
     genre_map = superdesk.get_resource_service("vocabularies").find_one(
         req=None, _id="genre")
     if genre_map is not None:
         return [
             x for x in genre_map.get("items", []) if x["name"] == genre
         ]
     else:
         raise SkipValue()
示例#3
0
 def get_headline(self, xml):
     if xml.find('body/body.head/hedline/hl1') is not None:
         return xml.find('body/body.head/hedline/hl1').text
     else:
         if xml.find('head/title') is not None:
             return xml.find('head/title').text
     raise SkipValue()
示例#4
0
 def get_version_creator(self, tree):
     elem = tree.find("head/meta[@name='aap-version-creator']")
     if elem is not None:
         query = {'username': re.compile('^{}$'.format(elem.get('content')), re.IGNORECASE)}
         user = superdesk.get_resource_service('users').find_one(req=None, **query)
         if user:
             return user.get('_id')
     raise SkipValue()
示例#5
0
 def get_original_creator(self, tree):
     elem = tree.find("head/meta[@name='aap-original-creator']")
     if elem is not None:
         query = {
             "username":
             re.compile("^{}$".format(elem.get("content")), re.IGNORECASE)
         }
         user = superdesk.get_resource_service("users").find_one(req=None,
                                                                 **query)
         if user is not None:
             return user.get("_id")
     raise SkipValue()
示例#6
0
 def get_task(self, tree):
     desk_name = tree.find('head/meta[@name="aap-desk"]')
     if desk_name is not None:
         desk = superdesk.get_resource_service('desks').find_one(req=None, name=desk_name.get('content'))
         if desk:
             task = {'desk': desk.get('_id')}
             stage_name = tree.find('head/meta[@name="aap-stage"]')
             if stage_name is not None:
                 lookup = {'$and': [{'name': stage_name.get('content')}, {'desk': str(desk.get('_id'))}]}
                 stages = superdesk.get_resource_service('stages').get(req=None, lookup=lookup)
                 if stages is not None and stages.count() == 1:
                     task['stage'] = stages[0].get('_id')
             return task
     raise SkipValue()
示例#7
0
 def get_task(self, tree):
     desk_name = tree.find('head/meta[@name="aap-desk"]')
     if desk_name is not None:
         desk = superdesk.get_resource_service("desks").find_one(
             req=None, name=desk_name.get("content"))
         if desk:
             task = {"desk": desk.get("_id")}
             stage_name = tree.find('head/meta[@name="aap-stage"]')
             if stage_name is not None:
                 lookup = {
                     "$and": [{
                         "name": stage_name.get("content")
                     }, {
                         "desk": str(desk.get("_id"))
                     }]
                 }
                 stages = superdesk.get_resource_service("stages").get(
                     req=None, lookup=lookup)
                 if stages is not None and stages.count() == 1:
                     task["stage"] = stages[0].get("_id")
             return task
     raise SkipValue()