Exemple #1
0
def del_post_imgs(str):
    soup = BeautifulSoup(str)
    imgs = soup.findAll("img")
    if imgs:
        for img in imgs:
            img_url = img['src']
            key = img_url.rsplit('/', 1)[-1]
            img_del({'bucket': config['upload'].IMG_B, 'key': key})
Exemple #2
0
def delete_img():

    form_del = ImgDelForm()
    if form_del.submit.data:
        url_list = request.form.getlist("boolean")
        id_len = len(url_list)
        op_type = form_del.op_type.data
        if op_type == 'delete':
            for url in url_list:
                url = eval(url)
                if url == 'y':
                    id_len -= 1
                    continue
                mdb_sys.db.img.remove({'url': url})
                img_del(url)
            flash({'msg': u'删除了{}张图片'.format(id_len), 'type': 's'})

        return redirect(url_for('media.image', project=form_del.q.data))
    abort(404)
Exemple #3
0
def sys_edit_img_log_claer(str, post_id=None, post_title=None):

    soup = BeautifulSoup(str, 'lxml')
    imgs = soup.findAll("img")
    log = mdb_sys.db.edit_img_log.find_one({
        'user_id':
        current_user.id,
        '$or': [{
            'case_id': 0
        }, {
            'case_id': {
                '$exists': False
            }
        }]
    })
    case_log = {}
    if post_id:
        case_log = mdb_sys.db.edit_img_log.find_one({
            'user_id':
            current_user.id,
            'case_id':
            ObjectId(post_id)
        })
    if log:
        p_urls = []
        for img in imgs:
            img_url = img['src']
            p_urls.append(img_url)

            img['class'] = "img-post-ud"
            img['alt'] = "文章图片"
            img['data-tag'] = "sharePhoto"
            del img['title']

        # user add post img log ------------------------------------------------------------
        log_urls = log['urls'][:]
        for l_url in log_urls:
            if not l_url in p_urls:
                # 如过这张图片不在文章里面,这删除
                key = l_url.rsplit('/', 1)[-1]
                img_del({'bucket': config['upload'].IMG_B, 'key': key})
            log['urls'].remove(l_url)
        mdb_sys.db.edit_img_log.update({'user_id': current_user.id},
                                       {'$set': {
                                           'urls': log['urls']
                                       }})

        # user edit post img log -----------------------------------------------------------
        if case_log:
            case_urls = case_log['urls'][:]
            for l_url in case_urls:
                if not l_url in p_urls:
                    # 如过这张图片不在文章里面,这删除
                    key = l_url.rsplit('/', 1)[-1]
                    img_del({'bucket': config['upload'].IMG_B, 'key': key})
            # remove case img log
            mdb_sys.db.edit_img_log.remove({
                'user_id': current_user.id,
                'case_id': ObjectId(post_id)
            })

    # a
    if post_title != u"友情链接":
        tag_a = soup.findAll("a")
        for a in tag_a:
            a['rel'] = "nofollow"
    soup = post_filter(soup)
    return unicode(soup)
Exemple #4
0
def reward_edit(type):
    view_data = {'title': '打赏设置-{}'.format(config['title'].TITLE)}
    profile = mdb_user.user_profile.find_one_or_404(
        {'user_id': current_user.id})
    form = EditRewardForm('edit')
    if form.submit.data:
        if current_user.verify_password(form.password.data):
            bucket_name = {
                'b': config['upload'].IMG_B,
                'domain': 'img',
                'project': 'pay'
            }
            uploaded_files = request.files.getlist("payimg")
            r = img_up(uploaded_files, bucket_name)
            if r['url'] != -1 and r['url'] != 1:
                img_del(profile['pay'][type.strip()]['url'])
                if 'pay' in profile:
                    _pay = profile['pay']
                    _pay[type.strip()] = {
                        'url': r['url'],
                        'word': form.word.data.strip(),
                        'status': 0,
                        'time': time.time()
                    }
                else:
                    _pay = {
                        type.strip(): {
                            'url': r['url'],
                            'word': form.word.data.strip(),
                            'status': 0,
                            'time': time.time()
                        }
                    }
                flash({'msg': '修改了二维码,需要等待审核!', 'type': 's'})
            else:
                if 'pay' in profile:
                    _pay = profile['pay']
                    status = _pay[type.strip()]['status']
                    _pay[type.strip()] = {
                        'url': _pay[type.strip()]['url'],
                        'word': form.word.data.strip(),
                        'status': status
                    }
                else:
                    _pay = {
                        type.strip(): {
                            'url': '',
                            'word': form.word.data.strip(),
                            'status': 0
                        }
                    }
            _pay[type.strip()]['use'] = int(form.nonuse.data)
            _pay[type.strip()]['time'] = time.time()
            mdb_user.user_profile.update({'user_id': current_user.id},
                                         {'$set': {
                                             'pay': _pay
                                         }})
            return redirect(url_for('online.reward'))
        else:
            flash({'msg': '登录密码不对!', 'type': 'e'})

    form.pay_type.data = type.strip()
    form.word.data = profile['pay'][type.strip()]['word']
    form.nonuse.data = str(profile['pay'][type.strip()]['use'])
    view_data['pay_url'] = profile['pay'][type.strip()]['url']
    view_data['op_type'] = 'edit'
    return render_template('online/user/reward_edit.html',
                           view_data=view_data,
                           form=form)
Exemple #5
0
def user_edit_profile(uploaded_files, username, sex, addr, info):
    _data = {}
    domain = None
    if 'u-domain' in request.value.all and request.value.all['u-domain'].strip():
        names = mdb_sys.db.audit_rules.find_one({'type':'username'})
        domain = request.value.all['u-domain'].strip().replace(' ','')
        if len(domain)<3 or len(domain)>30:
            flash({'msg':'个性域名:需要3至30个字符!', 'type':'w'})
            return jsonify(_data)
        if not re.search(r"^[a-z0-9]+$",domain):
            flash({'msg':'个性域名:只能是数字, 小写字母!', 'type':'w'})
            return jsonify(_data)

        elif mdb_user.db.user_profile.find_one({'domain':domain}) or domain==str(current_user.id):
            flash({'msg':'此个性域名已被使用!', 'type':'w'})
            return jsonify(_data)
        elif domain in names and not current_user.can(Permission.ADMINISTER) and not current_user.is_role(Permission.ECP):
            flash({'msg':'此个性域名已被使用!', 'type':'w'})
            return jsonify(_data)

    if not username:
        flash({'msg':'名号不能为空!', 'type':'w'})
        return jsonify(_data)

    user = mdb_user.db.user.find_one({"username":username})
    if user and user["_id"] != current_user.id:
        flash({'msg':'此名号已被使用!', 'type':'w'})
        return jsonify(_data)

    names = mdb_sys.db.audit_rules.find_one({'type':'username'})
    try:
        t_username = username.upper()
    except:
        t_username = username
    if t_username in names['rule'] and not current_user.can(Permission.ADMINISTER) and not current_user.is_role(Permission.ECP):
        flash({'msg':'此名号已被使用!', 'type':'w'})
        return jsonify(_data)

    if len(username.encode("gbk").decode("gbk")) > 150:
        flash({'msg':u'最多150字哦!','type':'w'})
        return jsonify(_data)

    # ---------------------------------------------------------------
    tel = ""

    # 地址
    _provinces = ''
    _city = ''
    _area = ''
    addrs = addr_f()
    if addr['p'].strip("string:"):
        for lv in addrs:
            if lv['id'] == addr['p'].strip("string:"):
                lv1 = lv
                _provinces = lv['text']
                break
    if addr['c'].strip("string:"):
        for lv in lv1['children']:
            if lv['id'] == addr['c'].strip("string:"):
                lv2 = lv
                _city = lv['text']
                break
    if addr['a'].strip("string:"):
        for lv in lv2['children']:
            if lv['id'] == addr['a'].strip("string:"):
                _area = lv['text']
                break
    addr = {"provinces":_provinces}
    addr['city'] = _city
    addr['area'] = _area
    #性别
    if sex:
        sex = int(sex)
    # 头像
    bucket_name = {'b':config['upload'].AVA_B, 'domain':'avatar', 'project':'avatar'}
    r = img_up(uploaded_files, bucket_name)
    if r['url'] != -1:
        if r['url'] == 1:
            user_profile = {
            'username':username,
            'addr':addr,
            'info':info,
            'tel_num':tel,
            'sex':sex
            }
        else:
            user_profile = {
                'username':username,
                'addr':addr,
                'info':info,
                'tel_num':tel,
                'sex':sex,
                'avatar_url':r['url']
            }
            u_p = mdb_user.db.user_profile.find_one({'user_id':current_user.id})
            if u_p:
                if not 'default' in u_p['avatar_url']['key']:
                    img_del(u_p['avatar_url'])
        flash({'msg':'头像更改成功,2秒后更新!.','type':'s'})
    else:
        user_profile = {
            'username':username,
            'addr':addr,
            'info':info,
            'tel_num':tel,
            'sex':sex
            }

    mdb_user.db.user.update({"_id":current_user.id}, {"$set":{"username":username}})
    if domain:
        user_profile['user_domain'] = domain
        user.domain = domain
    mdb_user.db.user_profile.update({'user_id':current_user.id}, {'$set':user_profile})
    flash({'msg':'信息修改成功哦.','type':'s'})

    return _data
Exemple #6
0
def edit_img(id):

    view_data = {'op_type': 'edit', 'title': '编辑图片信息'}
    form = EditImgForm()
    view_data['img'] = mdb_sys.db.img.find_one_or_404({'_id': ObjectId(id)})
    if form.submit.data:
        if not form.name.data.strip():
            flash({'type': 'w', 'msg': '名字不能为空!'})
        else:
            uploaded_files = request.files.getlist("img")
            bucket_name = {
                'b': app_config['upload'].IMG_B,
                'domain': 'img',
                'project': form.project.data
            }

            if uploaded_files[0]:
                img_del(view_data['img']['url'])
            r = img_up(uploaded_files,
                       bucket_name,
                       new_name=form.name.data.strip())
            if r['url'] != -1 and r['url'] != 1:
                img_profile = {
                    'url': r['url'],
                    'time': time.time(),
                    'name': form.name.data.strip(),
                    'showname': form.showname.data.strip(),
                    'info': form.info.data,
                    'link': form.link.data.strip()
                }
                mdb_sys.db.img.update({'_id': ObjectId(id)},
                                      {'$set': img_profile})
                flash({'msg': '成功.', 'type': 's'})

            else:
                url = view_data['img']['url']
                if form.name.data.strip() != view_data['img']['name']:
                    new_url = img_rename(url, form.name.data.strip())
                else:
                    new_url = url
                img_profile = {
                    'url': new_url,
                    'time': time.time(),
                    'name': form.name.data.strip(),
                    'showname': form.showname.data.strip(),
                    'info': form.info.data,
                    'link': form.link.data.strip()
                }
                mdb_sys.db.img.update({'_id': ObjectId(id)},
                                      {'$set': img_profile})

            return redirect(
                url_for('media.image', project=view_data['img']['type']))

    form.name.data = view_data['img']['name']
    form.project.data = view_data['img']['type']
    form.showname.data = view_data['img']['showname']
    form.info.data = view_data['img']['info']
    form.link.data = view_data['img']['link']
    return render_template('{}/media/image/add_img.html'.format(
        Theme.ADM_THEME_NAME),
                           form=form,
                           view_data=view_data)