Example #1
0
def delete_image(request):
    id = request.POST.get('id', 0)
    try:
        get_image_by_id(id).delete()
    except:
        return HttpResponseForbidden()
    return JsonResponse({})
Example #2
0
    def calculate(self):
        from app.db_manager.other_manager import get_image_by_id, filter_image_by_start_name
        if not self.args:
            self.args = ''
        self.args = self.args.strip()

        temp_args = self.args.split('|')
        img = None
        id_or_name = temp_args[0].strip()
        if re.search(r'=', id_or_name):
            k, v = id_or_name.split('=')
            k = k.strip()
            v = v.strip()
            if k == 'id':
                img = get_image_by_id(v)
            elif k == 'name':
                try:
                    img = filter_image_by_start_name(v)[0]
                except:
                    img = None
        else:
            img = get_image_by_id(id_or_name)
            if not img:
                try:
                    img = filter_image_by_start_name(id_or_name)[0]
                except:
                    img = None

        img_tag = HtmlTag('img')
        if img:
            img_tag.set_attr('src', img.img.url)
        for attr in temp_args[1:]:
            k, v = attr.split('=')
            img_tag.set_attr(k, v)
        self.result = img_tag
Example #3
0
    def calculate(self):
        from app.db_manager.other_manager import get_image_by_id, filter_image_by_start_name
        if not self.args:
            self.args = ''

        args = self.args.split('|')

        if len(args) == 0:
            raise ExpressionTypeError('表达式 text 至少需要一个参数')

        src = ''
        args_src = args[0]
        k, v = args_src.split('=')
        k = k.strip()
        v = v.strip()
        if k == 'src':
            src = v
        elif k == 'id':
            img = get_image_by_id(v)
            if img:
                src = img.img.url
        elif k == 'name':
            try:
                img = filter_image_by_start_name(v)[0]
                src = img.img.url
            except:
                pass
        if len(args) > 1:

            attrs = get_attrs(args[1:])
        else:
            attrs = {}

        return {'type': 'img', 'src': src, 'attrs': attrs}
Example #4
0
    def calculate(self):
        """
        解析结果,要重写
        :return:
        :rtype: dict
        """
        from app.db_manager.other_manager import get_image_by_id, filter_image_by_start_name

        r = self.args
        v = self.args['value'].strip()
        type = self.args['type']
        if type == 'src':
            r['type'] = 'img'
            r['src'] = v
        elif type == 'id':
            r['type'] = 'img'
            img = get_image_by_id(v)
            if img:
                r['src'] = img.img.url
            else:
                r['src'] = ''
        elif type == 'name':
            r['type'] = 'img'
            try:
                img = filter_image_by_start_name(v)[0]
                src = img.img.url
            except:
                src = ''
            r['src'] = src
        elif type == 'fa':
            r['type'] = 'fa'
            r['class'] = v
        elif type == 'svg':
            r['type'] = 'svg'
            r['svg'] = v
        return r