def generate_files(self):
        """
        generate_data method

        generate random file data so we can map it

        """

        # generate 500 file records
        total_records = 500
        messagelog = []

        for i in range(total_records):
            # create new file entity
            download_count = random.randint(1, 10)
            file_name = uuid.uuid4()
            new_file = File()
            new_file.name = str(file_name) + '.txt'
            new_file.download_count = download_count
            new_file.put()
            messagelog.append("File added: {0} - {1}".format(i, new_file.name))

        context = {'messagelog': messagelog}

        self.render_response('file.html', context=context)
Beispiel #2
0
    def post(self):
        upload = self.get_uploads()[0]

        # Path
        root = self.session.get('root')
        path = self.request.POST.get('path')
        if path != '':
            fpath = root + '/' + path
        else:
            fpath = root

        fname = upload.filename
        fsize = round(blobstore.BlobInfo(upload.key()).size / 1000, 2)
        if fsize < 1:
            fsize = 1
        fdate = blobstore.BlobInfo(upload.key()).creation

        qry = File.query(File.path == fpath, File.name == fname)
        result = qry.fetch()
        if len(result) > 0:
            result[0].key.delete()
            blobstore.delete(result[0].blob_key)

            # Get file info from blobinfo
        file = File(name=fname,
                    path=fpath,
                    blob_key=upload.key(),
                    size=str(fsize),
                    cdate=str(fdate.strftime("%m/%d/%Y %H:%M:%S")))
        file.put()

        # self.response.write(upload.filename)
        self.redirect('/?path=' + path)
    def post(self):
        for blob_info in self.get_uploads():
            if not users.get_current_user():
                #if they are not logged in then delete all the upload data and redirect them to login
                for blob in self.get_uploads():
                    blob.delete()
                self.redirect(users.create_login_url("/"))
                return

            #if uploading a csv file, update the datastore to match records in file
            if blob_info.content_type == "application/vnd.ms-excel":
                blobdata=blobstore.BlobReader(blob_info)
                reader = csv.DictReader(blobdata,dialect='excel')
                self.response.headers['Content-Type'] = 'text/plain'

                for row in reader:
                    artist = row["Artist"]
                    categories = row["Categories"]
                    name = row["Name of Piece"]
                    price = row["Price($)"]
                    itemNumber = row["Item Number"]
                    width = row["Width(in)"]
                    height = row["Height(in)"]
                    depth = row["Depth(in)"]
                    weight = row["Weight"]
                    width = row["Width(in)"]
                    description = row["Product Description"]
                    colors = row["Colors"]
                    mediums = row["Mediums"]
                    masterNum = row["Master Art Piece (Item Number)"]
                    pictureName = row ["Picture Name"]

                    #check if artpiece with this item number already exists
                    qry = ArtPiece.query(ArtPiece.itemNumber==itemNumber)
                    existingArtPiece = qry.get()

                    #if existingArtPiece:
                        #if an artpiece with that itemNumber is already stored then update the record with the new information


                #delete and skip to the next file, we don't save excel files nor do we perform photo related code
                blob_info.delete()
                continue

            #otherwise we assume it is a photo (since it only allows jpg, png, gif, and csv)
            else:
                #check to see if a photo with that name already exists
                qry = File.query(File.file_name==blob_info.filename.upper())
                existingPhoto = qry.get()

                if existingPhoto:
                    #if a file with that name is already stored then replace the blob with the new uploaded file
                    blobstore.delete(existingPhoto.blob)
                    existingPhoto.blob = blob_info.key()
                    existingPhoto.uploaded_by=users.get_current_user()
                    existingPhoto.thumbnail=images.get_serving_url(blob_info.key(), size=200)
                    existingPhoto.url=images.get_serving_url(blob_info.key())

                    existingPhoto.put()
                else:
                    #add a new file entry if no file with that name already exists
                    file = File(blob=blob_info.key(), file_name=blob_info.filename.upper(), uploaded_by=users.get_current_user(), url=images.get_serving_url(blob_info.key()), thumbnail=images.get_serving_url(blob_info.key(), size=200))
                    file.put()

                self.redirect("/admin/photos/%s/success" % blob_info.key())
    def post(self):
        for blob_info in self.get_uploads():
            if not users.get_current_user():
                #if they are not logged in then delete all the upload data and redirect them to login
                for blob in self.get_uploads():
                    blob.delete()
                self.redirect(users.create_login_url("/"))
                return

            #if uploading a csv file, update the datastore to match records in file
            if blob_info.content_type == "application/vnd.ms-excel":
                blobdata = blobstore.BlobReader(blob_info)
                reader = csv.DictReader(blobdata, dialect='excel')
                self.response.headers['Content-Type'] = 'text/plain'

                for row in reader:
                    artist = row["Artist"]
                    categories = row["Categories"]
                    name = row["Name of Piece"]
                    price = row["Price($)"]
                    itemNumber = row["Item Number"]
                    width = row["Width(in)"]
                    height = row["Height(in)"]
                    depth = row["Depth(in)"]
                    weight = row["Weight"]
                    width = row["Width(in)"]
                    description = row["Product Description"]
                    colors = row["Colors"]
                    mediums = row["Mediums"]
                    masterNum = row["Master Art Piece (Item Number)"]
                    pictureName = row["Picture Name"]

                    #check if artpiece with this item number already exists
                    qry = ArtPiece.query(ArtPiece.itemNumber == itemNumber)
                    existingArtPiece = qry.get()

                    #if existingArtPiece:
                    #if an artpiece with that itemNumber is already stored then update the record with the new information

                #delete and skip to the next file, we don't save excel files nor do we perform photo related code
                blob_info.delete()
                continue

            #otherwise we assume it is a photo (since it only allows jpg, png, gif, and csv)
            else:
                #check to see if a photo with that name already exists
                qry = File.query(File.file_name == blob_info.filename.upper())
                existingPhoto = qry.get()

                if existingPhoto:
                    #if a file with that name is already stored then replace the blob with the new uploaded file
                    blobstore.delete(existingPhoto.blob)
                    existingPhoto.blob = blob_info.key()
                    existingPhoto.uploaded_by = users.get_current_user()
                    existingPhoto.thumbnail = images.get_serving_url(
                        blob_info.key(), size=200)
                    existingPhoto.url = images.get_serving_url(blob_info.key())

                    existingPhoto.put()
                else:
                    #add a new file entry if no file with that name already exists
                    file = File(blob=blob_info.key(),
                                file_name=blob_info.filename.upper(),
                                uploaded_by=users.get_current_user(),
                                url=images.get_serving_url(blob_info.key()),
                                thumbnail=images.get_serving_url(
                                    blob_info.key(), size=200))
                    file.put()

                self.redirect("/admin/photos/%s/success" % blob_info.key())