def get(self, entity_key_string=None):
    if entity_key_string:
      entity_key = datastore.Key(entity_key_string)
      entity_key_name = entity_key.name()
      entity_key_id = entity_key.id()
      namespace = entity_key.namespace()
      kind = entity_key.kind()
      entities = [datastore.Get(entity_key)]
      parent_key = entity_key.parent()
      if parent_key:
        parent_key_string = _format_datastore_key(parent_key)
      else:
        parent_key_string = None
    else:
      entity_key = None
      entity_key_string = None
      entity_key_name = None
      entity_key_id = None
      namespace = self.request.get('namespace')
      kind = self.request.get('kind')
      entities, _ = _get_entities(kind,
                                  namespace,
                                  order=None,
                                  start=0,
                                  count=20)
      parent_key = None
      parent_key_string = None

      if not entities:
        self.redirect('/datastore?%s' % (
            urllib.urlencode(
                [('kind', kind),
                 ('message',
                  'Cannot create the kind "%s" in the "%s" namespace because '
                  'no template entity exists.' % (kind, namespace)),
                 ('namespace', namespace)])))
        return

    property_name_to_values = _property_name_to_values(entities)
    fields = []
    for property_name, values in sorted(property_name_to_values.iteritems()):
      data_type = DataType.get(values[0])
      field = data_type.input_field('%s|%s' % (data_type.name(), property_name),
                                    values[0] if entity_key else None,
                                    values,
                                    self.request.uri)
      fields.append((property_name, data_type.name(), field))

    self.response.write(self.render(
        'datastore_edit.html',
        {'fields': fields,
         'key': entity_key_string,
         'key_id': entity_key_id,
         'key_name': entity_key_name,
         'kind': kind,
         'namespace': namespace,
         'next': self.request.get('next', '/datastore'),
         'parent_key': parent_key,
         'parent_key_string': parent_key_string}))
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/tools/devappserver2/admin/datastore_viewer.py/DatastoreEditRequestHandler.get/original