def post(self):
        categoryName = self.request.get('categoryName')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name == photoName.upper()).get()

        #check to see if a category with that name already exists
        existingCategory = Category.query(
            Category.categoryName == categoryName).get()

        if existingCategory:
            #if an category with that name already exists, then update the information with the form data
            existingCategory.categoryName = categoryName
            existingCategory.picture = photo.key
            existingCategory.uploaded_by = users.get_current_user()

            existingCategory.put()
            existingCategory.add_to_search_index()
            message = "Successfully updated category record: " + existingCategory.categoryName

        else:
            #add a new category entry if no category with that name already exists
            category = Category(categoryName=categoryName,
                                picture=photo.key,
                                uploaded_by=users.get_current_user())
            category.put()
            category.add_to_search_index()
            message = "Successfully created category record: " + category.categoryName

        self.response.write(message)
    def post(self):
        firstName = self.request.get('firstName')
        lastName = self.request.get('lastName')
        biography = self.request.get('biography')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name==photoName.upper()).get()

        #check to see if a artist with that name already exists
        existingArtist = Artist.query(Artist.firstName==firstName and Artist.lastName==lastName).get()

        if existingArtist:
            #if an artist with that name already exists, then update the information with the form data
            existingArtist.biography=biography
            existingArtist.firstName=firstName
            existingArtist.lastName=lastName
            existingArtist.picture=photo.key
            existingArtist.uploaded_by=users.get_current_user()

            existingArtist.put()
            existingArtist.add_to_search_index()
            message = "Successfully updated artist record: " + existingArtist.firstName + " " + existingArtist.lastName

        else:
            #add a new artist entry if no artist with that name already exists
            artist = Artist(biography=biography, firstName=firstName, lastName=lastName, picture=photo.key, uploaded_by=users.get_current_user())
            artist.put()
            artist.add_to_search_index()
            message = "Successfully created artist record: " + artist.firstName + " " + artist.lastName

        self.response.write(message)
Exemplo n.º 3
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 get(self):

        #sort the art by artist name and then by artpiece name
        photos = File.query().order(File.file_name)

        html = ""
        for photo in photos:
            html+="""<li class="span3">
                        <div class="thumbnail">
                            <img data-src="holder.js/300x200" alt="300x200" style="width: 300px; height: 200px;" src=""" + photo.url + """>
                            <div class="caption">
                                <div class="artpieceName">
                                    <h5>""" + photo.file_name + """</h5>
                                    <a data-toggle="modal"  href="#editPhotoModal" onclick="fillEditPhotoModalDefaults(""" + str(photo.key.id()) + """,'""" + photo.file_name + """');" class="btn btn-medium">
                                        <span class="glyphicon icon-edit"></span>
                                    </a>
                                    <a data-toggle="modal" data-id=""" + str(photo.key.id()) + """ href="#deletePhotoModal" class="open-deletePhotoModal btn btn-medium">
                                        <span class="glyphicon icon-remove"></span>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>"""

        self.response.write(html)
Exemplo n.º 5
0
    def post(self):
        artistKeyString = self.request.get('editArtistKey')
        artistID = int(artistKeyString)
        firstName = self.request.get('editFirstName')
        lastName = self.request.get('editLastName')
        biography = self.request.get('editBiography')
        photoName = self.request.get('editPhotoName')

        #get the photo specified by the user
        photo = File.query(File.file_name == photoName.upper()).get()

        #get the artist based on the key and update all fields
        artist = Artist.get_by_id(artistID)

        artist.biography = biography
        artist.firstName = firstName
        artist.lastName = lastName
        artist.picture = photo.key
        artist.uploaded_by = users.get_current_user()

        artist.put()
        artist.add_to_search_index()

        message = "Successfully updated artist record: " + artist.firstName + " " + artist.lastName
        self.response.write(message)
    def get(self):

        #sort the art by artist name and then by artpiece name
        photos = File.query().order(File.file_name)

        html = ""
        for photo in photos:
            html += """<li class="span3">
                        <div class="thumbnail">
                            <img data-src="holder.js/300x200" alt="300x200" style="width: 300px; height: 200px;" src=""" + photo.url + """>
                            <div class="caption">
                                <div class="artpieceName">
                                    <h5>""" + photo.file_name + """</h5>
                                    <a data-toggle="modal"  href="#editPhotoModal" onclick="fillEditPhotoModalDefaults(""" + str(
                photo.key.id()
            ) + """,'""" + photo.file_name + """');" class="btn btn-medium">
                                        <span class="glyphicon icon-edit"></span>
                                    </a>
                                    <a data-toggle="modal" data-id=""" + str(
                photo.key.id()
            ) + """ href="#deletePhotoModal" class="open-deletePhotoModal btn btn-medium">
                                        <span class="glyphicon icon-remove"></span>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>"""

        self.response.write(html)
    def post(self):
        categoryName = self.request.get('categoryName')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name==photoName.upper()).get()

        #check to see if a category with that name already exists
        existingCategory = Category.query(Category.categoryName==categoryName).get()

        if existingCategory:
            #if an category with that name already exists, then update the information with the form data
            existingCategory.categoryName=categoryName
            existingCategory.picture=photo.key
            existingCategory.uploaded_by=users.get_current_user()

            existingCategory.put()
            existingCategory.add_to_search_index()
            message = "Successfully updated category record: " + existingCategory.categoryName

        else:
            #add a new category entry if no category with that name already exists
            category = Category(categoryName=categoryName, picture=photo.key, uploaded_by=users.get_current_user())
            category.put()
            category.add_to_search_index()
            message = "Successfully created category record: " + category.categoryName

        self.response.write(message)
    def post(self):
        artistKeyString = self.request.get('editArtistKey')
        artistID = int(artistKeyString)
        firstName = self.request.get('editFirstName')
        lastName = self.request.get('editLastName')
        biography = self.request.get('editBiography')
        photoName = self.request.get('editPhotoName')

        #get the photo specified by the user
        photo = File.query(File.file_name==photoName.upper()).get()

        #get the artist based on the key and update all fields
        artist = Artist.get_by_id(artistID)

        artist.biography=biography
        artist.firstName=firstName
        artist.lastName=lastName
        artist.picture=photo.key
        artist.uploaded_by=users.get_current_user()

        artist.put()
        artist.add_to_search_index()

        message = "Successfully updated artist record: " + artist.firstName + " " + artist.lastName
        self.response.write(message)
 def get(self):
   photos = File.query().order(File.file_name)
   self.render_template("/templates/fileUpload.html", {
       "title": "Manage Photos",
       'form_url': blobstore.create_upload_url('/admin/photos/upload'),
       'logout_url': users.create_logout_url('/'),
       'photos' : photos
   })
 def get(self):
     photos = File.query().order(File.file_name)
     self.render_template(
         "/templates/fileUpload.html", {
             "title": "Manage Photos",
             'form_url':
             blobstore.create_upload_url('/admin/photos/upload'),
             'logout_url': users.create_logout_url('/'),
             'photos': photos
         })
Exemplo n.º 11
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template(
            '/templates/publicArtPiece.html')

        itemNumber = self.request.get('itemNumber')
        artpiece = ArtPiece.query(ArtPiece.itemNumber == itemNumber).get()
        photo = File.query(File.key == artpiece.picture).get()
        artist = Artist.query(Artist.key == artpiece.artist).get()

        #create a comma separated string of categories
        categories = ndb.get_multi(artpiece.categories)
        categoryNamesList = []
        for category in categories:
            categoryNamesList.append(str(category.categoryName))
        categoriesString = ",".join(categoryNamesList)

        #check for additional sizes if this is a master or a slave piece
        additionalPieces = []
        if artpiece.masterArtFlag:
            slavePieces = ArtPiece.query(
                ArtPiece.masterArtPiece == artpiece.key)
            for slavepiece in slavePieces:
                additionalPieces.append(slavepiece)
        if artpiece.slaveArtFlag:
            masterArtPiece = ArtPiece.query(
                ArtPiece.key == artpiece.masterArtPiece).get()
            otherSlavePieces = ArtPiece.query(
                ArtPiece.masterArtPiece == masterArtPiece.key,
                ArtPiece.key <> artpiece.key)
            additionalPieces.append(masterArtPiece)
            for slavepiece in otherSlavePieces:
                additionalPieces.append(slavepiece)

        #generate the appropriate html to link to these other pieces if they exist
        additionalSizes = ""
        if len(additionalPieces) > 0:
            additionalSizes += "<h5>Also Available in Other Sizes:</h5><ul>"
            for additionalPiece in additionalPieces:
                additionalSizes += "<a href=\"/artpiece?itemNumber=" + additionalPiece.itemNumber + "\"><li>" + additionalPiece.name + " (" + additionalPiece.priceDisplay + ")</li></a>"
            additionalSizes += "</ul>"

        templateVars = {
            "title": artpiece.name,
            "additionalSizes": additionalSizes,
            "artpiece": artpiece,
            "artist": artist,
            "photo": photo,
            "categories": categoriesString
        }

        self.response.write(template.render(templateVars))
    def post(self):
        fileKeyString = self.request.get('editPhotoKey')
        newPhotoName = self.request.get('editPhotoName').upper()
        fileToEdit = File.get_by_id(int(fileKeyString))

        #check if another file with that name already exists
        oldFile = File.query(File.file_name == newPhotoName).get()
        if oldFile:
            message = "ERROR: A file with that name already exists"
        else:
            #Find and update the file name of the current file(not possible to do on the actual blob)
            fileToEdit.file_name = newPhotoName
            fileToEdit.put()
            message = "Successfully updated photo name: " + fileToEdit.file_name

        self.response.write(message)
    def post(self):
        fileKeyString = self.request.get('editPhotoKey')
        newPhotoName = self.request.get('editPhotoName').upper()
        fileToEdit = File.get_by_id(int(fileKeyString))

        #check if another file with that name already exists
        oldFile= File.query(File.file_name==newPhotoName).get()
        if oldFile:
            message = "ERROR: A file with that name already exists"
        else:
            #Find and update the file name of the current file(not possible to do on the actual blob)
            fileToEdit.file_name = newPhotoName
            fileToEdit.put()
            message = "Successfully updated photo name: " + fileToEdit.file_name

        self.response.write(message)
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('/templates/publicArtPiece.html')

        itemNumber =  self.request.get('itemNumber')
        artpiece = ArtPiece.query(ArtPiece.itemNumber==itemNumber).get()
        photo = File.query(File.key==artpiece.picture).get()
        artist = Artist.query(Artist.key==artpiece.artist).get()

        #create a comma separated string of categories
        categories = ndb.get_multi(artpiece.categories)
        categoryNamesList = []
        for category in categories:
            categoryNamesList.append(str(category.categoryName))
        categoriesString = ",".join(categoryNamesList)

        #check for additional sizes if this is a master or a slave piece
        additionalPieces = []
        if artpiece.masterArtFlag:
            slavePieces=ArtPiece.query(ArtPiece.masterArtPiece==artpiece.key)
            for slavepiece in slavePieces:
                additionalPieces.append(slavepiece)
        if artpiece.slaveArtFlag:
            masterArtPiece = ArtPiece.query(ArtPiece.key==artpiece.masterArtPiece).get()
            otherSlavePieces=ArtPiece.query(ArtPiece.masterArtPiece==masterArtPiece.key,ArtPiece.key<>artpiece.key)
            additionalPieces.append(masterArtPiece)
            for slavepiece in otherSlavePieces:
                additionalPieces.append(slavepiece)

        #generate the appropriate html to link to these other pieces if they exist
        additionalSizes = ""
        if len(additionalPieces) > 0:
            additionalSizes += "<h5>Also Available in Other Sizes:</h5><ul>"
            for additionalPiece in additionalPieces:
                additionalSizes += "<a href=\"/artpiece?itemNumber=" + additionalPiece.itemNumber + "\"><li>" + additionalPiece.name + " (" + additionalPiece.priceDisplay + ")</li></a>"
            additionalSizes += "</ul>"

        templateVars = {
                        "title" : artpiece.name,
                        "additionalSizes": additionalSizes,
                        "artpiece": artpiece,
                        "artist": artist,
                        "photo": photo,
                        "categories": categoriesString}

        self.response.write(template.render(templateVars))
Exemplo n.º 15
0
    def post(self):
        root = self.session.get('root')
        file = self.request.get('file')
        file = file.split(',')
        full_path = root + '/' + file[0]
        filename = file[1]

        # Delete from file model
        qry = File.query(File.path == full_path, File.name == filename)
        res = qry.fetch()
        res[0].key.delete()

        # if file is shared, delete it from sharefile model
        qry = Shared.query(Shared.path == full_path, Shared.name == filename)
        res = qry.fetch()
        res[0].key.delete()

        # Delete from blobstore
        blobstore.delete(res[0].blob_key)

        self.redirect('/?path=' + file[0])
    def post(self):
        categoryKeyString = self.request.get('editCategoryKey')
        categoryID = int(categoryKeyString)
        categoryName = self.request.get('editCategoryName')
        photoName = self.request.get('editCategoryPhotoName')

        #get the photo specified by the user
        photo = File.query(File.file_name == photoName.upper()).get()

        #get the category based on the key and update all fields
        category = Category.get_by_id(categoryID)

        category.categoryName = categoryName
        category.picture = photo.key
        category.uploaded_by = users.get_current_user()

        category.put()
        category.add_to_search_index()

        message = "Successfully updated category record: " + category.categoryName
        self.response.write(message)
    def post(self):
        categoryKeyString = self.request.get('editCategoryKey')
        categoryID = int(categoryKeyString)
        categoryName = self.request.get('editCategoryName')
        photoName = self.request.get('editCategoryPhotoName')

        #get the photo specified by the user
        photo = File.query(File.file_name==photoName.upper()).get()

        #get the category based on the key and update all fields
        category = Category.get_by_id(categoryID)

        category.categoryName=categoryName
        category.picture=photo.key
        category.uploaded_by=users.get_current_user()

        category.put()
        category.add_to_search_index()

        message = "Successfully updated category record: " + category.categoryName
        self.response.write(message)
Exemplo n.º 18
0
    def post(self):
        root = self.session.get('root')

        path = self.request.get('path')
        userto = self.request.get('selectuser')
        if userto == 'Select User':
            self.redirect('/?path=' + path + '&err=user_select_err')
        else:
            filename = self.request.get('filename')

            if path == '':
                full_path = root
            else:
                full_path = root + '/' + path

            qry = User.query()
            results = qry.fetch()
            for result in results:
                userkey = result.key.id()
                if str(userkey) == str(root):
                    share_by = result.email

            # private duplicate sharefile
            if dup_sharefile(full_path, filename):
                self.redirect('/?path=' + path + '&err=share_duplicate_err')
            else:
                qry = File.query(File.path == full_path, File.name == filename)
                results = qry.fetch()

                shared = Shared()
                shared.name = filename
                shared.path = full_path
                shared.blob_key = results[0].blob_key
                shared.sh_by = share_by
                shared.sh_to = userto
                shared.size = results[0].size
                shared.time = results[0].cdate
                shared.put()

                self.redirect('/?path=' + path)
Exemplo n.º 19
0
    def post(self):
        firstName = self.request.get('firstName')
        lastName = self.request.get('lastName')
        biography = self.request.get('biography')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name == photoName.upper()).get()

        #check to see if a artist with that name already exists
        existingArtist = Artist.query(Artist.firstName == firstName
                                      and Artist.lastName == lastName).get()

        if existingArtist:
            #if an artist with that name already exists, then update the information with the form data
            existingArtist.biography = biography
            existingArtist.firstName = firstName
            existingArtist.lastName = lastName
            existingArtist.picture = photo.key
            existingArtist.uploaded_by = users.get_current_user()

            existingArtist.put()
            existingArtist.add_to_search_index()
            message = "Successfully updated artist record: " + existingArtist.firstName + " " + existingArtist.lastName

        else:
            #add a new artist entry if no artist with that name already exists
            artist = Artist(biography=biography,
                            firstName=firstName,
                            lastName=lastName,
                            picture=photo.key,
                            uploaded_by=users.get_current_user())
            artist.put()
            artist.add_to_search_index()
            message = "Successfully created artist record: " + artist.firstName + " " + artist.lastName

        self.response.write(message)
 def get(self):
     files = File.query()
     for file in files:
         blobstore.delete(file.blob)
         key = file.key
         key.delete()
Exemplo n.º 21
0
    def post(self):
        blob_info = self.get_uploads()[0]

        #only act on the file if it is a .csv, .xls, or .xlsx file type
        if blob_info.content_type == "application/vnd.ms-excel" or blob_info.content_type == ".csv" or blob_info.content_type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
            blobdata=blobstore.BlobReader(blob_info)
            reader = csv.DictReader(blobdata,dialect='excel')
            self.response.headers['Content-Type'] = 'text/plain'
            message = ""
            editedMessage = ""
            createdMessage = ""

            for row in reader:
                artistString = row["Artist"]
                categoriesString = row["Categories"]
                name = row["Name of Piece"]
                price = row["Price($)"]
                priceDisplay = "$" + '{:20,.2f}'.format(Decimal(price))
                itemNumber = row["Item Number"]
                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"]
                masterItemNum = row["Master Art Piece (Item Number)"]
                pictureName = row ["Picture Name"]

                #find related objects to tie to this artpiece
                artistNameList=artistString.split(" ")
                artistFirstName=artistNameList[0]
                artistLastName=artistNameList[-1]
                artist = Artist.query(Artist.firstName==artistFirstName, Artist.lastName==artistLastName).get()
                categories = []
                categoriesList = categoriesString.split(",")
                for categoryString in categoriesList:
                    category = Category.query(Category.categoryName==categoryString.strip()).get()
                    categories.append(category)
                masterArtPiece = ArtPiece.query(ArtPiece.itemNumber==masterItemNum).get()
                photo = File.query(File.file_name==pictureName.upper()).get()

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

                if existingArtPiece:
                    #if an artpiece with that itemNumber is already stored then update the record with the new information
                    existingArtPiece.artist = artist.key
                    existingArtPiece.categories = []
                    for category in categories:
                        existingArtPiece.categories.append(category.key)
                    existingArtPiece.colors = colors
                    existingArtPiece.depth = depth
                    existingArtPiece.description = description
                    existingArtPiece.height = height
                    if masterArtPiece:
                        existingArtPiece.masterArtPiece = masterArtPiece.key
                        existingArtPiece.slaveArtFlag = True
                        masterArtPiece.masterArtFlag = True
                        masterArtPiece.put()
                    existingArtPiece.mediums = mediums
                    existingArtPiece.name = name
                    existingArtPiece.picture = photo.key
                    existingArtPiece.price = price
                    existingArtPiece.priceDisplay = priceDisplay
                    existingArtPiece.uploaded_by=users.get_current_user()
                    existingArtPiece.weight = weight
                    existingArtPiece.width = width

                    existingArtPiece.put()
                    existingArtPiece.add_to_search_index()

                    editedMessage += "<br>" + existingArtPiece.name

                else:
                    #otherwise create a new record for the artpiece
                    artPiece = ArtPiece(artist=artist.key, colors=colors, depth=depth, description=description, height=height, itemNumber=itemNumber, mediums=mediums, name=name, picture=photo.key, price=price, priceDisplay=priceDisplay, weight=weight, width=width, uploaded_by=users.get_current_user())
                    for category in categories:
                        artPiece.categories.append(category.key)
                    if masterArtPiece:
                        artPiece.masterArtPiece = masterArtPiece.key
                        artPiece.slaveArtFlag = True
                        masterArtPiece.masterArtFlag = True
                        masterArtPiece.put()

                    artPiece.put()
                    artPiece.add_to_search_index()

                    createdMessage += "<br>" + artPiece.name



            #no need to save the file in the blobstore
            blob_info.delete()

            message = "The following items were added to the database: <br>"
            message += createdMessage + "<br><br>"
            message+= "The following items were updated in the database: <br>"
            message += editedMessage

            self.response.write(message)
    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 get(self):
     files = File.query()
     for file in files:
         blobstore.delete(file.blob)
         key = file.key
         key.delete()
    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())
Exemplo n.º 25
0
    def post(self):
        artpieceKeyString = self.request.get('editArtKey')
        artpieceID = int(artpieceKeyString)
        artistString = self.request.get('editArtist')
        categoriesString = self.request.get('editCategories')
        name = self.request.get('editName')
        price = self.request.get('editPrice')
        priceDisplay = "$" + '{:20,.2f}'.format(Decimal(price))
        itemNumber = self.request.get('editItemNumber')
        width = self.request.get('editWidth')
        height = self.request.get('editHeight')
        depth = self.request.get('editDepth')
        weight = self.request.get('editWeight')
        description = self.request.get('editProductDescription')
        colors = self.request.get('editColors')
        mediums = self.request.get('editMediums')
        masterItemNum = self.request.get('editMasterArtNum')
        pictureName = self.request.get('editProductPhotoName')

        #find related objects to tie to this artpiece
        artistNameList=artistString.split(" ")
        artistFirstName=artistNameList[0]
        artistLastName=artistNameList[-1]
        artist = Artist.query(Artist.firstName==artistFirstName, Artist.lastName==artistLastName).get()
        categories = []
        categoriesList = categoriesString.split(",")
        for categoryString in categoriesList:
            category = Category.query(Category.categoryName==categoryString.strip()).get()
            categories.append(category)
        masterArtPiece = ArtPiece.query(ArtPiece.itemNumber==masterItemNum).get()
        photo = File.query(File.file_name==pictureName.upper()).get()

        #get the artpiece based on the key and update all fields accordingly
        artpiece = ArtPiece.get_by_id(artpieceID)

        artpiece.artist = artist.key
        artpiece.categories = []
        for category in categories:
            artpiece.categories.append(category.key)
        artpiece.colors = colors
        artpiece.depth = depth
        artpiece.description = description
        artpiece.height = height
        artpiece.itemNumber = itemNumber
        if masterArtPiece:
            artpiece.masterArtPiece = masterArtPiece.key
            artpiece.slaveArtFlag = True
            masterArtPiece.masterArtFlag = True
            masterArtPiece.put()
        artpiece.mediums = mediums
        artpiece.name = name
        artpiece.picture = photo.key
        artpiece.price = price
        artpiece.priceDisplay = priceDisplay
        artpiece.uploaded_by=users.get_current_user()
        artpiece.weight = weight
        artpiece.width = width

        artpiece.put()
        artpiece.add_to_search_index()

        message = "Successfully updated artpiece record: " + artpiece.name
        self.response.write(message)
Exemplo n.º 26
0
def listFiles(path):
    qry = File.query(File.path == path)
    results = qry.fetch()
    return results