Python google.appengine.ext.db 模块,get() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用google.appengine.ext.db.get()

项目:Tinychat-Bot--Discontinued    作者:Tinychat    | 项目源码 | 文件源码
def getGAEObjects(context):
    """
    Returns a reference to the C{gae_objects} on the context. If it doesn't
    exist then it is created.

    @param context: The context to load the C{gae_objects} index from.
    @return: The C{gae_objects} index reference.
    @rtype: Instance of L{GAEReferenceCollection}
    @since: 0.4.1
    """
    ref_collection = context.get(XDB_CONTEXT_NAME, None)

    if ref_collection:
        return ref_collection

    ret = context[XDB_CONTEXT_NAME] = XDBReferenceCollection()

    return ret
项目:Tinychat-Bot--Discontinued    作者:Tinychat    | 项目源码 | 文件源码
def encode_xdb_key(key, encoder=None):
    """
    Convert the `db.Key` to it's entity and encode it.
    """
    gae_objects = getGAEObjects(encoder.context.extra)

    klass = db.class_for_kind(key.kind())

    try:
        referenced_object = gae_objects.get(klass, key)
    except KeyError:
        referenced_object = db.get(key)
        gae_objects.set(klass, key, referenced_object)

    if not referenced_object:
        encoder.writeElement(None)
    else:
        encoder.writeObject(referenced_object)
项目:Multi_User_Blog    作者:Nshmais    | 项目源码 | 文件源码
def get(self, post_id):
        """
            This renders home post page with content, comments and likes.
        """
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        comments = db.GqlQuery("select * from Comment where post_id = " +
                               post_id + " order by created desc")

        likes = db.GqlQuery("select * from Like where post_id="+post_id)

        if not post:
            self.error(404)
            return

        error = self.request.get('error')

        self.render("permalink.html", post=post, noOfLikes=likes.count(),
                    comments=comments, error=error)
项目:Multi_User_Blog    作者:Nshmais    | 项目源码 | 文件源码
def get(self, post_id):
        if self.user:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            # check if the post exist in the database
            if not post:
                # if post does not exist, redirect to login page
                return self.redirect('/login')

            if post.user_id == self.user.key().id():
                post.delete()

                # delete all the comments associated with that post
                comments = Comment.all()
                comments.filter("post_id", int(post_id))
                for comment in comments:
                    comment.delete()

                self.redirect("/?deleted_post_id="+post_id)
            else:
                self.redirect("/blog/" + post_id + "?error=You don't have " +
                              "access to delete this record.")
        else:
            self.redirect("/login?error=You need to be logged, in order" +
                          " to delete your post!!")
项目:Multi_User_Blog    作者:Nshmais    | 项目源码 | 文件源码
def get(self, post_id):
        if self.user:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            if not post:
                # if post does not exist, redirect to login page
                return self.redirect('/login')
            if post.user_id == self.user.key().id():
                self.render("editpost.html", subject=post.subject,
                            content=post.content)
            else:
                self.redirect("/blog/" + post_id + "?error=You don't have " +
                              "access to edit this record.")
        else:
            self.redirect("/login?error=You need to be logged, " +
                          "in order to edit your post!!")
项目:Multi_User_Blog    作者:Nshmais    | 项目源码 | 文件源码
def get(self, post_id, comment_id):
        if self.user:
            key = db.Key.from_path('Comment', int(comment_id),
                                   parent=blog_key())
            c = db.get(key)
            if not c:
                # if post does not exist, redirect to login page
                return self.redirect('/login')
            if c.user_id == self.user.key().id():
                c.delete()
                return self.redirect("/blog/"+post_id+"?deleted_comment_id=" +
                                     comment_id)
            else:
                return self.redirect("/blog/" + post_id +
                                     "?error=You don't have " +
                                     "access to delete this comment.")
        else:
            return self.redirect("/login?error=You need to be logged," +
                                 "in order to delete your comment!!")
项目:Multi_User_Blog    作者:Nshmais    | 项目源码 | 文件源码
def get(self, post_id, comment_id):
        if self.user:
            key = db.Key.from_path('Comment',
                                   int(comment_id),
                                   parent=blog_key())
            c = db.get(key)
            if not c:
                return self.redirect('/login')
            if c.user_id == self.user.key().id():
                return self.render("editcomment.html", comment=c.comment)
            else:
                return self.redirect("/blog/" + post_id +
                                     "?error=You don't have access" +
                                     "to edit this comment.")
        else:
            return self.redirect("/login?error=You need to be logged," +
                                 "in order to edit your post!!")
项目:udacity-multi-user-blog    作者:rrjoson    | 项目源码 | 文件源码
def get(self, post_id, post_user_id):
        if self.user and self.user.key().id() == int(post_user_id):
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            post.delete()

            self.redirect('/')

        elif not self.user:
            self.redirect('/login')

        else:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)

            comments = db.GqlQuery(
                "select * from Comment where ancestor is :1 order by created desc limit 10", key)

            error = "You don't have permission to delete this post"
            self.render("permalink.html", post=post, comments=comments, error=error)
项目:udacity-multi-user-blog    作者:rrjoson    | 项目源码 | 文件源码
def get(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if self.user and self.user.key().id() == post.user_id:
            self.write("You cannot dislike your own post")
        elif not self.user:
            self.redirect('/login')
        else:
            user_id = self.user.key().id()
            post_id = post.key().id()

            l = Like.all().filter('user_id =', user_id).filter('post_id =', post_id).get()

            if l:
                l.delete()
                post.likes -= 1
                post.put()

                self.redirect('/' + str(post.key().id()))
            else:
                self.redirect('/' + str(post.key().id()))
项目:ifttt-line    作者:MypaceEngine    | 项目源码 | 文件源码
def getUserByDashId(dashId):
    # id=memcache.get(key = "Dash-user-"+dashid)
    logging.debug('ENTER getUser_DashButton\n')
    found_lineId = None

    # get lineId from dashId
    try:
        q = UserData.all()
        q.filter('dashId = ', dashId)
        for p in q.run(limit=1):
            found_lineId = p.lineId
            logging.debug('  found: ' + str(p) + '\n')
    except:
        logging.error(u'dashId??lineId????????????????')

    return found_lineId
项目:Utmost_Bot    作者:jiachen247    | 项目源码 | 文件源码
def post(self):
        data = json.loads(self.request.body)
        logging.debug(self.request.body)

        if data.get('message'):
            logging.info('Processing incoming message')
            self.handle_message(data.get('message'))
        elif data.get('callback_query'):
            logging.info('Processing incoming callback query')
            self.handle_callback_query(data.get('callback_query'))
        # elif data.inline_query:
        #     logging.info('Processing incoming inline query')
        #     self.handle_inline_query(data.inline_query)
        #
        else:
            logging.info(LOG_TYPE_NON_MESSAGE)
            return
项目:Utmost_Bot    作者:jiachen247    | 项目源码 | 文件源码
def post(self):
        params = json.loads(self.request.body)
        msg_type = params.get('msg_type')
        data = params.get('data')
        uid = str(json.loads(data).get('chat_id'))
        user = get_user(uid)

        try:
            result = telegram_post(data, 4)
        except Exception as e:
            logging.warning(LOG_ERROR_SENDING.format(msg_type, uid, user.get_description(), str(e)))
            logging.debug(data)
            self.abort(502)

        response = json.loads(result.content)

        if handle_response(response, user, uid, msg_type) == False:
            logging.debug(data)
            self.abort(502)
项目:Utmost_Bot    作者:jiachen247    | 项目源码 | 文件源码
def get(self):
        logging.debug("Caching devos for today.")
        memcache.flush_all()

        status = "Status : "

        try:
            # cache only today and tmr
            for delta in range(0, 2):
                for version in range(V.get_size()):
                    logging.debug("how many times {}".format(version))
                    get_devo(delta=delta, version=V.get_version_letters(version))
        except Exception as e:
            status += "Cache Failed - " + str(e)

        else:
            status += "Cache Passed: "
        finally:
            send_message(CREATOR_ID, status)
            self.response.write("Success...")

        return
项目:FSND_Multi_User_Blog    作者:harrystaley    | 项目源码 | 文件源码
def post(self, login_id):
        auth_error = True
        if self.read_secure_cookie('usercookie'):
            auth_error = False
        else:
            auth_error = True
        username = self.read_secure_cookie('usercookie')
        if not self.user_exists(username):
            auth_error = False
        else:
            auth_error = True

        if not auth_error:
            comment_id = self.request.get('edit_comment_id')
            post_id = self.request.get('post_id')
            if self.read_secure_cookie('usercookie'):
                if comment_id and post_id:
                    self.redirect('/editcomment?comment_id=%s&post_id=%s' %
                                  (comment_id, post_id))
        else:
            self.redirect('/signup')
项目:FSND_Multi_User_Blog    作者:harrystaley    | 项目源码 | 文件源码
def get(self):
        """ handles the GET request for welcome.html """
        # if the usercookie exists render the welcome page
        # otherwise redirect to the signup page.
        if self.read_secure_cookie('usercookie'):
            # Gets the user id from the cookie
            user_id = self.read_secure_cookie('usercookie')
            # gets the key for the kind (table)
            key = db.Key.from_path('User',
                                   int(user_id),
                                   parent=user_key())
            # gets the user data based upon what is passed
            # from user_id into key
            user = db.get(key)
            # renders the welcome page passing in the user name
            self.render("welcome.html",
                        username=user.username)
        else:
            self.redirect('/signup')
项目:FSND_Multi_User_Blog    作者:harrystaley    | 项目源码 | 文件源码
def get(self):
        """ uses get request to get newpost.html """
        post_id = self.request.get('post_id')
        key = db.Key.from_path('Post',
                               int(post_id),
                               parent=blog_key())
        # gets the post data based upon what
        # is passed from post_id into key
        post = db.get(key)
        if self.read_secure_cookie('usercookie'):
            user_id = self.read_secure_cookie('usercookie')
            # If the current logged in user is not the post author
            # it redirects them back to the previous page
            if user_id == post.author_id:
                self.render("editpost.html",
                            subject=post.subject,
                            content=post.content,
                            post_id=post_id)
            else:
                referrer = self.request.headers.get('referer')
                if referrer:
                    return self.redirect(referrer)
                return self.redirect_to('/')
        else:
            self.redirect('/signup')
项目:FSND_Multi_User_Blog    作者:harrystaley    | 项目源码 | 文件源码
def post(self):
        """ Submits data to the server to delete the post """
        auth_error = True
        if self.read_secure_cookie('usercookie'):
            auth_error = False
        else:
            auth_error = True
        username = self.read_secure_cookie('usercookie')
        if not self.user_exists(username):
            auth_error = False
        else:
            auth_error = True

        if not auth_error:
            post_id = self.request.get('post_id')
            key = db.Key.from_path('Post',
                                   int(post_id),
                                   parent=blog_key())
            # gets the post data based upon what
            # is passed from post_id into key
            db.delete(key)
            self.render('/postdeleted.html')
        else:
            self.redirect('/signup')
项目:deprecated_thedap    作者:unitedvote    | 项目源码 | 文件源码
def post(self):
        data = json.loads(self.request.body)
        logging.info(data)  

        p = Proposal(
                     proposal_title=data["proposal_title"],
                     proposal_text=data["proposal_text"],
                     cost=float(data["cost"]),
                     dap=db.get(data["dap"]),
                     user=str(self.get_current_user().key())
                    )
        p.put()

        r = {"proposal_title":p.proposal_title,
             "proposal_text":p.proposal_text,
             "cost":p.cost,
             "timestamp":.p.created.strftime("%d/%m/%Y %H:%M:%S"),
             "user":p.user.key(),
             "dap":p.dap.key()
             })
        self.set_status(200)
        self.write(json.dumps(r))
项目:deprecated_thedap    作者:unitedvote    | 项目源码 | 文件源码
def get(self):
        data = json.loads(self.get_arguments)
        logging.info(data)

        user = self.from_email(data["email"])

        if user.check_password(data["password"]):
            #set secure cookie
            self.set_secure_cookie("user", str(user.key()))
            self.set_status(200)
            resp = {"success":True, "error":""}
        else:
            self.set_status(400)
            resp = {"success":False, "error":"Could not authenticate user"}            

        self.write(json.dumps(resp))
项目:dancedeets-monorepo    作者:mikelambert    | 项目源码 | 文件源码
def _drop_gracefully(self):
        """Drop worker task gracefully.

    Set current shard_state to failed. Controller logic will take care of
    other shards and the entire MR.
    """
        shard_id = self.request.headers[util._MR_SHARD_ID_TASK_HEADER]
        mr_id = self.request.headers[util._MR_ID_TASK_HEADER]
        shard_state, mr_state = db.get([model.ShardState.get_key_by_shard_id(shard_id), model.MapreduceState.get_key_by_job_id(mr_id)])

        if shard_state and shard_state.active:
            logging.error('Would normally mark this shard for failure...and kill the entire mapreduce!')
            logging.error('But we ignore that and let this shard continue to run (and fail) instead.')
            # shard_state.set_for_failure()
            # config = util.create_datastore_write_config(mr_state.mapreduce_spec)
            # shard_state.put(config=config)
            raise Exception('Worker cannot run due to attempt to drop gracefully.')
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def key_for_entity(cls, entity_or_key):
    """Return the metadata key for the entity group containing entity_or_key.

    Use this key to get() the __entity_group__ metadata entity for the
    entity group containing entity_or_key.

    Args:
      entity_or_key: a key or entity whose __entity_group__ key you want.

    Returns:
      The __entity_group__ key for the entity group containing entity_or_key.
    """
    if isinstance(entity_or_key, db.Model):
      key = entity_or_key.key()
    else:
      key = entity_or_key
    while key.parent():
      key = key.parent()
    return db.Key.from_path(cls.KIND_NAME, cls.ID, parent=key)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get_entity_group_version(entity_or_key):
  """Return the version of the entity group containing entity_or_key.

  Args:
    entity_or_key: a key or entity whose version you want.

  Returns: The version of the entity group containing entity_or_key. This
    version is guaranteed to increase on every change to the entity
    group. The version may increase even in the absence of user-visible
    changes to the entity group. May return None if the entity group was
    never written to.

    On non-HR datatores, this function returns None.
  """

  eg = db.get(EntityGroup.key_for_entity(entity_or_key))
  if eg:
    return eg.version
  else:
    return None
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    requested_backup_ids = handler.request.get_all('backup_id')
    backups = []
    gs_warning = False
    if requested_backup_ids:
      for backup in db.get(requested_backup_ids):
        if backup:
          backups.append(backup)
          gs_warning |= backup.filesystem == FILES_API_GS_FILESYSTEM
    template_params = {
        'form_target': DoBackupDeleteHandler.SUFFIX,
        'datastore_admin_home': utils.GenerateHomeUrl(handler.request),
        'backups': backups,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'gs_warning': gs_warning,
        'run_as_a_service': handler.request.get('run_as_a_service'),
    }
    utils.RenderToResponse(handler, 'confirm_delete_backup.html',
                           template_params)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def Render(cls, handler):
    """Rendering method that can be called by main.py.

    Args:
      handler: the webapp.RequestHandler invoking the method
    """
    requested_backup_ids = handler.request.get_all('backup_id')
    backups = []
    if requested_backup_ids:
      for backup in db.get(requested_backup_ids):
        if backup:
          backups.append(backup)
    template_params = {
        'form_target': DoBackupAbortHandler.SUFFIX,
        'datastore_admin_home': utils.GenerateHomeUrl(handler.request),
        'backups': backups,
        'xsrf_token': utils.CreateXsrfToken(XSRF_ACTION),
        'run_as_a_service': handler.request.get('run_as_a_service'),
    }
    utils.RenderToResponse(handler, 'confirm_abort_backup.html',
                           template_params)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get(self):
    """Handler for get requests to datastore_admin backup operations.

    Status of executed jobs is displayed.
    """
    jobs = self.request.get_all('job')
    remote_job = self.request.get('remote_job')
    tasks = self.request.get_all('task')
    error = self.request.get('error', '')
    xsrf_error = self.request.get('xsrf_error', '')
    template_params = {
        'job_list': jobs,
        'remote_job': remote_job,
        'task_list': tasks,
        'mapreduce_detail': self.MAPREDUCE_DETAIL,
        'error': error,
        'xsrf_error': xsrf_error,
        'datastore_admin_home': utils.GenerateHomeUrl(self.request),
    }
    utils.RenderToResponse(self, self._get_html_page, template_params)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def post(self):
    """Handler for post requests to datastore_admin/backup.do.

    Redirects to the get handler after processing the request.
    """
    token = self.request.get('xsrf_token')

    if not utils.ValidateXsrfToken(token, XSRF_ACTION):
      parameters = [('xsrf_error', '1')]
    else:
      try:
        parameters = self._ProcessPostRequest()


      except Exception, e:
        error = self._HandleException(e)
        parameters = [('error', error)]

    self.SendRedirect(self._get_post_html_page, parameters)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def _run_map_jobs_deferred(backup_name, job_operation_key, backup_info_key,
                           kinds, job_name, backup_handler, input_reader,
                           output_writer, mapper_params, mapreduce_params,
                           queue):
  backup_info = BackupInformation.get(backup_info_key)
  if backup_info:
    try:
      _run_map_jobs(job_operation_key, backup_info_key, kinds, job_name,
                    backup_handler, input_reader, output_writer, mapper_params,
                    mapreduce_params, queue)
    except BaseException:
      logging.exception('Failed to start a datastore backup job[s] for "%s".',
                        backup_name)
      delete_backup_info(backup_info)
  else:
    logging.info('Missing backup info, can not start backup jobs for "%s"',
                 backup_name)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def post(self):
    """Handler for post requests to datastore_admin/backup_delete.do.

    Deletes are executed and user is redirected to the base-path handler.
    """
    backup_ids = self.request.get_all('backup_id')
    token = self.request.get('xsrf_token')
    params = ()
    if backup_ids and utils.ValidateXsrfToken(token, XSRF_ACTION):
      try:
        for backup_info in db.get(backup_ids):
          if backup_info:
            delete_backup_info(backup_info)
      except Exception, e:
        logging.exception('Failed to delete datastore backup.')
        params = [('error', e.message)]

    self.SendRedirect(params=params)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def post(self):
    """Handler for post requests to datastore_admin/backup_abort.do.

    Abort is executed and user is redirected to the base-path handler.
    """
    backup_ids = self.request.get_all('backup_id')
    token = self.request.get('xsrf_token')
    params = ()
    if backup_ids and utils.ValidateXsrfToken(token, XSRF_ACTION):
      try:
        for backup_info in db.get(backup_ids):
          if backup_info:
            operation = backup_info.parent()
            if operation.parent_key():
              job_id = str(operation.parent_key())
              datastore_admin_service = services_client.DatastoreAdminClient()
              datastore_admin_service.abort_backup(job_id)
            else:
              utils.AbortAdminOperation(operation.key())
            delete_backup_info(backup_info)
      except Exception, e:
        logging.exception('Failed to abort pending datastore backup.')
        params = [('error', e.message)]

    self.SendRedirect(params=params)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def _perform_backup_complete(
    operation, job_id, kind, backup_info_pk, gcs_path_prefix, filenames, queue):
  backup_info = BackupInformation.get(backup_info_pk)
  if backup_info:
    if job_id in backup_info.active_jobs:
      backup_info.active_jobs.remove(job_id)
      backup_info.completed_jobs = list(
          set(backup_info.completed_jobs + [job_id]))


    filenames = [GCSUtil.add_gs_prefix_if_missing(name) for name in filenames]
    kind_backup_files = backup_info.get_kind_backup_files([kind])[0]
    if kind_backup_files:
      kind_backup_files.files = list(set(kind_backup_files.files + filenames))
    else:
      kind_backup_files = backup_info.create_kind_backup_files(kind, filenames)
    db.put((backup_info, kind_backup_files), force_writes=True)
    if operation.status == utils.DatastoreAdminOperation.STATUS_COMPLETED:
      deferred.defer(finalize_backup_info, backup_info.key(),
                     gcs_path_prefix,
                     _url=config.DEFERRED_PATH,
                     _queue=queue,
                     _transactional=True)
  else:
    logging.warn('BackupInfo was not found for %s', backup_info_pk)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def load(cls, backup_id, kind_name, shard_id=None):
    """Retrieve SchemaAggregationResult from the Datastore.

    Args:
      backup_id: Required BackupInformation Key.
      kind_name: Required kind name as string.
      shard_id: Optional shard id as string.

    Returns:
      SchemaAggregationResult iterator or an entity if shard_id not None.
    """
    parent = cls._get_parent_key(backup_id, kind_name)
    if shard_id:
      key = datastore_types.Key.from_path(cls.kind(), shard_id, parent=parent)
      return SchemaAggregationResult.get(key)
    else:
      return db.Query(cls).ancestor(parent).run()
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def get_queue_names(app_id=None, max_rows=100):
  """Returns a list with all non-special queue names for app_id."""
  rpc = apiproxy_stub_map.UserRPC('taskqueue')
  request = taskqueue_service_pb.TaskQueueFetchQueuesRequest()
  response = taskqueue_service_pb.TaskQueueFetchQueuesResponse()
  if app_id:
    request.set_app_id(app_id)
  request.set_max_rows(max_rows)
  queues = ['default']
  try:
    rpc.make_call('FetchQueues', request, response)
    rpc.check_success()

    for queue in response.queue_list():
      if (queue.mode() == taskqueue_service_pb.TaskQueueMode.PUSH and
          not queue.queue_name().startswith('__') and
          queue.queue_name() != 'default'):
        queues.append(queue.queue_name())
  except Exception:
    logging.exception('Failed to get queue names.')
  return queues
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def head_object(self, filename):
    """Get file stat with a HEAD.

    Args:
      filename: gcs filename of form '/bucket/filename'

    Returns:
      A GCSFileStat object containing file stat. None if file doesn't exist.
    """
    common.validate_file_path(filename)
    blobkey = self._filename_to_blobkey(filename)
    key = blobstore_stub.BlobstoreServiceStub.ToDatastoreBlobKey(blobkey)
    info = db.get(key)
    if info and info.finalized:
      metadata = common.get_metadata(info.options)
      filestat = common.GCSFileStat(
          filename=info.filename,
          st_size=info.size,
          etag=info.etag,
          st_ctime=calendar.timegm(info.creation.utctimetuple()),
          content_type=info.content_type,
          metadata=metadata)
      return filestat
    return None
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def delete_object(self, filename):
    """Delete file with a DELETE.

    Args:
      filename: gcs filename of form '/bucket/filename'

    Returns:
      True if file is deleted. False if file doesn't exist.
    """
    common.validate_file_path(filename)
    blobkey = self._filename_to_blobkey(filename)
    key = blobstore_stub.BlobstoreServiceStub.ToDatastoreBlobKey(blobkey)
    gcsfileinfo = db.get(key)
    if not gcsfileinfo:
      return False

    blobstore_stub.BlobstoreServiceStub.DeleteBlob(blobkey, self.blob_storage)
    return True
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def _schedule_slice(cls,
                      shard_state,
                      tstate,
                      queue_name=None,
                      eta=None,
                      countdown=None):
    """Schedule slice scanning by adding it to the task queue.

    Args:
      shard_state: An instance of ShardState.
      tstate: An instance of TransientShardState.
      queue_name: Optional queue to run on; uses the current queue of
        execution or the default queue if unspecified.
      eta: Absolute time when the MR should execute. May not be specified
        if 'countdown' is also supplied. This may be timezone-aware or
        timezone-naive.
      countdown: Time in seconds into the future that this MR should execute.
        Defaults to zero.
    """
    queue_name = queue_name or os.environ.get("HTTP_X_APPENGINE_QUEUENAME",
                                              "default")
    task = cls._state_to_task(tstate, shard_state, eta, countdown)
    cls._add_task(task, tstate.mapreduce_spec, queue_name)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def _drop_gracefully(self):
    """See parent."""
    mr_id = self.request.get("mapreduce_id")
    logging.error("Failed to kick off job %s", mr_id)

    state = model.MapreduceState.get_by_job_id(mr_id)
    if not self._check_mr_state(state, mr_id):
      return


    config = util.create_datastore_write_config(state.mapreduce_spec)
    model.MapreduceControl.abort(mr_id, config=config)


    state.active = False
    state.result_status = model.MapreduceState.RESULT_FAILED
    ControllerCallbackHandler._finalize_job(state.mapreduce_spec, state)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def decode_payload(cls, request):
    """Decode task payload.

    HugeTask controls its own payload entirely including urlencoding.
    It doesn't depend on any particular web framework.

    Args:
      request: a webapp Request instance.

    Returns:
      A dict of str to str. The same as the params argument to __init__.

    Raises:
      DeprecationWarning: When task payload constructed from an older
        incompatible version of mapreduce.
    """


    if request.headers.get(cls.PAYLOAD_VERSION_HEADER) != cls.PAYLOAD_VERSION:
      raise DeprecationWarning(
          "Task is generated by an older incompatible version of mapreduce. "
          "Please kill this job manually")
    return cls._decode_payload(request.body)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def find_all_by_mapreduce_state(cls, mapreduce_state):
    """Find all shard states for given mapreduce.

    Args:
      mapreduce_state: MapreduceState instance

    Yields:
      shard states sorted by shard id.
    """
    keys = cls.calculate_keys_by_mapreduce_state(mapreduce_state)
    i = 0
    while i < len(keys):
      @db.non_transactional
      def no_tx_get(i):
        return db.get(keys[i:i+cls._MAX_STATES_IN_MEMORY])


      states = no_tx_get(i)
      for s in states:
        i += 1
        if s is not None:
          yield s
项目:cloud-memory    作者:onejgordon    | 项目源码 | 文件源码
def get(self):
        e = None
        create_user = self.request.get_range('user') == 1
        pw = self.request.get('pw')

        if pw == INSTALL_PW:

            empty_db = Organization.query().get() is None

            if empty_db:

                if create_user:
                    email = self.request.get('email')
                    password = self.request.get('password')
                    phone = self.request.get('phone')
                    u = User.Create(email=email)
                    u.Update(password=password, level=USER.ADMIN, phone=phone)
                    u.put()

                self.response.out.write("OK")
            else:
                self.response.out.write("App already installed")
项目:full-stack-developer-nanodegree    作者:pelayolluna    | 项目源码 | 文件源码
def post(self):
        user_id = self.read_secure_cookie('user_id')

        if not self.user:
            self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')

        if subject and content:
            p = Post(parent = blog_key(), subject = subject, content = content, user_id=user_id)
            p.put()
            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "Subject and content, please!"
            self.render("newpost.html", subject=subject, content=content, error=error, user_id=user_id)
项目:full-stack-developer-nanodegree    作者:pelayolluna    | 项目源码 | 文件源码
def get(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)
        user_id = self.read_secure_cookie('user_id')
        error = ''
        info = ''

        if not post:
            self.redirect("/")
            return

        if self.read_secure_cookie('user_id') == '':
            self.redirect("/login")

        if post.user_id != user_id:
            error = 'You are not allowed to edit this post.'
            self.render("infopost.html", info = info, error = error)
        else:        
            self.render("editpost.html", post = post, error = error)
项目:full-stack-developer-nanodegree    作者:pelayolluna    | 项目源码 | 文件源码
def post(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)
        user_id = self.read_secure_cookie('user_id')
        subject = self.request.get('subject')
        content = self.request.get('content')
        error = ''
        info = ''

        if subject and content and post.user_id == user_id:
            post.subject = subject
            post.content = content
            post.put()
            redirect_id = post.key().id()
            info = 'Post edited!'
            self.render("infopost.html", error = error, info=info)
        else:
            error = "Subject and content, please!"
            self.render("editpost.html", post = post, error=error)
项目:full-stack-developer-nanodegree    作者:pelayolluna    | 项目源码 | 文件源码
def get(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)
        post.subject
        error = ''
        info=''
        user_id = self.read_secure_cookie('user_id')

        if self.read_secure_cookie('user_id') == '':
            self.redirect("/login")

        if not post:
            self.redirect("/")
            return

        if post.user_id != user_id:
            error = 'You are not allowed to delete this post.'
        else:
            db.delete(key)
            info='Post Deleted!'

        self.render("infopost.html", error = error, info=info)
项目:multi-user-blog    作者:code-dagger    | 项目源码 | 文件源码
def post(self):
        '''
            It first checks for user and then stores post in the database
        '''
        if self.user:
            self.subject = self.request.get("subject")
            self.content = self.request.get("content")
            self.username = self.user.username
            if self.subject and self.content:
                post = Post(subject=self.subject, content=self.content,
                            created_by_user=self.username)
                post.put()
                # Redirect to the newly created post page
                self.redirect('/post/%s' % str(post.key().id()))
            else:
                self.error = "All fields are required !!"
                self.render_page(subject=self.subject, content=self.content,
                                 error=self.error)
        else:
            self.redirect('/login')
项目:multi-user-blog    作者:code-dagger    | 项目源码 | 文件源码
def get(self, post_id):
        if self.user:
            key = db.Key.from_path('Post', int(post_id))
            self.post = db.get(key)
            if self.post:
                if self.post.created_by_user == self.user.username:
                    if self.post.created_by_user == self.user.username:
                        self.render("deletepost.html", post_id=post_id)
                    else:
                        self.redirect("/home")
                else:
                    self.redirect('/home')
            else:
                self.redirect("/home")
        else:
            self.redirect("/login")
项目:multi-user-blog    作者:code-dagger    | 项目源码 | 文件源码
def post(self, post_id):
        '''
        This block first if user is logged in or not, if logged in
        then checks the request made for deletion of post is in database,
        if found it deletes that post.
        '''
        if self.user:
            key = db.Key.from_path('Post', int(post_id))
            self.post = db.get(key)
            if self.post:
                comments = Comment.get_comments(post_id)
                if self.post.created_by_user == self.user.username:
                    db.delete(key)
                    for comment in comments:
                        db.delete(comment)
                    self.redirect("/home")
                else:
                    self.redirect("/home")
            else:
                self.redirect("/home")
        else:
            self.redirect("/login")
项目:multi-user-blog    作者:code-dagger    | 项目源码 | 文件源码
def get(self, post_id):
        if self.user:
            key = db.Key.from_path('Post', int(post_id))
            self.post = db.get(key)
            if self.post:
                if self.post.created_by_user == self.user.username:
                    self.redirect('/home')
                else:
                    if self.post.total_likes is None:
                        self.post.total_likes = 0
                    if self.user.username not in self.post.liked_by_users:
                        self.post.total_likes += 1
                        self.post.liked_by_users.append(self.user.username)
                        self.post.put()
                        self.redirect('/post/%s' % int(post_id))
                    else:
                        self.post.total_likes -= 1
                        self.post.liked_by_users.remove(self.user.username)
                        self.post.put()
                        self.redirect('/post/%s' % int(post_id))
            else:
                self.redirect('/home')
        else:
            self.redirect('/login')
项目:multi-user-blog    作者:code-dagger    | 项目源码 | 文件源码
def post(self, comment_id):
        '''
        This block first checks if user is logged in or not, if logged in
        it checks for the comment and if it exists it edit comment.
        '''
        if self.user:
            commentKey = db.Key.from_path('Comment', int(comment_id))
            self.comment = db.get(commentKey)
            if self.comment:
                if self.comment.comment_by_user == self.user.username:
                    editedComment = self.request.get("comment")
                    if editedComment:
                        self.comment.comment = editedComment
                        self.comment.put()
                        self.redirect('/post/%s' % int(self.comment.post_id))
                    else:
                        self.error = "Comment cannot be blank!!"
                        self.render("editcomment.html", comment=self.comment,
                                    user=self.user, error=self.error)
                else:
                    self.redirect('/home')
            else:
                self.redirect('/home')
        else:
            self.redirect('/login')
项目:Multi-User-Blog    作者:thetreythomas    | 项目源码 | 文件源码
def post(self, postID, commentID):
        key = db.Key.from_path('Post', int(postID), parent = blog_key())
        post = db.get(key)

        if self.request.get("save"):
            comment = Comments.get_by_id(int(commentID))
            if self.user and comment:
                comment = Comments.get_by_id(int(commentID))
                if comment.author.name == self.user.name:
                    comment.content = self.request.get("content")
                    comment.put()
                    time.sleep(0.2)
                    self.redirect("/blog/%s" % str(post.key().id()))
                else:
                    save_error = "Only the author of the comment can make changes."
                    self.render("editcomment.html", comment = comment, save_error = save_error)

        if self.request.get("cancel"):
            self.redirect("/blog/%s" % str(post.key().id()))
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def __call__(cls, *args, **kwargs):
        entity_quoting = kwargs.get('entity_quoting', False)
        if 'entity_quoting' in kwargs:
             del kwargs['entity_quoting']

        obj = super(AdapterMeta, cls).__call__(*args, **kwargs)
        if not entity_quoting:
            quot = obj.QUOTE_TEMPLATE = '%s'
            regex_ent = r'(\w+)'
        else:
            quot = obj.QUOTE_TEMPLATE
            regex_ent = REGEX_NO_GREEDY_ENTITY_NAME
        obj.REGEX_TABLE_DOT_FIELD = re.compile(r'^' + \
                                                    quot % regex_ent + \
                                                    r'\.' + \
                                                    quot % regex_ent + \
                                                    r'$')

        return obj


###############################################################################
# this is a generic adapter that does nothing; all others are derived from this
###############################################################################