示例#1
0
def message_check_news(timestamp):
    """Kiểm tra xem có tin nhắn mới kể từ thời điểm timestamp hay không"""
    if (current_user.new_message == 0):
        res = []
    else:
        timestamp = dateutil.parser.parse(timestamp)
        res = current_user.message_r.filter_by(read=False).filter(
            Message.timestamp >= timestamp).limit(
                current_user.new_message).all()
        res = [{
            'id': m.id,
            'user': {
                'uuid':
                m.sender.uuid,
                'name':
                m.sender.name,
                'avatar':
                resized_img_src(m.sender.avatar,
                                width=48,
                                height=48,
                                mode='crop')
            },
            'link': url_for('main.inbox', uuid=m.sender.uuid),
            'timestamp': m.timestamp.isoformat()
        } for m in res]
    return jsonify({'messages': res, 'new_message': current_user.new_message})
示例#2
0
def get_images():
    if request.method == 'POST':
        # check if the post request has 'images_dir' in data
        if 'images_dir' in request.form:
            dir_ = request.form['images_dir']
            images_dir = _create_figures_dir_path(dir_)
            _log_info("Get images list from " + images_dir)
            images = os.listdir(images_dir)
            images = [fn for fn in images if any(fn.endswith(ext) for ext in _allowed_image_extenstions)]
            ret = []
            for img in images:
                img_path = os.path.join(dir_, img)
                img_full_path = os.path.join(car_figures_dir, img_path)
                im = Image.open(img_full_path)
                width, height = im.size
                img_dict = {
                    'width': width,
                    'height': height,
                    'name': img,
                    'path': img_path,
                    'thumb_url': resized_img_src(img_path, width=thumb_widht, height=thumb_height, mode='fit', background=thumb_back),
                    'url': request.host_url + 'get_image?dir=' + dir_ + '&name=' + img
                }
                ret.append(img_dict)
            return json.dumps(ret)
示例#3
0
    def app_info():
        baits = Bait.query.all()
        for b in baits:
            if b.url is not None:
                b.url = resized_img_src(b.url,
                                        _external=True,
                                        width=150,
                                        height=150,
                                        mode='crop',
                                        quality=95)

        colors = Color.query.all()
        for c in colors:
            if c.url is not None:
                c.url = resized_img_src(c.url,
                                        _external=True,
                                        width=150,
                                        height=150,
                                        mode='crop',
                                        quality=95)

        comments = Comment.query.all()
        for cm in comments:
            if cm.file_url is not None:
                cm.file_url = resized_img_src(cm.file_url,
                                              _external=True,
                                              width=150,
                                              height=150,
                                              mode='crop',
                                              quality=95)

        dom = Dom.get_single()
        dom_json = dom.to_json
        dom_json['baits'] = [i.to_json for i in baits]
        dom_json['colors'] = [j.to_json for j in colors]
        dom_json['comments'] = [k.to_json for k in comments]

        json_response = json.dumps(dom_json, ensure_ascii=False)

        response = Response(json_response,
                            content_type="application/json; charset=utf-8")
        return response
示例#4
0
    def prepare_colors():
        colors = Color.query.all()
        for c in colors:
            c.redirect_url = url_for('edit_color', _external=True, id=c.id)
            if c.url:
                c.url = resized_img_src(c.url,
                                        width=40,
                                        height=40,
                                        mode='crop',
                                        quality=95)

        return colors
示例#5
0
    def prepare_baits():
        baits = Bait.query.all()
        for b in baits:
            b.redirect_url = url_for('edit_bait', _external=True, id=b.id)
            if b.url:
                b.url = resized_img_src(b.url,
                                        width=40,
                                        height=40,
                                        mode='crop',
                                        quality=95)

        return baits
def get_images():
    if request.method == 'POST':
        # check if the post request has 'images_dir' in data
        if 'images_dir' in request.form:
            dir_ = request.form['images_dir']
            images_dir = _create_figures_dir_path(dir_)
            _log_info("Get images list from " + images_dir)
            images = os.listdir(images_dir)
            images = [
                fn for fn in images if any(
                    fn.endswith(ext) for ext in _allowed_image_extenstions)
            ]
            ret = []
            for img in images:
                img_path = os.path.join(dir_, img)
                img_full_path = os.path.join(car_figures_dir, img_path)
                im = Image.open(img_full_path)
                width, height = im.size
                img_dict = {
                    'width':
                    width,
                    'height':
                    height,
                    'name':
                    img,
                    'path':
                    img_path,
                    'thumb_url':
                    resized_img_src(img_path,
                                    width=thumb_widht,
                                    height=thumb_height,
                                    mode='fit',
                                    background=thumb_back),
                    'url':
                    request.host_url + 'get_image?dir=' + dir_ + '&name=' + img
                }
                ret.append(img_dict)
            return json.dumps(ret)
示例#7
0
 def todict(self):
     return {'uuid': self.uuid, 'name': self.name, 'avatar': resized_img_src(self.avatar, width=48, height=48, mode='crop'), 'url': url_for('main.user', uuid=self.uuid)}
示例#8
0
def render_uploaded_file_url(filename, **kwargs):
    if filename:
        return resized_img_src(uploads.url(filename), **kwargs)

    return resized_img_src('no-image-icon.png')