Esempio n. 1
0
def setUserSocial():
    img = request.files.get('img')
    weibo = request.form['weibo']
    if not allowedFileSize(len(img.read()), 1):
        flash(u"请上传小于1M的图片!")
        return redirect(url_for('admin.userInfo'))
    #文件read后,要重样把指针定位到开头
    img.seek(0)
    if img and allowedImage(img.filename):
        try:
            fileName = creatFileName(current_user.id, img.filename)
            img.save(os.path.join(current_app.config['UPLOAD_PATH'], fileName))
            if 'local/images/' not in current_user.custom['weixin']:
                #删除以前的图片
                removeFile(
                    os.path.join(current_app.config['STATIC_PATH'],
                                 current_user.custom['weixin']))
            current_user.custom['weixin'] = current_app.config[
                'UPLOAD_PATH_FOR_DB'] + '/' + fileName
            flash(u"微信二维码修改成功!")
        except:
            flash(u"图片上传失败!")
    flash(u"微博链接修改成功!")
    current_user.custom['weibo'] = weibo
    current_user.save()
    return redirect(url_for('admin.userInfo'))
Esempio n. 2
0
def setUserIcon():
    img = request.files.get('img')
    if not allowedFileSize(len(img.read()), 1):
        flash(u"请上传小于1M的图片!")
        return redirect(url_for('admin.userInfo'))
    #文件read后,要重样把指针定位到开头
    img.seek(0)
    if img and allowedImage(img.filename):
        try:
            fileName = creatFileName(current_user.id, img.filename)
            img.save(os.path.join(current_app.config['UPLOAD_PATH'], fileName))
            if 'local/images/' not in current_user.icon:
                #删除以前的图片
                removeFile(
                    os.path.join(current_app.config['STATIC_PATH'],
                                 current_user.icon))
            current_user.icon = current_app.config[
                'UPLOAD_PATH_FOR_DB'] + '/' + fileName
            current_user.save()
            flash(u"头像修改成功!")
        except:
            flash(u"图片上传失败!")
    else:
        flash(u"请上传png/jpg/gif图片!")
    return redirect(url_for('admin.userInfo'))
Esempio n. 3
0
def photoAlbumPhotoDelete(id):
    p = Photo.objects(id=id).first()
    albumId = p.album.id
    if p.path:
        removeFile(os.path.join(current_app.config['STATIC_PATH'], p.path))
    p.delete()
    flash(u'图像删除成功!')

    p.album.photoCount -= 1
    p.album.save()
    return redirect(url_for('admin.photoAlbumManage', id=albumId))
Esempio n. 4
0
def navigationWebDelete(id,number):
    number = int(number)
    n = Navigation.objects(id=id).first()
    w = n.webs[number]
    #删除图标,先判断是否有图标
    if w.icon:
        removeFile(os.path.join(current_app.config['STATIC_PATH'], w.icon))
    n.webs.remove(w)
    n.save()
    flash(u'网站删除成功!')
    return redirect(url_for('admin.navigationColumnManage', id=id))
Esempio n. 5
0
def navigationWebEdit(id,number):
    number = int(number)
    n = Navigation.objects(id=id).first()
    w = n.webs[number]

    if request.method == 'GET':
        return render_template('admin/navigationWebEdit.html',n=n,w=w,number=number)

    if request.method == 'POST':
        webName = request.form['webName']
        url = request.form['url']
        icon = request.files.get('img')
        introduction = request.form['introduction']

        if not strLength(webName,1,60):
            flash(u'请输入60个字符内的网站名称!')
            return redirect(url_for('admin.navigationColumnManage', id=id))
        if not strLength(url,1,1000):
            flash(u'请输入1000个字符内的网站url!')
            return redirect(url_for('admin.navigationColumnManage', id=id))
        if not url.startswith('http'):
            flash(u'url开头请带上http://或者https://')
            return redirect(url_for('admin.navigationColumnManage', id=id))
        if introduction and not strLength(introduction,1,1000):
            flash(u'请输入1000个字符内的栏目介绍!')
            return redirect(url_for('admin.navigationColumnManage', id=id))

        #其他字段判断完再判断图片上传
        iconPath = None
        if icon and allowedImage(icon.filename):
            if allowedFileSize(len(icon.read()), 1):
                icon.seek(0)
                fileName = creatFileName(current_user.id, icon.filename)
                icon.save(os.path.join(current_app.config['UPLOAD_WEBICON_PATH'], fileName))
                iconPath = current_app.config['UPLOAD_PATH_WEBICON_FOR_DB'] + '/' + fileName
                if w.icon:
                    #删除以前的图片
                    removeFile(os.path.join(current_app.config['STATIC_PATH'], w.icon))
            else:
                flash(u"请上传小于1M的图片!")
                return redirect(url_for('admin.navigationColumnManage', id=id))

        w.webName = webName
        w.url = url
        if introduction:w.introduction=introduction
        else:w.introduction=None
        if iconPath:w.icon=iconPath
        n.webs[number]=w
        n.save()
        flash(u'网站修改成功!')
        return redirect(url_for('admin.navigationColumnManage',id=id))
Esempio n. 6
0
def deleteSlide(index):
    index = int(index)
    if 'local/images/' not in current_user.custom['slide'][index][0]:
        # 删除以前的图片
        removeFile(
            os.path.join(current_app.config['STATIC_PATH'],
                         current_user.custom['slide'][index][0]))
    current_user.custom['slide'][index][0] = None
    current_user.custom['slide'][index][1] = None
    current_user.custom['slide'][index][2] = None
    current_user.custom['slide'][index][3] = None
    current_user.save()
    flash(u"幻灯片删除成功!")
    return redirect(url_for('admin.slideSetting'))
Esempio n. 7
0
def uploadSlide(index):
    index = int(index)
    mainTitle = request.form['mainTitle']
    subTitle = request.form['subTitle']
    link = request.form['link']
    img = request.files.get('img')
    if not allowedFileSize(len(img.read()), 1):
        flash(u"请上传小于1M的图片!")
        return redirect(url_for('admin.slideSetting'))
    #文件read后,要重样把指针定位到开头
    img.seek(0)
    if img and allowedImage(img.filename):
        try:
            fileName = creatFileName(current_user.id, img.filename)
            img.save(os.path.join(current_app.config['UPLOAD_PATH'], fileName))
            if current_user.custom['slide'][index][0] and (
                    'local/images/'
                    not in current_user.custom['slide'][index][0]):
                #删除以前的图片
                removeFile(
                    os.path.join(current_app.config['STATIC_PATH'],
                                 current_user.custom['slide'][index][0]))
            current_user.custom['slide'][index][
                0] = current_app.config['UPLOAD_PATH_FOR_DB'] + '/' + fileName
            current_user.custom['slide'][index][1] = mainTitle
            current_user.custom['slide'][index][2] = subTitle
            current_user.custom['slide'][index][3] = link
            current_user.save()
            flash(u"幻灯片修改成功!")
        except:
            flash(u"图片上传失败!")
    else:
        current_user.custom['slide'][index][1] = mainTitle
        current_user.custom['slide'][index][2] = subTitle
        current_user.custom['slide'][index][3] = link
        current_user.save()
    return redirect(url_for('admin.slideSetting'))