Beispiel #1
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'))
Beispiel #2
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'))
Beispiel #3
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))
Beispiel #4
0
def photoAlbumPhotoAdd():
    albumId = request.form['albumId']
    if not albumId:
        flash(u'请先添加相册!')
        return redirect(url_for('admin.photoAlbum'))
    pa = Album.objects(id=albumId).first()
    introduction = request.form['introduction']

    if len(introduction) > 1000:
        flash(u'请输入1000个字符内的图片描述!')
        return redirect(url_for('admin.photoAlbum'))

    p = Photo()
    p.introduction = introduction

    photo = request.files.get('photo')
    #其他字段判断完再判断图片上传
    photoPath = None
    if photo and allowedImage(photo.filename):
        if allowedFileSize(len(photo.read()), 2):
            photo.seek(0)
            p.title = photo.filename[:50]
            fileName = creatFileName(current_user.id, photo.filename)
            photo.save(
                os.path.join(current_app.config['UPLOAD_PHOTOALBUM_PATH'],
                             fileName))
            photoPath = current_app.config[
                'UPLOAD_PATH_PHOTOALBUM_FOR_DB'] + '/' + fileName
        else:
            flash(u"请上传小于2M的图片!")
            return redirect(url_for('admin.photoAlbum'))
    else:
        flash(u"请上传png/jpg/gif图片")
        return redirect(url_for('admin.photoAlbum'))
    p.path = photoPath

    p.album = pa
    p.save()

    pa.photoCount += 1
    pa.save()
    flash(u'图像添加成功!')
    return redirect(url_for('admin.photoAlbum'))
Beispiel #5
0
def navigationWebAdd(id):
    n = Navigation.objects(id=id).first()

    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
        else:
            flash(u"请上传小于1M的图片!")
            return redirect(url_for('admin.navigationColumnManage', id=id))

    w = Web()
    w.webName = webName
    w.url = url
    if introduction:w.introduction=introduction
    if iconPath:w.icon=iconPath
    n.webs.append(w)
    n.save()
    flash(u'网站添加成功!')
    return redirect(url_for('admin.navigationColumnManage',id=id))
Beispiel #6
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'))