Exemple #1
0
    def on_remove_ar(self, request):
        res = {'error': 1}
        if request.method == 'POST':
            user_id = request.form.get('user_id')
            session_id = request.form.get('session_id')
            ar_id = request.form.get('ar_id')

            if ar_id is not None:
                if cvtools.user_logged_in(user_id, session_id):
                    image, count = cvtools.get_list(None, None, ar_id)
                    if len(image) > 0:
                        image = image[0]
                        if image['user_id'] != int(user_id):
                            res['error_msg'] = 'this ar is not yours'
                        else:
                            if image['target_type'] == conf.TAR_TYPE_IMAGE:
                                tar = conf.UPLOAD_DIR_TAR_IMG + '/' + image['target']
                            elif image['target_type'] == conf.TAR_TYPE_VIDEO:
                                tar = conf.UPLOAD_DIR_TAR_VIDEO + '/' + image['target']
                            else:
                                tar = None

                            if cvtools.remove_image(ar_id, conf.UPLOAD_DIR_SRC + '/' + image['src_name'], tar):
                                res['error'] = 0
                            else:
                                res['error_msg'] = 'delete unsuccessful'
                    else:
                        res['error_msg'] = 'image with id (' + ar_id + ') not found'
                else:
                    res['error'] = 2
                    res['error_msg'] = 'please login'
            else:
                res['error_msg'] = 'ar_id missing'
        response_str = json.dumps([res])
        return Response(response_str, mimetype='application/json')
Exemple #2
0
    def on_admin_remove_multiple_image(self, request):
        if request.cookies.get('cookie_name') is None:
            return redirect('/')
        checked = request.args.getlist('checked[]')
        error = 0
        for img_id in checked:
            if img_id is not None:
                image, count = cvtools.get_list(None, None, img_id)
                if len(image) > 0:
                    image = image[0]
                    if image['target_type'] == conf.TAR_TYPE_IMAGE:
                        tar = conf.UPLOAD_DIR_TAR_IMG + '/' + image['target']
                    elif image['target_type'] == conf.TAR_TYPE_VIDEO:
                        tar = conf.UPLOAD_DIR_TAR_VIDEO + '/' + image['target']
                    else:
                        tar = None

                    if not cvtools.remove_image(img_id, conf.UPLOAD_DIR_SRC + '/' + image['src_name'], tar):
                        error = 1
                    
        return redirect(request.referrer)
Exemple #3
0
    def on_admin_multiple_image_action(self, request):
        if request.cookies.get('cookie_name') is None:
            return redirect('/')
        
        action = request.args.get('action')
        checked = request.args.getlist('checked[]')
        
        error = 0
        if action == "pin":
            for img_id in checked:
                if img_id is not None:
                    if cvtools.is_pinned(img_id) is False:
                        cvtools.toggle_pinned(img_id)
                    else:
                        continue
        elif action == "unpin":
            for img_id in checked:
                if img_id is not None:
                    if cvtools.is_pinned(img_id) is True:
                        cvtools.toggle_pinned(img_id)
                    else:
                        continue
        elif action == "remove":
            for img_id in checked:
                if img_id is not None:
                    image, count = cvtools.get_list(None, None, img_id)
                    if len(image) > 0:
                        image = image[0]
                        if image['target_type'] == conf.TAR_TYPE_IMAGE:
                            tar = conf.UPLOAD_DIR_TAR_IMG + '/' + image['target']
                        elif image['target_type'] == conf.TAR_TYPE_VIDEO:
                            tar = conf.UPLOAD_DIR_TAR_VIDEO + '/' + image['target']
                        else:
                            tar = None

                        if not cvtools.remove_image(img_id, conf.UPLOAD_DIR_SRC + '/' + image['src_name'], tar):
                            error = 1
        
        return redirect(request.referrer)