Exemple #1
0
def services_to_json(sprojects):
    sitems = []
    for service_id in sprojects:
        sproject = get_db()['sprojects'].find_one({'_id': service_id})
        sitem = item_to_json(
            sproject,
            ['_id', 'context_type', 'status', 'provider', 'created_at'])
        service = get_db()['services'].find_one({'_id': sproject['service']})
        provider = get_db()['partners'].find_one({'_id': service['provider']})

        sitem['provider'] = item_to_json(provider, ['_id', 'name'])
        # sitem['service'] = item_to_json(service, ['_id', 'name'])
        sitem['service'] = item_to_json(service, ['_id', 'name'])
        sitems.append(sitem)

    return sitems
Exemple #2
0
 def _item_to_json(self, item):
     sitem = ItemRes._item_to_json(self, item)
     provider_id = sitem['provider']
     if provider_id:
         provider = get_db()['partners'].find_one(
             {'_id': ObjectId(provider_id)})
         sitem['provider'] = item_to_json(provider, ['_id', 'name'])
     return sitem
Exemple #3
0
def partner_to_json(item):
    partner_id = item.pop('partner_id', None)
    if partner_id:
        partner = get_db()['partners'].find_one({'_id': partner_id})
        item['partner'] = item_to_json(partner, ['_id', '_cls', 'name'])
    else:
        item['partner'] = None

    return item
 def _item_to_json(self, item):
     services = item.get('services')
     project = self._find_obj(item['_id'])
     sproject = get_db(_cfg.database__database_name)['sprojects'].find_one(
         {'project': ObjectId(item['_id'])})
     item['status'] = project.get_status()
     item['services'] = services_to_json(services)
     if 'runtime_params' in sproject['runtime_params']:
         item['runtime_params'] = sproject['runtime_params'][
             'runtime_params']
     else:
         item['runtime_params'] = sproject['runtime_params']
     return item_to_json(item, self.fields)
 def get(self, id):
     item = []
     limit = get_int(get_arg('limit'))
     skip = get_int(get_arg('skip'))
     _filter = self.get_status(id)
     result = super(SProjectStatusRes,
                    self)._get_items(skip * limit, limit, _filter)
     for sproject in result:
         sitems = []
         sitem = {}
         project = find_one_in_collection(
             'projects', {"services": {
                 "$in": [ObjectId(sproject['_id'])]
             }})
         data = item_to_json(project, [
             '_id', 'name', 'summary', 'description', 'client', 'created_at'
         ])
         data['sproject'] = str(sproject['_id'])
         data['status'] = sproject['status']
         service = find_one_in_collection('services',
                                          {'_id': sproject['service']})
         provider = find_one_in_collection('users',
                                           {'_id': service['provider']})
         client = find_one_in_collection(
             'users', {"_id": ObjectId(project['client'])})
         sitem['provider'] = item_to_json(provider, ['_id', 'user_name'])
         sitem['service'] = item_to_json(service, ['_id', 'name'])
         data['client'] = item_to_json(client, ['_id', 'user_name'])
         data['provider'] = str(sproject['provider'])
         sitems.append(sitem)
         data['services'] = sitems
         item.append(data)
     response = dict(count=count_collection(self.collection, _filter),
                     skip=skip,
                     limit=limit,
                     result=item)
     return dict(response=response, status=200)
Exemple #6
0
def sproject_to_json(sproject, context=False):
    project = get_db()['projects'].find_one({'_id': sproject['project']})
    sitem = item_to_json(sproject, ['_id', 'status', 'created_at'])
    service = get_db()['services'].find_one({'_id': sproject['service']})
    provider = get_db()['partners'].find_one({'_id': service['provider']})
    client = get_db()['partners'].find_one({'_id': project['client']})

    sitem['project'] = item_to_json(project, ['_id', 'name'])
    sitem['client'] = item_to_json(client, ['_id', 'name'])
    sitem['provider'] = item_to_json(provider, ['_id', 'name'])
    # sitem['service'] = item_to_json(service, ['_id', 'name'])
    sitem['service'] = item_to_json(service, ['_id', 'name'])

    if context:
        sitem.update(item_to_json(sproject, ['context_type', 'context']))

    return sitem
 def _item_to_json(self, item):
     project = self._find_obj(item['_id'])
     item['status'] = project.get_status()
     services = item.get('services')
     item['services'] = services_to_json(services)
     return item_to_json(item, self.fields)
Exemple #8
0
 def _item_to_json(self, item):
     item = partner_to_json(item)
     return item_to_json(item, self.fields)