Beispiel #1
0
def oparl_organization_layout(data, params):
  # default values
  data['id'] = "%s/oparl/organization/%s%s" % (app.config['api_url'], data['_id'], generate_postfix(params))
  data['type'] = 'https://schema.oparl.org/1.0/Organization'
  data['body'] = "%s/oparl/body/%s%s" % (app.config['api_url'], data['body'].id, generate_postfix(params))
  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['membership'] = generate_backref_list(db.get_membership(search_params={'organization': DBRef('organization', ObjectId(data['_id']))}), params)
  data['meeting'] = "%s/oparl/organization/%s/meeting%s" % (app.config['api_url'], data['_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
Beispiel #2
0
def oparl_membership_data(params):
  data = db.get_membership(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]['organization'] = generate_single_url(params=params, type='organization', id=data[0]['organization'].id)
    data[0]['person'] = generate_single_backref_url(params=params, get='get_person', type='person', reverse_type='membership', id=params['_id'])
    data[0]['@type'] = 'OParlMembership'
    data[0]['@id'] = data[0]['_id']
    return data[0]
  elif len(data) == 0:
    abort(404)
Beispiel #3
0
def oparl_memberships_data(params):
  return db.get_membership(membership_list=True,
                           add_prefix = "%s/oparl/membership/" % app.config['api_url'],
                           add_postfix=generate_postfix(params))
Beispiel #4
0
def oparl_organization_membership_data(params):
  data = db.get_membership(membership_list = True,
                           search_params = {'organization': DBRef('organization', ObjectId(params['organization_id']))},
                           add_prefix = "%s/oparl/membership/" % app.config['api_url'],
                           add_postfix = generate_postfix(params))
  return data
Beispiel #5
0
def oparl_membership_data(params):
  data = db.get_membership(search_params={'_id': ObjectId(params['_id'])})
  if len(data) == 1:
    return oparl_membership_layout(data[0], params)
  elif len(data) == 0:
    abort(404)
Beispiel #6
0
def oparl_membership_data(params):
  data = db.get_membership(search_params={'_id': ObjectId(params['_id'])})
  if len(data) == 1:
    return oparl_membership_layout(data[0], params)
  elif len(data) == 0:
    abort(404)