Пример #1
0
def oparl_person_data(params):
  data = db.get_person(search_params={'_id': ObjectId(params['_id'])},
                       deref={'values': ['membership']})
  if len(data) == 1:
    return oparl_person_layout(data[0], params)
  elif len(data) == 0:
    abort(404)
Пример #2
0
def oparl_membership_layout(data, params):
  # default values
  data['id'] = "%s/oparl/membership/%s%s" % (app.config['api_url'], data['_id'], generate_postfix(params))
  data['type'] = 'https://schema.oparl.org/1.0/Membership'
  data['body'] = generate_single_url(params=params, type='body', id=data['body'].id)
  data['created'] = data['created'].strftime("%Y-%m-%dT%H:%M:%S+01:00")
  data['modified'] = data['modified'].strftime("%Y-%m-%dT%H:%M:%S+01:00")

  # additional transformations
  if 'startDate' in data:
    if isinstance(data['startDate'], datetime.datetime):
      data['startDate'] = data['startDate'].strftime("%Y-%m-%d")
  if 'endDate' in data:
    if isinstance(data['endDate'], datetime.datetime):
      data['endDate'] = data['endDate'].strftime("%Y-%m-%d")

  data['organization'] = "%s/oparl/organization/%s%s" % (app.config['api_url'], data['organization'].id, generate_postfix(params))
  data['person'] = "%s/oparl/person/%s%s" % (app.config['api_url'], db.get_person(search_params={'membership': DBRef('membership', ObjectId(data['_id']))})[0]['_id'], generate_postfix(params))

  if 'originalId' in data:
    data['PolitikBeiUns:originalId'] = data['originalId']
  if 'originalUrl' in data:
    data['PolitikBeiUns:originalUrl'] = data['originalUrl']

  # delete stuff
  del data['_id']
  if 'originalId' in data:
    del data['originalId']
  if 'originalUrl' in data:
    del data['originalUrl']
  if 'slug' in data:
    del data['slug']

  return data
Пример #3
0
def oparl_person_data(params):
  data = db.get_person(search_params={'_id': ObjectId(params['_id'])})
  if len(data) == 1:
    data[0]['body'] = generate_single_url(params=params, type='body', id=data[0]['body'].id)
    data[0]['membership'] = generate_sublist_url(params=params, main_type='person', sublist_type='membership')
    data[0]['@type'] = 'OParlPerson'
    data[0]['@id'] = data[0]['_id']
    return data[0]
  elif len(data) == 0:
    abort(404)
Пример #4
0
def oparl_body_person_data(params):
  search_params = oparl_generate_list_search_params(params)
  data = db.get_person(search_params = search_params,
                       limit=app.config['oparl_items_per_page'],
                       deref={'values': ['membership']})
  data = oparl_generate_list_items(params=params,
                                   search_params=search_params,
                                   result_count=db.get_person_count(search_params=search_params),
                                   data=data,
                                   type='person')
  for key_person, single_person in enumerate(data['data']):
    data['data'][key_person] = oparl_person_layout(data=single_person, params=params)
  return data
Пример #5
0
def oparl_body_person_data(params):
  search_params = oparl_generate_list_search_params(params)
  data = db.get_person(search_params = search_params,
                       limit=app.config['oparl_items_per_page'],
                       deref={'values': ['membership']})
  data = oparl_generate_list_items(params=params,
                                   search_params=search_params,
                                   result_count=db.get_person_count(search_params=search_params),
                                   data=data,
                                   type='person')
  for key_person, single_person in enumerate(data['items']):
    data['items'][key_person] = oparl_person_layout(data=single_person, params=params)
    memberships = []
    for single_membership in data['items'][key_person]['membership']:
      memberships.append(oparl_membership_layout(single_membership, params))
    data['items'][key_person]['membership'] = memberships
  return data
Пример #6
0
def oparl_person_membership_data(params):
  data = db.get_person(deref={'value': 'membership', 'list_select': '_id'},
                       search_params={'_id': ObjectId(params['person_id'])},
                       add_prefix = "%s/oparl/membership/" % app.config['api_url'],
                       add_postfix = generate_postfix(params))
  return data
Пример #7
0
def oparl_persons_data(params):
  return db.get_person(person_list=True,
                       add_prefix = "%s/oparl/person/" % app.config['api_url'],
                       add_postfix=generate_postfix(params))
Пример #8
0
def oparl_body_person_data(params):
  data = db.get_person(person_list = True,
                       search_params = {'body': DBRef('body', ObjectId(params['body_id']))},
                       add_prefix = "%s/oparl/person/" % app.config['api_url'],
                       add_postfix = generate_postfix(params))
  return data
Пример #9
0
def oparl_person_data(params):
  data = db.get_person(search_params={'_id': ObjectId(params['_id'])})
  if len(data) == 1:
    return oparl_person_layout(data[0], params)
  elif len(data) == 0:
    abort(404)