Ejemplo n.º 1
0
    def upload_img(self):

        im = ImageManager()
        files = request.files['files']
        media = Media()

        filelist = []
        # sname = str(files)
        # imgsize = im.resize(files, (200, 100, True))
        if files:
            newname = im.generate_name(None, files)
            mpath = config.IMG_UPLOAD_FOLDER + '/' + newname
            im.save_file(files,
                         mpath,
                         thumbnail_size=(75, 50, True),
                         size=(1225, 750, True))
            media.name = newname

            fpath = self.appbuilder.static_url_path + '/uploads/images/' + newname
            files, file_extension = os.path.splitext(fpath)
            th = files + '_thumb' + file_extension

            db.session.add(media)
            db.session.commit()

            size = os.path.getsize(mpath)
            json_display = {
                'name': newname,
                "thumbnailUrl": th,
                'deleteUrl': 'delete/' + newname,
                'size': size
            }
            filelist.append(json_display)

        return simplejson.dumps({"files": filelist})
Ejemplo n.º 2
0
 def _add_files(self, this_request, item: Model):
     fm = FileManager()
     im = ImageManager()
     for file_col in this_request.files:
         if self.is_file(file_col):
             fm.save_file(this_request.files[file_col], getattr(item, file_col))
     for file_col in this_request.files:
         if self.is_image(file_col):
             im.save_file(this_request.files[file_col], getattr(item, file_col))
Ejemplo n.º 3
0
    def add(self):
        ## post with json
        if request.is_json:
            name = request.json.get('name', None)
            login_qrcode_base64 = request.json.get('login_qrcode_base64', None)
            description = request.json.get('description', None)

            if name is None or login_qrcode_base64 is None:
                return self.response_400(message="Request payload is not JSON")

            s = self.datamodel.session
            #datamodel = SQLAInterface(Project)
            #datamodel.session = s

            #filters = datamodel.get_filters()
            #filters.add_filter('name', FilterEqual, name)
            #count, item = datamodel.query(filters=filters, page_size=1)
            #if count:
            #    item = item[0]
            #    pid = item.id
            #    datamodel = SQLAInterface(ProjectFiles)
            #    datamodel.session = s
            #    filters = datamodel.get_filters()
            #    filters.add_filter('project_id', FilterEqual, pid)
            #    count, child = datamodel.query(filters=filters, page_size=1)
            #    child = child[0]

            #else:
            #    item = datamodel.obj()
            #    item.name = name
            #    item.created_by_fk = 1
            #    item.changed_by_fk = 1

            #    datamodel.add(item)

            #    pid = item.id

            #    datamodel = SQLAInterface(ProjectFiles)
            #    datamodel.session = s
            #    child = datamodel.obj()

            datamodel = SQLAInterface(ProjectFiles, s)

            filters = datamodel.get_filters()
            filters.add_filter('name', FilterEqual, name)
            count, item = datamodel.query(filters=filters, page_size=1)
            if count:
                child = item[0]
            else:
                child = datamodel.obj()

            child.name = name
            #child.description = description # description now is line_id for user's
            child.login_qrcode_base64 = login_qrcode_base64
            datamodel.add(child)

        else:
            name = request.form.get('name')

            if not name:
                return self.response_400(message="Missing required parameter")

            if 'file' not in request.files:
                flash('No file part')
                return self.response_400(message="Missing file parameter")
            file = request.files['file']

            if file.filename == '':
                return self.response_400(message="no file select")
            #filename = secure_filename(file.filename)
            #file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            s = self.datamodel.session
            datamodel = SQLAInterface(Project)
            datamodel.session = s
            item = datamodel.obj()
            item.name = name
            item.created_by_fk = 1
            item.changed_by_fk = 1

            datamodel.add(item)
            pid = item.id

            im = ImageManager()
            filename = im.save_file(file, im.generate_name(file, file))

            datamodel = SQLAInterface(ProjectFiles)
            datamodel.session = s
            child = datamodel.obj()
            child.file = filename
            child.project = item
            child.description = request.form.get('description')
            datamodel.add(child)
        #datamodel._add_files(request, item)
        #log.warning("XX", item.id, "VV")

        return self.response(200, message=datamodel.message)