Exemplo n.º 1
0
    def post(self):
        """Remove one plaque and its associated Comments and GCS image."""
        user = users.get_current_user()
        name = "anon" if user is None else user.nickname()

        plaque_key = self.request.get('plaque_key')
        plaque = ndb.Key(urlsafe=plaque_key).get()

        if name != 'kester':
            email_admin('Delete warning!', '%s tried to delete %s' % (
                name, plaque.title_url))
            raise NotImplementedError("delete is turned off for now")

        for comment in plaque.comments:
            comment.delete()
        try:
            gcs.delete(plaque.pic)

            # Delete search index for this document
            plaque_search_index = search.Index(PLAQUE_SEARCH_INDEX_NAME)
            results = plaque_search_index.search(search_term)
            for result in results:
                plaques = [ndb.Key(urlsafe=r.doc_id).get() for r in results]
                plaque_search_index.delete(result.doc_id)
        except:
            pass

        plaque.key.delete()
        #memcache.flush_all()
        email_admin('%s Deleted plaque %s' % (name, plaque.title_url),
                    '%s Deleted plaque %s' % (name, plaque.title_url))
        self.redirect('/nextpending')
Exemplo n.º 2
0
    def delete(self):
        """ delete filename in GCS and GCSFile """

        try:
            gcs.delete(self.gcs_filename)
        except gcs.NotFoundError, e:
            logging.warning('GCS file %s NOT FOUND : %s' % (self.gcs_filename, e))
Exemplo n.º 3
0
    def post(self):
        """Remove one plaque and its associated GCS image."""
        user = users.get_current_user()
        if not users.is_current_user_admin():
            return "admin only, please log in"
        name = "anon" if user is None else user.nickname()

        plaque_key = self.request.get('plaque_key')
        plaque = ndb.Key(urlsafe=plaque_key).get()

        if name != 'kester':
            email_admin('Delete warning!',
                        '%s tried to delete %s' % (name, plaque.title_url))
            raise NotImplementedError("delete is turned off for now")

        try:
            gcs.delete(plaque.pic)

            # Delete search index for this document
            plaque_search_index = search.Index(PLAQUE_SEARCH_INDEX_NAME)
            results = plaque_search_index.search(search_term)
            for result in results:
                plaques = [ndb.Key(urlsafe=r.doc_id).get() for r in results]
                plaque_search_index.delete(result.doc_id)
        except:
            pass

        plaque.key.delete()
        #memcache.flush_all()
        email_admin('%s Deleted plaque %s' % (name, plaque.title_url),
                    '%s Deleted plaque %s' % (name, plaque.title_url))
        self.redirect('/nextpending')
Exemplo n.º 4
0
 def delete_files(self):
     self.response.write('Deleting files...\n')
     for filename in self.tmp_filenames_to_clean_up:
         self.response.write('Deleting file %s\n' % filename)
         try:
             gcs.delete(filename)
         except gcs.NotFoundError:
             pass
Exemplo n.º 5
0
def delete_thumbnail(thumbnail_key):
    filename = '/gs/' + THUMBNAIL_BUCKET + '/' + thumbnail_key
    blob_key = blobstore.create_gs_key(filename)
    images.delete_serving_url(blob_key)
    thumbnail_reference = ThumbnailReference.query(
        ThumbnailReference.thumbnail_key == thumbnail_key).get()
    thumbnail_reference.key.delete()
    filename = '/' + THUMBNAIL_BUCKET + '/' + thumbnail_key
    gcs.delete(filename)
Exemplo n.º 6
0
    def delete(self, image_id):
        image_model = ImageModel.get_by_id(int(image_id))
        filename = image_model.bucket_name
        gcs.delete(filename)
        image_model.key.delete()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'id': image_id
        }))
Exemplo n.º 7
0
 def post(self):
     file_name = self.request.get('fileName')
     secret = self.request.get('secret')
     if secret == secrets.Google_Frontend:
         try:
             gcs.delete(file_name)
         except gcs.NotFoundError:
             pass
         else:
             self.write('success')
     else:
         self.write('no')
Exemplo n.º 8
0
    def post(self):
        # url request is a list
        delete_stream_string = self.request.get('delete_list')
        delete_stream_list = delete_stream_string.split(',')
        # delete the stream list using map method
        # self.response.out.write(delete_stream_list[1]) error receive a string not a list

        # self.response.out.write(delete_stream_list[0])
        for stream in delete_stream_list:
            ops.delete_stream(str(stream))
            # delete the stream in the google cloud storage
            try:
                stream_path = "/pigeonhole-apt.appspot.com/" + str(
                    stream) + "/"
                gcs.delete(stream_path)
            except gcs.NotFoundError:
                pass
Exemplo n.º 9
0
 def post(self):
     for dictionary in Dictionary.query():
         data_object = []
         key = str(int(time.time()))
         words = GlobalDictionaryWord.query(GlobalDictionaryWord.deleted == False,
                                            GlobalDictionaryWord.lang == dictionary.key.id()).order(GlobalDictionaryWord.E).fetch()
         chunk_size = len(words) // 100
         for i, word in enumerate(words):
             data_object.append({"word": word.word,
                                 "diff": i // chunk_size,
                                 "used": word.used_times,
                                 "tags": word.tags})
         output_file = gcs.open(get_gcs_filename(key), "w", "application/json")
         json.dump(data_object, output_file)
         output_file.close()
         old_key = dictionary.gcs_key
         dictionary.gcs_key = key
         dictionary.put()
         if old_key:
             gcs.delete(get_gcs_filename(old_key))
Exemplo n.º 10
0
 def delete(self):
     file_id = self.request.get('fileId')
     user_id = self.request.headers.get('Firebase-User-Id')
     if file_id and user_id and file_id.isdigit():
         # get the gcs_file_name from the database
         db_gcs_file = GCSFile.get(int(file_id))
         if db_gcs_file:
             try:
                 gcs.delete(db_gcs_file.gcs_file_name)
             except gcs.NotFoundError:
                 pass
             else:
                 # log the delete
                 FileDeletes.save_new(user_id=user_id, gcs_file_name=db_gcs_file.gcs_file_name,
                                      original_file_name=db_gcs_file.original_file_name).put_async()
                 # delete from the database
                 db_gcs_file.key.delete()
                 self.response.set_status(204)
         else:
             self.response.set_status(400)
             self.write('404: This file does not exist')
Exemplo n.º 11
0
 def post(self):
     for dictionary in Dictionary.query():
         data_object = []
         key = str(int(time.time()))
         words = (
             GlobalDictionaryWord.query(
                 GlobalDictionaryWord.deleted == False, GlobalDictionaryWord.lang == dictionary.key.id()
             )
             .order(GlobalDictionaryWord.E)
             .fetch()
         )
         chunk_size = len(words) // 100
         for i, word in enumerate(words):
             data_object.append(
                 {"word": word.word, "diff": i // chunk_size, "used": word.used_times, "tags": word.tags}
             )
         output_file = gcs.open(get_gcs_filename(key), "w", "application/json")
         json.dump(data_object, output_file)
         output_file.close()
         old_key = dictionary.gcs_key
         dictionary.gcs_key = key
         dictionary.put()
         if old_key:
             gcs.delete(get_gcs_filename(old_key))
Exemplo n.º 12
0
    def post(self, is_edit=False):
        """
        We set the same parent key on the 'Plaque' to ensure each Plauqe is in
        the same entity group. Queries across the single entity group will be
        consistent. However, the write rate to a single entity group should be
        limited to ~1/second.
        """

        try:
            plaqueset_name = self.request.get('plaqueset_name',
                                              DEF_PLAQUESET_NAME)
            plaqueset_key = get_plaqueset_key(plaqueset_name)

            # Create new plaque entity:
            #
            logging.info('creating or updating plaque entity')
            plaque = self._create_or_update_plaque(is_edit, plaqueset_key)
            logging.info("Plaque %s is added with is_edit %s." %
                         (plaque.title, is_edit))

            # Make the plaque searchable:
            #
            logging.info('making search document')
            try:
                plaque_search_index = search.Index(PLAQUE_SEARCH_INDEX_NAME)
                plaque_search_index.put(plaque.to_search_document())
            except search.Error as err:
                logging.error(err)
                raise err

            # Notify admin:
            #
            #logging.info('creating email')
            post_type = 'Updated' if is_edit else 'New'
            user = users.get_current_user()
            name = "anon" if user is None else user.nickname()
            msg = '%s %s plaque! %s' % (name, post_type, plaque.title_page_url)
            body = """
<p>
    <a href="https://readtheplaque.com{1.title_page_url}">
        {0} plaque!
    </a>
</p>
<p>
    <a href="https://readtheplaque.com{1.title_page_url}">
        <img alt="plaque alt" title="plaque title" src="{1.img_url}"/>
    </a>
</p>
            """.format(post_type, plaque)
            #email_admin(msg, body)
            state = ADD_STATES['ADD_STATE_SUCCESS']
            msg = plaque.title_page_url
        except (BadValueError, ValueError, SubmitError) as err:
            msg = err
            state = ADD_STATES['ADD_STATE_ERROR']
            logging.info(msg)
            # Delete the GCS image, if it exists (the GCS images are not
            # managed by the transaction, apparently)
            try:
                gcs.delete(plaque.pic)
            except:
                pass

        self.redirect('/add?state=%s&message=%s' % (state, msg))
Exemplo n.º 13
0
    def post(self, is_edit=False):
        """
        We set the same parent key on the 'Plaque' to ensure each Plauqe is in
        the same entity group. Queries across the single entity group will be
        consistent. However, the write rate to a single entity group should be
        limited to ~1/second.
        """

        #if users.is_current_user_admin():
            #memcache.flush_all()
        try:
            plaqueset_name = self.request.get('plaqueset_name',
                                              DEF_PLAQUESET_NAME)
            plaqueset_key = get_plaqueset_key(plaqueset_name)

            # Create new plaque entity:
            #
            logging.info('creating or updating plaque entity')
            plaque = self._create_or_update_plaque(is_edit, plaqueset_key)
            logging.info("Plaque %s is added with is_edit %s." %
                (plaque.title, is_edit))

            # Make the plaque searchable:
            #
            logging.info('making search document')
            try:
                plaque_search_index = search.Index(PLAQUE_SEARCH_INDEX_NAME)
                plaque_search_index.put(plaque.to_search_document())
            except search.Error as err:
                logging.error(err)
                raise err

            # Notify admin:
            #
            #logging.info('creating email')
            post_type = 'Updated' if is_edit else 'New'
            user = users.get_current_user()
            name = "anon" if user is None else user.nickname()
            msg = '%s %s plaque! %s' %  (name, post_type, plaque.title_page_url)
            body = """
<p>
    <a href="http://readtheplaque.com{1.title_page_url}">
        {0} plaque!
    </a>
</p>
<p>
    <a href="http://readtheplaque.com{1.title_page_url}">
        <img alt="plaque alt" title="plaque title" src="{1.img_url}"/>
    </a>
</p>
            """.format(post_type, plaque)
            #logging.info('sending email')
            #email_admin(msg, body)
            state = ADD_STATES['ADD_STATE_SUCCESS']
            msg = plaque.title_page_url
        except (BadValueError, ValueError, SubmitError) as err:
            msg = err
            state = ADD_STATES['ADD_STATE_ERROR']
            logging.info(msg)
            # Delete the GCS image, if it exists (the GCS images are not
            # managed by the transaction, apparently)
            try:
                gcs.delete(plaque.pic)
            except:
                pass

        self.redirect('/add?state=%s&message=%s' % (state, msg))