Example #1
0
def receive():
    data = request.data
    data = xmltodict.parse(data)['xml']
    if data['MsgType'] == 'text':
        return send_text(data['FromUserName'], 'hi')
    if data['MsgType'] == 'image':
        token = current_access_token()
        file_url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s' % (token, data['MediaId'])
        file = requests.get(file_url, stream=True).raw
        i = Image()
        i.image = file
        uuid = shortuuid.ShortUUID().random(length=6)
        while Image.objects(iid=uuid):
            uuid = shortuuid.ShortUUID().random(length=6)
        i.iid = uuid
        i.title = data['MediaId']
        i.user = system_user
        i.description = ''
        i.tags = []
        i.save()
        return send_text(
            data['FromUserName'], '업로드 성공, 사진주소:%s%s' % (
                request.url_root[:-1], url_for('light-cms.image', iid=i.iid)
            )
        )
Example #2
0
def drop():
    file = request.files['file']
    i = Image()
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    if login.current_user.is_active():
        i.user = login.current_user._get_current_object()
    else:
        i.user = system_user
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid)
Example #3
0
def drop():
    file = request.files['file']
    i = Image()
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    if login.current_user.is_active():
        i.user = login.current_user._get_current_object()
    else:
        i.user = system_user
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid)
Example #4
0
def gallery_drop(gid):
    if not login.current_user.is_active():
        flash('앨범기능엔 로그인이 필요합니다')
        return redirect(url_for('light-cms.user_login'))
    g = Gallery.objects.get_or_404(gid=gid)
    file = request.files['file']
    i = Image()
    i.gallery.append(g)
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    i.user = login.current_user._get_current_object()
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid)
Example #5
0
def gallery_drop(gid):
    if not login.current_user.is_active():
        flash('请登录后再搞相册哦~')
        return redirect(url_for('light-cms.user_login'))
    g = Gallery.objects.get_or_404(gid=gid)
    file = request.files['file']
    i = Image()
    i.gallery.append(g)
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    i.user = login.current_user._get_current_object()
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid)
Example #6
0
def receive():
    data = request.data
    data = xmltodict.parse(data)['xml']
    if data['MsgType'] == 'text':
        return send_text(data['FromUserName'], 'hi')
    if data['MsgType'] == 'image':
        token = current_access_token()
        file_url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s' % (
            token, data['MediaId'])
        file = requests.get(file_url, stream=True).raw
        i = Image()
        i.image = file
        uuid = shortuuid.ShortUUID().random(length=6)
        while Image.objects(iid=uuid):
            uuid = shortuuid.ShortUUID().random(length=6)
        i.iid = uuid
        i.title = data['MediaId']
        i.user = system_user
        i.description = ''
        i.tags = []
        i.save()
        return send_text(
            data['FromUserName'], '上传成功!图片地址:%s%s' %
            (request.url_root[:-1], url_for('light-cms.image', iid=i.iid)))