Beispiel #1
0
def do_search(terms, list_for_type, types=None, permission_type='read',
              permission_model=None, contact_id=None, extra_params=None,
              relevant_objects=None):
  indexer = get_indexer()
  with benchmark("Search"):
    results = indexer.search(
        terms, types=types, permission_type=permission_type,
        permission_model=permission_model, contact_id=contact_id,
        extra_params=extra_params
    )

  related_filter = _build_relevant_filter(types, relevant_objects)
  seen_results = {}

  for result in results:
    id = result.key
    model_type = result.type
    result_pair = (model_type, id)
    if result_pair not in seen_results and related_filter(result_pair):
      seen_results[result_pair] = True
      entries_list = list_for_type(model_type)
      entries_list.append({
          'id': id,
          'type': model_type,
          'href': url_for(model_type, id=id),
      })
Beispiel #2
0
def do_search(terms, list_for_type, types=None, permission_type='read',
              contact_id=None, extra_params=None,
              relevant_objects=None):
  indexer = get_indexer()
  with benchmark("Search"):
    results = indexer.search(
        terms, types=types, permission_type=permission_type,
        contact_id=contact_id,
        extra_params=extra_params
    )

  related_filter = _build_relevant_filter(types, relevant_objects)
  seen_results = {}

  for result in results:
    id = result.key
    model_type = result.type
    result_pair = (model_type, id)
    if result_pair not in seen_results and related_filter(result_pair):
      seen_results[result_pair] = True
      entries_list = list_for_type(model_type)
      entries_list.append({
          'id': id,
          'type': model_type,
          'href': url_for(model_type, id=id),
      })
Beispiel #3
0
 def generate_link_object_for_foreign_key(self, id, type, context_id=None):
     """Generate a link object for this object reference."""
     return {
         'id': id,
         'type': type,
         'href': url_for(type, id=id),
         'context_id': context_id
     }
Beispiel #4
0
def _render_stub_from_match(match, type_columns):
  type_ = match[type_columns['type']]
  id_ = match[type_columns['id']]
  return {
      'type': type_,
      'id': id_,
      'context_id': match[type_columns['context_id']],
      'href': url_for(type_, id=id_),
  }
Beispiel #5
0
def publish_base_properties(obj):
    ret = {}
    self_url = url_for(obj)
    if self_url:
        ret['selfLink'] = self_url
    view_url = view_url_for(obj)
    if view_url:
        ret['viewLink'] = view_url
    return ret
Beispiel #6
0
def publish_base_properties(obj):
    ret = {}
    self_url = url_for(obj)
    if self_url:
      ret['selfLink'] = self_url
    view_url = view_url_for(obj)
    if view_url:
      ret['viewLink'] = view_url
    return ret
Beispiel #7
0
def _render_stub_from_match(match, type_columns):
    type_ = match[type_columns['type']]
    id_ = match[type_columns['id']]
    return {
        'type': type_,
        'id': id_,
        'context_id': match[type_columns['context_id']],
        'href': url_for(type_, id=id_),
    }
Beispiel #8
0
def publish_base_properties(obj):
  """Return a dict with selfLink and viewLink for obj."""
  ret = {}
  self_url = url_for(obj)
  if self_url:
    ret['selfLink'] = self_url
  view_url = view_url_for(obj)
  if view_url:
    ret['viewLink'] = view_url
  return ret
Beispiel #9
0
def publish_base_properties(obj):
    """Return a dict with selfLink and viewLink for obj."""
    ret = {}
    self_url = url_for(obj)
    if self_url:
        ret['selfLink'] = self_url
    view_url = view_url_for(obj)
    if view_url:
        ret['viewLink'] = view_url
    return ret
Beispiel #10
0
def _stub(obj):
  """Returns stub of object"""
  data = {
      "viewLink": utils.view_url_for(obj),
      "selfLink": utils.url_for(obj),
      "id": obj.id,
      "type": obj.type,
  }
  if hasattr(obj, "title"):
    data.update({"title": obj.title})
  return data
Beispiel #11
0
def _stub(obj):
    """Returns stub of object"""
    data = {
        "viewLink": utils.view_url_for(obj),
        "selfLink": utils.url_for(obj),
        "id": obj.id,
        "type": obj.type,
    }
    if hasattr(obj, "title"):
        data.update({"title": obj.title})
    return data
Beispiel #12
0
def publish_stub(obj):
  publisher = get_json_builder(obj)
  if publisher:
    ret = {}
    self_url = url_for(obj)
    if self_url:
      ret['href'] = self_url
    ret['type'] = obj.__class__.__name__
    if hasattr(publisher, '_stub_attrs') and publisher._stub_attrs:
      ret.update(publisher.publish_stubs(obj))
    return ret
  # Otherwise, just return the value itself by default
  return obj
Beispiel #13
0
def publish_stub(obj, inclusions=(), inclusion_filter=None):
  """Generate a stub for obj."""
  publisher = get_json_builder(obj)
  if publisher:
    ret = {}
    self_url = url_for(obj)
    if self_url:
      ret['href'] = self_url
    ret['type'] = obj.__class__.__name__
    ret['context_id'] = obj.context_id
    if getattr(publisher, '_stub_attrs', []):
      ret.update(publisher.publish_stubs(obj, inclusions, inclusion_filter))
    return ret
  # Otherwise, just return the value itself by default
  return obj
Beispiel #14
0
 def generate_link_object_for(self, obj, inclusions, include):
   """Generate a link object for this object. If there are property paths
   to be included specified in the ``inclusions`` parameter, those properties
   will be added to the object representation. If the ``include`` parameter
   is ``True`` the entire object will be represented in the result.
   """
   if include:
     return publish(obj, inclusions)
   result = {'id': obj.id, 'type': type(obj).__name__, 'href': url_for(obj)}
   for path in inclusions:
     if type(path) is not str and type(path) is not unicode:
       attr_name, remaining_path = path[0], path[1:]
     else:
       attr_name, remaining_path = path, ()
     result[attr_name] = self.publish_attr(obj, attr_name, remaining_path)
   return result
Beispiel #15
0
 def generate_link_object_for(
         self, obj, inclusions, include, inclusion_filter):
   """Generate a link object for this object. If there are property paths
   to be included specified in the ``inclusions`` parameter, those properties
   will be added to the object representation. If the ``include`` parameter
   is ``True`` the entire object will be represented in the result.
   """
   if include and ((not inclusion_filter) or inclusion_filter(obj)):
     return publish(obj, inclusions, inclusion_filter)
   result = {
       'id': obj.id, 'type': type(obj).__name__, 'href': url_for(obj),
       'context_id': obj.context_id}
   for path in inclusions:
     if not isinstance(path, basestring):
       attr_name, remaining_path = path[0], path[1:]
     else:
       attr_name, remaining_path = path, ()
     result[attr_name] = self.publish_attr(
         obj, attr_name, remaining_path, include, inclusion_filter)
   return result
Beispiel #16
0
 def generate_link_object_for(
         self, obj, inclusions, include, inclusion_filter):
   """Generate a link object for this object. If there are property paths
   to be included specified in the ``inclusions`` parameter, those properties
   will be added to the object representation. If the ``include`` parameter
   is ``True`` the entire object will be represented in the result.
   """
   if include and ((not inclusion_filter) or inclusion_filter(obj)):
     return publish(obj, inclusions, inclusion_filter)
   result = {
       'id': obj.id, 'type': type(obj).__name__, 'href': url_for(obj),
       'context_id': obj.context_id}
   for path in inclusions:
     if not isinstance(path, basestring):
       attr_name, remaining_path = path[0], path[1:]
     else:
       attr_name, remaining_path = path, ()
     result[attr_name] = self.publish_attr(
         obj, attr_name, remaining_path, include, inclusion_filter)
   return result
Beispiel #17
0
def do_search(
    terms, list_for_type, types=None, permission_type='read',
    permission_model=None):
  indexer = get_indexer()
  results = indexer.search(
      terms, types=types, permission_type=permission_type,
      permission_model=permission_model)
  seen_results = {}

  for result in results:
    id = result.key
    model_type = result.type
    result_pair = (model_type, id)
    if result_pair not in seen_results:
      seen_results[result_pair] = True
      entries_list = list_for_type(model_type)
      entries_list.append({
        'id': id,
        'type': model_type,
        'href': url_for(model_type, id=id),
        })
Beispiel #18
0
 def generate_link_object_for_foreign_key(self, id, type):
   """Generate a link object for this object reference."""
   return {'id': id, 'type': type, 'href': url_for(type, id=id)}
Beispiel #19
0
def _get_object_subdict(obj):
    return {
        "id": obj.id,
        "href": utils.url_for(obj),
        "type": obj.type,
    }