Пример #1
0
    def post(self):
        # try:
            upload = self.get_uploads()[0]

            image = Image(author=users.get_current_user().user_id(), blob_key=upload.key())

            image_key = image.put()

            self.redirect('/admin/nameupload/%s' % image_key)
Пример #2
0
    def _get_blog_single(self, par):

        ut = Utils()
        self._build_widgets_single()

        o = self._obj
        # if it is the single blog view and the user is an editor then load up the images for the image select box
        if self._req.sesh().can_edit():
            o['images'] = Image.all().order("-date").fetch(self._conf.IMAGES_VIEWER_COUNT)

        content = Content.get_by_key_name(par[1])
        if content:
            o['data'] = self.copy_bits(content)
        
            # versions for admin - perhaps optimise this out with a isAdmin clause
            o['data'].otherversions = content.contentversion_set
            ov = []
            for c in content.contentversion_set:
                c.nicetime = c.createtime.strftime('%e %b %Y - %H:%M:%S')
                ov.append(c)
            o['data'].otherversions = ov
            
            # what to put in the meta description - needed for singe blog post only
            if content.current.summary:
                o['data'].metadesc = ut.strip_tags(content.current.summary)
            else:
                o['data'].metadesc = o['data'].title
     
            # no paging controls - for a single blog
            o['page'] = {}
            
        else:
            return self._req.notfound()

        self._respond(path='blog-single', obj=self._obj)
Пример #3
0
    def _get_default(self, par):

        obj = {}
        obj['images'] = Image.all().order("-date").fetch(20)
        obj['groups'] = Group.all()

        self._respond(par, obj)
Пример #4
0
    def _get_name_upload(self, par):

        image = Image.get(par[0])
        image.serving_url = images.get_serving_url(image.blob_key, 640)
        image.put()

        self._respond(["nameupload"], image)
Пример #5
0
    def _post_update_images(self, par):

        key = self._pl["key"]
        which = self._pl["which"]
        url = self._pl["url"]
        parcontent = Content.get_by_key_name(key)
        content = parcontent.editing

        if which == "mainimage":
            image = Image.get_by_id(int(url))

            content.mainimage = image
            content.imagepath = None  # so reset the path

            if content.thumb == None:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "thumb":
            content.thumb = url

        elif which == "reset_thumb":
            image = content.mainimage
            if image:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "main_url":
            content.imagepath = url  # so reset the path

        elif which == "thumb_url":
            content.thumb = url  # so reset the path

        content.put()

        # respond with a good code
        self._req.draw_code()
Пример #6
0
    def _post_update_images(self, par):
        
        key = self._pl['key']
        which = self._pl['which']
        url = self._pl['url']
        parcontent = Content.get_by_key_name(key)
        content = parcontent.editing
        
        if which == "mainimage":
            image = Image.get_by_id(int(url))
            
            content.mainimage = image
            content.imagepath = None   # so reset the path    

            if content.thumb == None:
                content.thumb = images.get_serving_url(image.blob_key, 150)

        elif which == "thumb":
            content.thumb = url

        elif which == "reset_thumb":
            image = content.mainimage
            if image:
                content.thumb = images.get_serving_url(image.blob_key, 150) 
            
        content.put()
Пример #7
0
    def _post_name_upload(self, par):
    
        image = Image.get(par[0])
        image.title = self._req.par('image_title')
        image.tag = self._req.par('image_tags')
        image.put()

        self._req.redirect(path='/admin/nameupload/' + str(image.key()))
Пример #8
0
 def get_image(self, par):
     """ called directly from main get router """
     try:
         iid = int(par[0]);
         img = Image.get_by_id(iid)
         if img:
             self._req.redirect(str(img.serving_url))
         else:
             self._req.notfound()
     except:
         self._req.notfound()
Пример #9
0
    def _get_blog_single(self, par):

        ut = Utils()
        self._build_widgets_single()

        o = self._obj
        # if it is the single blog view and the user is an editor then load up the images for the image select box
        if self._req.sesh().can_edit():
            o['images'] = Image.all().order("-date").fetch(self._conf.IMAGES_VIEWER_COUNT)

        content = Content.get_by_key_name(par[1])
        if content:
            if self._req.sesh().can_edit():
                o['data'] = content.editing
            else:
                o['data'] = content.current

            o['data'].ctype = content.ctype
            o['data'].status = content.status
            o['data'].otherversions = content.contentversion_set
            ov = []
            for c in content.contentversion_set:
                c.nicetime = c.createtime.strftime('%e %b %Y - %H:%M:%S')
                ov.append(c)

            o['data'].otherversions = ov
            o['data'].keyname = content.key().name()
            o['data'].group = content.group
     
            # what to put in the meta description 
            if content.current.summary:
                o['data'].metadesc = ut.strip_tags(content.current.summary)
            else:
                o['data'].metadesc = o['data'].title
     
            o['data'].nicedate = content.sortdate.strftime('%e %b %Y')

            # use hard coded imagepath, or the mainimage's url
            if not o['data'].imagepath:
                if o['data'].mainimage:
                    o['data'].imagepath = o['data'].mainimage.serving_url

            # no paging controls - for a single blog
            o['page'] = {}
            
        else:
            return self._req.notfound()

        self._respond(path='blog-single', obj=self._obj)
Пример #10
0
def events(date, seq):
    matchPath = scan(imageRoot, date, seq)
    # use list to allow update with many images on one page
    imgs = [Image(matchPath)]
    return render_template("data.html", imgs = imgs)
Пример #11
0
    def post(self, request, format=None):

        ALLOWED_FORMATS = ['jpeg', 'jpg', 'png', 'svs']

        reqData = request.data
        image_name = reqData.get("image_name")
        image_format = reqData.get("image_format").lower()
        bucket_name = reqData.get("image_data").get("bucketName")
        object_name = reqData.get("image_data").get("objectName")
        user = reqData.get("user")
        is_private = reqData.get("is_private")
        pub_date = reqData.get("pub_date")
        processed = reqData.get("processed")
        preview_url = ''

        if not (image_format in ALLOWED_FORMATS):

            m_status = status.HTTP_403_FORBIDDEN
            msg = "Format not supported"
            data = {"status": m_status, "msg": msg}

            return Response(data=json.dumps(data),
                            status=m_status,
                            content_type='application/json')
        '''
        # TODO: Make Preview images to show
        '''
        preview_path = ""

        # Test if user exists
        if not (Users.objects.all().filter(name=user).exists()):

            m_status = status.HTTP_404_NOT_FOUND
            msg = "User Not Found"
            data = {"status": m_status, "msg": msg}

            return Response(data=json.dumps(data),
                            status=m_status,
                            content_type='application/json')

        else:

            m_user = Users.objects.all().filter(name=user).get()

        # Save to DB
        try:

            if (oid.objects.all().filter(bucket_name=bucket_name).filter(
                    object_name=object_name).exists()):

                m_status = status.HTTP_409_CONFLICT
                msg = "Image already exists"
                data = {"status": m_status, "msg": msg}

                return Response(data=json.dumps(data),
                                status=m_status,
                                content_type='application/json')

            else:

                m_oid = oid(url='192.168.0.162:9000',
                            bucket_name=bucket_name,
                            object_name=object_name)
                m_oid.save()

                if (is_private == "True"):
                    is_private = True
                else:
                    is_private = False

                m_image = Image(image_name=image_name,
                                image_oid=m_oid,
                                preview_url=preview_path,
                                user=m_user,
                                is_private=is_private,
                                pub_date=pub_date,
                                processed=processed)

                try:

                    m_image.save()

                except Exception as e:

                    logger.error(e)

                logger.info('image saved')

                try:

                    if (processed is False):

                        mt = DeepZoomWrapper()
                        mt.put(m_image)
                        mt.process()

                except Exception as e:

                    logger.error(e)

        except Exception as e:

            logger.error(e)
            m_status = status.HTTP_406_NOT_ACCEPTABLE
            msg = "Failed inserting DB"
            data = {"status": m_status, "msg": msg}

            return Response(data=json.dumps(data),
                            status=m_status,
                            content_type='application/json')

        m_status = status.HTTP_201_CREATED
        msg = "Success"
        data = {"status": m_status, "msg": msg}

        return Response(data=json.dumps(data),
                        status=m_status,
                        content_type='application/json')
Пример #12
0
    def updateImage(self, image, imagePath, logger):

        logger.debug("Start sending to minio server")
        minioClient = Minio(
            '192.168.0.162:9000',
            access_key='FM9GO6CT17O8122165HB',
            secret_key='yLyai1DFC03hzN17srK0PvYTIZFvHDnDxRKYAjK4',
            secure=False
        )

        imageName = os.path.splitext(image.image_name)[0] + '.dzi'
        image_oid = image.image_oid
        bucketName = image_oid.bucket_name
        user = image.user
        is_private = image.is_private
        pub_date = image.pub_date
        processed = True
        dataDirPath = os.path.join(
            os.path.split(imagePath)[0],
            os.path.splitext(
                os.path.split(imagePath)[1])[0]+"_files"
        )

        try:
            with open(imagePath, 'rb') as file_data:
                file_stat = os.stat(imagePath)
                minioClient.put_object(
                    bucketName,
                    imageName,
                    file_data,
                    file_stat.st_size,
                    content_type='application/dzi'
                )
                file_data.close()

            logger.info(
                "Starting upload \
recursively to minio server, starting from " +
                dataDirPath)
            self.uploadRecursively(
                minioClient,
                dataDirPath,
                logger,
                os.path.split(dataDirPath)[0],
                bucketName,
                os.path.split(dataDirPath)[1],
                os.path.splitext(imageName)[0]
                )
            logger.info("Successfully sent to minio server")

            logger.info("Copying files to frontend/public/")
            try:
                dir_util.copy_tree(
                    os.path.split(dataDirPath)[0],
                    '/code/frontend_app/deepzoom/' + bucketName)
                logger.info("[DeepZeeomWrapper] Successfully copied files")

            except Exception as e:
                logger.error("Error occured copying files: ")
                logger.error("" + str(e))

            logger.info("Deleting temporary files")
            shutil.rmtree(os.path.split(dataDirPath)[0])
            shutil.rmtree('/code/imageuploader/image_tmp/source/' +
                          os.path.splitext(imageName)[0]
                          )
            logger.info("Successfully \
deleted temporary files")

            logger.info("Start update db")

            try:
                if (oid.objects.all().filter(bucket_name=bucketName)
                        .filter(object_name=imageName).exists()):
                        raise Exception

                else:
                        m_oid = oid(
                            url='192.168.0.162:9000',
                            bucket_name=bucketName,
                            object_name=imageName
                        )
                        m_oid.save()
                        m_user = Users.objects.all().filter(name=user).get()
                        m_image = Image(
                            image_name=imageName,
                            image_oid=m_oid,
                            preview_url="",
                            user=m_user,
                            is_private=is_private,
                            pub_date=pub_date,
                            processed=processed
                        )
                        m_image.save()

                        logger.debug("\
Deleting original image from db")
                        m_image2del = Image.objects.all() \
                            .filter(image_oid__bucket_name=bucketName) \
                            .filter(image_name=image.image_name).get()
                        m_image2del.delete()

                        logger.debug("\
Deleting original image from minio")
                        minioClient.remove_object(bucketName, image.image_name)
                        logger.info("\
Successfully deleted unprocessed image")

            except Exception as e:
                logger.error("[Exception] at DeepZoomWrapper:183 " + e)
                logger.error("Object exists?")

            logger.info("Succesfully updated db")

        except ResponseError as err:
            logger.error("[ResponseError] at DeepZoomWrapper:190 " + err)

        return