Exemplo n.º 1
0
def image_ajx_list():
    page = int(request.args.get('page', 1))
    per_page = int(request.args.get('per_page', 10))
    target_id = request.args.get('target_id', '')
    asset_type = int(request.args.get('asset_type', 2))
    cover_id = request.args.get('cover_id', '')

    meta = {}
    query = {}
    if target_id:
        query['target_id'] = target_id
    query['asset_type'] = asset_type
    query['deleted'] = 0

    try:
        data = Image.objects(**query).order_by('-created_at').paginate(
            page=page, per_page=per_page)
        total_count = Image.objects(**query).count()

        # 过滤数据
        fields = []
        for i, d in enumerate(data.items):
            thumb_dict = d.get_thumb_path()
            thumb_url = ''
            is_cover = False
            if cover_id == str(d._id):
                is_cover = True
            if thumb_dict:
                thumb_url = thumb_dict['sm']
            field = {
                '_id': str(d._id),
                'name': d.name,
                'path': d.path,
                'img_url': d.img_url,
                'asset_type': d.asset_type,
                'domain': d.domain,
                'is_cover': is_cover,
            }
            if thumb_url:
                field['thumb_url'] = thumb_url
            elif d.img_url:
                field['thumb_url'] = d.img_url

            fields.append(field)

        meta['rows'] = fields
    except (Exception) as e:
        meta['rows'] = []
        total_count = 0

    meta['total_count'] = total_count
    meta['page'] = page
    meta['per_page'] = per_page

    return jsonify(code=0, message='success!', data=meta)
Exemplo n.º 2
0
    def cover(self):
        if self.cover_id and len(self.cover_id) == 24:
            image = Image.objects(_id=ObjectId(self.cover_id)).first()
            if image and image.deleted == 0:
                return image

        image = Image.objects(target_id=str(self._id), asset_type=2,
                              deleted=0).first()
        if image and image.deleted == 0:
            return image

        return None
Exemplo n.º 3
0
def image_list():

    query = {}
    meta = {}
    page = int(request.args.get('page', 1))
    per_page = int(request.args.get('per_page', 100))
    status = int(request.args.get('status', 0))
    deleted = int(request.args.get('deleted', 0))
    name = request.args.get('name', '')

    if name:
        query['name'] = name

    if in_grap:
        if in_grap == -1:
            query['in_grap'] = 0
        else:
            query['in_grap'] = in_grap

    if out_grap:
        if out_grap == -1:
            query['out_grap'] = 0
        else:
            query['out_grap'] = out_grap

    if status == -1:
        query['status'] = 0
    if status == 1:
        query['status'] = 1
    else:
        pass

    query['deleted'] = deleted

    try:
        data = Image.objects(**query).order_by('-created_at').paginate(
            page=page, per_page=per_page)
        total_count = Image.objects(**query).count()

        # 过滤数据
        for i, d in enumerate(data.items):
            data.items[i]._id = str(d._id)

        meta['rows'] = data.items
    except (Exception) as e:
        meta['rows'] = []
        total_count = 0

    meta['total_count'] = total_count
    meta['page'] = page
    meta['per_page'] = per_page

    return jsonify(code=0, message='success!', data=meta)
Exemplo n.º 4
0
def insert_data():
    query = {}
    page = 1
    per_page = 100
    is_end = False
    total = 1
    while not is_end:
        # 倒序
        data = Image.objects(**query).order_by('created_at').paginate(
            page=page, per_page=per_page)
        if not len(data.items):
            print("get data is empty! \n")
            break
        for i, image in enumerate(data.items):
            obj = ElasticObj()
            obj.create_index()
            print(type(image))
            # image['id'] = str(image['_id'])
            # image.pop('_id')
            # obj.post_index_data(image)
        total += 1
        print("current page %s: \n" % page)
        page += 1
        if len(data.items) < per_page:
            is_end = True
    print("is over execute count %s\n" % total)
Exemplo n.º 5
0
def save_data(design_case):
    image = Image.objects(img_url=design_case.cover_url).first()
    if image:
        print('此作品已存在素材库,添加失败,失败作品_id', str(design_case._id))
    elif design_case.prize_label == '红星奖':
        image = Image()
        image.title = design_case.title  # 标题
        image.tags = design_case.tags  # 标签
        image.img_url = design_case.cover_url  # 图片地址
        image.designer = design_case.designer_name  # 设计者姓名
        # company = DesignCompany.objects(number=design_case.target_id).first()  # 公司
        if design_case.company_name:
            image.company = design_case.company_name  # 公司姓名
        elif design_case.en_company_name:
            image.company = design_case.en_company_name  # 公司姓名
        image.kind = 1  #类型
        # image.brand_id =  #品牌id
        #d = prize_options(design_case.prize_label)  # 获取奖项id和名称的字典映射
        image.prize_id = 4  # 奖项ID
        image.prize = design_case.prize_label  # 奖项名称
        image.prize_level = design_case.prize_level  # 奖项级别
        image.prize_time = design_case.award_time  # 奖项时间
        image.channel = 'opalus_design_case'
        image.evt = 1
        # 保存数据到素材库
        ok = True
        #ok = image.save()
        if not ok:
            print("保存成功: %s" % design_case.prize_label)
        else:
            print("保存失败: %s" % str(design_case._id))

        print('作品以成功转入素材库,成功作品_id', str(design_case._id))
    else:
        print("作品奖项不匹配: %s" % str(design_case._id))
Exemplo n.º 6
0
def image_view():
    meta = metaInit.copy()

    id = request.args.get('id', None)
    if not id:
        flash('ID不存在!', 'warning')
        return redirect(url_for('main.image_index'))

    if not len(id) == 24:
        flash('ID非法!', 'warning')
        return redirect(url_for('main.image_index'))

    image = Image.objects(_id=ObjectId(id)).first()

    if not image:
        flash('内容不存在!', 'warning')
        return redirect(url_for('main.image_index'))

    if image.deleted == 1:
        flash('内容已删除!', 'warning')
        return redirect(url_for('main.image_index'))

    # image = tranform

    meta['title'] = "%s-素材库" % image['title']
    return render_template('image/view.html',
                           meta=meta,
                           form=t_image_view(image))
Exemplo n.º 7
0
def produce_submit():
    ok = False
    form = SaveApi(request.values)
    if not form.validate_on_submit():
        return jsonify(code=3004, message=str(form.errors))
    data = request.values.to_dict()
    if not data:
        return jsonify(code=3003, message='至少传入一个参数!')
    try:
        if not (data['title'] and data['channel']):
            return jsonify(code=3003, message='标题和渠道为必填')
        if not data['img_urls']:
            return jsonify(code=3003, message='img_urls为空')
        produce = Produce.objects(title=data['title'],
                                  channel=data['channel']).first()
        if not produce:
            produce_data = data.copy()
            produce_data.pop('img_urls')
            produce = Produce(**produce_data)
            produce.save()
        else:
            # if produce.editor_id != 0:
            if produce.editor_id == 0:
                produce_data = data.copy()
                produce_data.pop('img_urls')
                ok = produce.update(**produce_data)
                if not ok:
                    return jsonify(code=3003, message='产品更新失败')
        img_urls = data['img_urls'].split(',')

        for i, img_url in enumerate(img_urls):
            img_data = {}
            img_data['title'] = data['title']
            img_data['img_url'] = img_url
            img_data['channel'] = data['channel']
            img_data['url'] = data['url']
            img_data['target_id'] = str(produce._id)
            img = Image.objects(img_url=img_url).first()
            if not img:
                img = Image(**img_data)
                ok = img.save()
            else:
                ok = img.update(target_id=str(produce._id))
            if i == 0:
                if not produce.cover_id:
                    ok = produce.update(cover_id=str(img._id))

        if ok:
            return jsonify(code=0, message='success!', data=produce)
        else:
            return jsonify(code=3010, message='操作失败!')

    except (Exception) as e:
        return jsonify(code=3011, message=str(e))
Exemplo n.º 8
0
def image_submit():
    meta = metaInit.copy()
    id = request.args.get('id', None)
    meta['data'] = None
    if id:
        item = Image.objects(_id=ObjectId(id)).first()
        item._id = str(item._id)
        item.thumb = item.get_thumb_path()
        item.tags_s = ','.join(item.tags)
        item.color_tags_s = ','.join(item.color_tags)
        item.brand_tags_s = ','.join(item.brand_tags)
        item.material_tags_s = ','.join(item.material_tags)
        item.style_tags_s = ','.join(item.style_tags)
        item.technique_tags_s = ','.join(item.technique_tags)
        item.other_tags_s = ','.join(item.other_tags)
        item.color_ids_s = ','.join(item.color_ids)
        meta['data'] = item

    form = SaveForm()

    meta['default_tags'] = re.split('[,,]', get_block_content('default_tags'))
    meta['default_color_tags'] = re.split(
        '[,,]', get_block_content('default_color_tags'))
    meta['default_brand_tags'] = re.split(
        '[,,]', get_block_content('default_brand_tags'))
    meta['default_material_tags'] = re.split(
        '[,,]', get_block_content('default_material_tags'))
    meta['default_style_tags'] = re.split(
        '[,,]', get_block_content('default_style_tags'))
    meta['default_technique_tags'] = re.split(
        '[,,]', get_block_content('default_technique_tags'))
    meta['default_other_tags'] = re.split(
        '[,,]', get_block_content('default_other_tags'))

    meta['prize_options'] = prize_options()

    categories = Category.objects(kind=2, status=1, deleted=0)[:20]
    meta['categories'] = categories

    # 获取品牌列表
    brands = Brand.objects(status=1, deleted=0)[:1000]
    meta['brands'] = brands

    meta['referer_url'] = request.environ.get(
        'HTTP_REFERER') if request.environ.get('HTTP_REFERER') else url_for(
            'admin.image_list')

    return render_template('admin/image/submit.html', meta=meta, form=form)
Exemplo n.º 9
0
def image_ajx_del():
    id = request.args.get('id', '')
    if not id:
        return jsonify(code=500, message='缺少请求参数!')

    try:
        asset = Image.objects(_id=ObjectId(id)).first()
        if not asset:
            return jsonify(code=500, message='内容不存在!')
        if not g.is_edit:
            return jsonify(code=500, message='没有权限!')

        ok = asset.mark_delete()
        return jsonify(code=0, message='success')
    except (Exception) as e:
        return jsonify(code=500, message=str(e))
Exemplo n.º 10
0
def image_update():

    page = 1
    perPage = 100
    isEnd = False
    successStatCount = 0
    failStatCount = 0
    query = {}
    # query['deleted'] = 0
    # query['kind'] = 1
    # query['channel'] = 'a-four'
    query['channel'] = 'thecool'
    #query['status'] = 1
    #query['channel'] = 'g_mark'
    #query['total_tags'] = '女装'

    while not isEnd:
        data = Image.objects(**query).order_by('-created_at').paginate(
            page=page, per_page=perPage)
        if not data:
            print("get data is empty! \n")
            continue

        # 过滤数据
        for i, d in enumerate(data.items):

            #img_url = d.img_url.strip()
            #if d.channel == 'g_mark':
            #r = random.randint(1000000, 9999999)
            if True:
                # if not d.img_url.startswith('http'):
                #     ok = d.update(img_url='http://www.a-fourdesign.com'+d.img_url)
                ok = True
                ok = d.update(channel='chinagood')
                #ok = d.update(random=r)
                if ok:
                    successStatCount += 1
                else:
                    failStatCount += 1

        print("current page %s: \n" % page)
        page += 1
        if len(data.items) < perPage:
            isEnd = True

    print("is over execute SuccessCount %d ---- failCount: %d\n" %
          (successStatCount, failStatCount))
Exemplo n.º 11
0
def image_submit():
    meta = metaInit.copy()
    id = request.args.get('id', None)
    meta['data'] = None
    if id:
        item = Image.objects(_id=ObjectId(id)).first()
        item._id = str(item._id)
        item.thumb = item.get_thumb_path()
        item.tags_s = ','.join(item.tags)
        meta['data'] = item

    form = SaveForm()

    meta['referer_url'] = request.environ.get(
        'HTTP_REFERER') if request.environ.get('HTTP_REFERER') else ''

    return render_template('admin/image/submit.html', meta=meta, form=form)
Exemplo n.º 12
0
 def loop(self, *args, **kwargs):
     query = {}
     query['path'] = ''
     query['deleted'] = 0
     query['kind'] = 1
     while not self.is_end:
         # 倒序
         data = Image.objects(**query).order_by('created_at').paginate(
             page=self.page, per_page=self.per_page)
         if not len(data.items):
             print("get data is empty! \n")
             break
         for i, image in enumerate(data.items):
             func(self, image)
         print("current page %s: \n" % self.page)
         self.page += 1
         if len(data.items) < self.per_page:
             self.is_end = True
     print("is over execute count %s\n" % self.total)
Exemplo n.º 13
0
 def loop(*args, **kwargs):
     page = 1
     per_page = 100
     is_end = False
     total = 0
     query = {}
     while not is_end:
         data = Image.objects(**query).paginate(page=page, per_page=per_page)
         if not len(data.items):
             print("get data is empty! \n")
             break
         for i, image in enumerate(data.items):
             if image.target_id:
                 continue
             func(image)
         print("current page %s: \n" % page)
         page += 1
         total += 1
         if len(data.items) < per_page:
             is_end = True
     print("is over execute count %s\n" % total)
Exemplo n.º 14
0
def image_index():
    meta = metaInit.copy()
    query = {
        'stick': 1,
        'status': 1,
        'deleted': 0,
    }
    stickList = Image.objects(**query).order_by('-stick_on')[:4]
    # 过滤数据
    sticks = []
    for i, d in enumerate(stickList):
        row = {
            '_id': str(d._id),
            'title': d.title,
            'thumb': d.get_thumb_path(),
        }
        sticks.append(row)
    meta['sticks'] = sticks

    meta['index_home_slide'] = get_column('image_index_slider', 10)
    meta['image_home_fine'] = get_column('image_home_fine', 3)
    meta['image_home_special'] = get_column('image_home_special', 2)
    return render_template('image/index.html', meta=meta)
Exemplo n.º 15
0
def image_set_stick():
    meta = metaInit.copy()

    id = request.values.get('id', '')
    evt = request.values.get('evt', 1)
    if not id:
        return jsonify(success=False, message='缺少请求参数!')

    try:
        image = Image.objects(_id=ObjectId(id)).first()
        if not image:
            return jsonify(success=False, message='对象不存在!')
        image.mark_stick(evt=evt) if image else None
    except (Exception) as e:
        return jsonify(success=False, message=str(e))

    return jsonify(success=True,
                   message='操作成功!',
                   data={
                       'id': id,
                       'evt': evt
                   },
                   redirect_to=url_for('admin.image_list'))
Exemplo n.º 16
0
def image_recovery():
    meta = {}

    ids = request.values.get('ids', '')
    type = request.values.get('type', 1)
    if not ids:
        return jsonify(success=False, message='缺少请求参数!')

    try:
        arr = ids.split(',')
        for d in arr:
            item = Image.objects(_id=ObjectId(d)).first()
            item.mark_recovery() if item else None
    except (Exception) as e:
        return jsonify(success=False, message=str(e))

    return jsonify(success=True,
                   message='操作成功!',
                   data={
                       'ids': ids,
                       'type': type
                   },
                   redirect_to=url_for('admin.image_list'))
Exemplo n.º 17
0
 def assets(self):
     assets = Image.objects(target_id=str(self._id),
                            asset_type=2,
                            deleted=0)[:20]
     return assets
Exemplo n.º 18
0
def image_list():
    meta = metaInit.copy()
    query = {}
    page = force_int(request.args.get('page', 1))
    per_page = force_int(request.args.get('per_page', 100))
    status = force_int(request.args.get('status', 0))
    deleted = force_int(request.args.get('deleted', 0))
    kind = force_int(request.args.get('kind', 0))
    prize_id = force_int(request.args.get('prize_id', 0))
    site_mark = request.args.get('site_mark', '')

    t = force_int(request.args.get('t', 1), 1)
    q = request.args.get('q', '')

    if q:
        if t == 1:
            query['_id'] = ObjectId(q.strip())
        if t == 2:
            query['channel'] = q.strip()
        if t == 3:
            query['evt'] = force_int(q.strip())

    if prize_id:
        query['prize_id'] = prize_id

    if kind:
        if kind == 1:
            meta['css_design'] = 'active'
        elif kind == 5:
            meta['css_fashion'] = 'active'
        meta['css_all'] = ''
        query['kind'] = kind

    if status == -1:
        query['status'] = 0
    if status == 1:
        query['status'] = 1
    else:
        pass

    if deleted == 1:
        query['deleted'] = 1
        meta['css_deleted'] = 'active'
    else:
        query['deleted'] = 0
    if site_mark:
        query['channel'] = site_mark
    if not kind and not deleted:
        meta['css_all'] = 'active'
    else:
        meta['css_all'] = ''

    page_url = url_for('admin.image_list',
                       page="#p#",
                       q=q,
                       t=t,
                       prize_id=prize_id,
                       site_mark=site_mark,
                       kind=kind,
                       status=status,
                       deleted=deleted)

    data = Image.objects(**query).order_by('-created_at').paginate(
        page=page, per_page=per_page)
    total_count = Image.objects(**query).count()
    site_list = Site.objects(kind=1, status=1, deleted=0)
    # 过滤数据
    rows = t_image_list(data)

    meta['data'] = rows
    meta['total_count'] = total_count
    meta['prize_options'] = prize_options()
    meta['site_list'] = site_list
    pager = Pager(page, per_page, total_count, page_url)
    meta['pager'] = pager.render_view()

    return render_template('admin/image/list.html', meta=meta)
Exemplo n.º 19
0
def image_list():
    meta = metaInit.copy()
    query = {}
    page = force_int(request.args.get('page', 1))
    per_page = force_int(request.args.get('per_page', 100))
    status = force_int(request.args.get('status', 0))
    deleted = force_int(request.args.get('deleted', 0))
    kind = force_int(request.args.get('kind', 0))

    t = force_int(request.args.get('t', 1), 1)
    q = request.args.get('q', '')

    if q:
        if t == 1:
            query['id'] = force_int(q.strip())
        if t == 2:
            query['name'] = {"$regex": q.strip()}

    if kind:
        if kind == 1:
            meta['css_industry'] = 'active'
        elif kind == 2:
            meta['css_plane'] = 'active'
        meta['css_all'] = ''
        query['kind'] = kind

    if status == -1:
        meta['css_disable'] = 'active'
        query['status'] = 0
    if status == 1:
        query['status'] = 1
        meta['css_enable'] = 'active'
    else:
        pass

    if deleted == 1:
        query['deleted'] = 1
        meta['css_deleted'] = 'active'
    else:
        query['deleted'] = 0

    if not status and not deleted:
        meta['css_all'] = 'active'
    else:
        meta['css_all'] = ''

    page_url = url_for('admin.image_list',
                       page="#p#",
                       q=q,
                       t=t,
                       kind=kind,
                       status=status,
                       deleted=deleted)

    data = Image.objects(**query).order_by('-created_at').paginate(
        page=page, per_page=per_page)
    total_count = Image.objects(**query).count()

    # 过滤数据
    for i, d in enumerate(data.items):
        data.items[i]._id = str(d._id)
        data.items[i].thumb = d.get_thumb_path()
        if d.tags:
            data.items[i].tags_s = ','.join(d.tags)

    meta['data'] = data.items

    pager = Pager(page, per_page, total_count, page_url)
    meta['pager'] = pager.render_view()

    return render_template('admin/image/list.html', meta=meta)
Exemplo n.º 20
0
def image_list():
    meta = metaInit.copy()
    query = {}
    page = force_int(request.args.get('page', 1))
    per_page = force_int(request.args.get('per_page', 20))
    status = force_int(request.args.get('status', 1))
    deleted = force_int(request.args.get('deleted', 0))
    kind = force_int(request.args.get('kind', 1))
    prize_id = force_int(request.args.get('prize_id', 0))
    tag = request.args.get('tag', '')

    t = force_int(request.args.get('t', 1), 1)
    q = request.args.get('q', '')

    if q:
        if t == 1:
            query['_id'] = ObjectId(q.strip())
        if t == 2:
            query['channel'] = q.strip()
        if t == 3:
            query['evt'] = force_int(q.strip())

    if tag:
        query['total_tags'] = tag

    if prize_id:
        query['prize_id'] = prize_id

    if kind:
        if kind == 1:
            meta['css_industry'] = 'active'
        elif kind == 2:
            meta['css_plane'] = 'active'
        meta['css_all'] = ''
        query['kind'] = kind

    if status == -1:
        meta['css_disable'] = 'active'
        query['status'] = 0
    if status == 1:
        query['status'] = 1
        meta['css_enable'] = 'active'
    else:
        pass

    if deleted == 1:
        query['deleted'] = 1
        meta['css_deleted'] = 'active'
    else:
        query['deleted'] = 0

    if not status and not deleted:
        meta['css_all'] = 'active'
    else:
        meta['css_all'] = ''

    page_url = url_for('main.image_list',
                       page="#p#",
                       q=q,
                       t=t,
                       tag=tag,
                       prize_id=prize_id,
                       kind=kind,
                       status=status,
                       deleted=deleted)

    data = Image.objects(**query).order_by('random').paginate(
        page=page, per_page=per_page)
    total_count = Image.objects(**query).count()

    # 过滤数据
    for i, d in enumerate(data.items):
        prize_label = ''
        brand = None
        data.items[i]._id = str(d._id)
        data.items[i].thumb = d.get_thumb_path()
        if d.prize_id:
            prize_label = prize_options(d.prize_id)['name']
        if d.brand_id:
            brand = Brand.objects(_id=d.brand_id).first()

        data.items[i].prize_label = prize_label
        data.items[i].brand = brand

    # 过滤数据
    rows = t_image_list(data)

    meta['data'] = rows
    meta['total_count'] = total_count
    meta['prize_options'] = prize_options()

    pager = Pager(page, per_page, total_count, page_url)
    meta['pager'] = pager.render_view()
    return render_template('image/list.html', meta=meta)
Exemplo n.º 21
0
def get_tones():
    query = {}
    query['deleted'] = 0
    query['kind'] = 1
    #query['color_ids'] = []
    page = 1
    per_page = 100
    is_end = False
    total = 1
    asset_url = current_app.config['ASSET_URL']
    while not is_end:
        # 倒序
        data = Image.objects(**query).order_by('-created_at').paginate(
            page=page, per_page=per_page)
        if not len(data.items):
            print("get data is empty! \n")
            break
        for i, image in enumerate(data.items):
            if image.color_ids:
                print('色值已存在,跳过...')
                continue
            img_url = ''
            if image.path:
                img_url = os.path.join(asset_url, image.path)
            else:
                print('没有上传图片,跳过..')
                continue
                img_url = image.img_url

            try:
                response = requests.get(img_url)
            except:
                print('网络超时访问图片地址失败', str(image._id))
                continue
            try:
                if response.status_code == 200:
                    img = read_file(response)
                else:
                    print('读取图片失败:%s', response.status_code)
                    continue
            except:
                print('读取文件失败: %s', str(image._id))
                continue
            try:
                img.reduce_size(img.raw_image.size[1])
                img.unstack_pixel()
                img.extract_tones(4)
                color_ids = []
                for j in range(len(img.tones_str)):
                    color = Color.objects(rgb=img.tones_str[j]).first()
                    if color:
                        color_ids.append(str(color._id))
                    else:
                        color = Color(rgb=img.tones_str[j], hex=img.hex[j])
                        ok = color.save()
                        color_ids.append(str(ok._id))
                ok = image.update(color_ids=color_ids)
                if ok:
                    print('更新成功: %s' % str(image._id))
                else:
                    print('更新失败:%s' % str(image._id))
            except:
                print('解析图片失败:%s', str(image._id))
                continue
        total += 1
        print("current page %s: \n" % page)
        page += 1
        if len(data.items) < per_page:
            is_end = True
    print("is over execute count %s\n" % total)