def delete_button(context, obj):
    """The syntax: {% delete_button object %}"""
    user = context.get('user', None)
    deletion_requests = get_reports_by_user(user, obj,
                                            reason=Report.DELETION_REQUEST)
    disabled = True if not can_delete(obj, user) and deletion_requests else False
    return dict(app_label=obj._meta.app_label,
                model_name=obj._meta.module_name,
                id=obj.id,
                disabled=disabled)
Exemplo n.º 2
0
def delete_button(context, obj):
    """The syntax: {% delete_button object %}"""
    user = context.get('user', None)
    deletion_requests = get_reports_by_user(user,
                                            obj,
                                            reason=Report.DELETION_REQUEST)
    disabled = True if not can_delete(obj,
                                      user) and deletion_requests else False
    return dict(app_label=obj._meta.app_label,
                model_name=obj._meta.module_name,
                id=obj.id,
                disabled=disabled)
Exemplo n.º 3
0
def moderation_delete(request, app_label, model_name, obj_id):
    logger.debug('accessing Moderation > moderation_delete : POST={}'.format(
        request.POST))
    model = get_model(app_label, model_name)
    data_dict = {'error': _('No data'), 'success': 'false'}
    if model:
        obj = get_object_or_404(model, id=obj_id)

        if can_delete(obj, request.user):
            logger.debug('user can delete the content {}'.format(obj))
            confirmed = (request.POST.get('confirmed', 'false') == 'true')
            if confirmed:
                logger.debug('deletion confirmed. deleting {}'.format(obj))
                try:
                    delete_object(obj)
                    data_dict = {
                        'next': 'showDeleteFeedback',
                        'success': 'true'
                    }
                except Exception, e:
                    logger.debug('An unexpected error occurred while ' \
                            'deleting {} : {}'.format(obj, e.message))
                    data_dict = {
                        'next': 'unexpectedError',
                        'info': e.message,
                        'success': 'false'
                    }
            else:
                logger.debug('asking to display the confirmation dialog...')
                data_dict = {'next': 'confirmation', 'success': 'true'}
        else:
            requesting = (request.POST.get('action', 'none') == 'request')
            if requesting:
                comment = request.POST.get('comment', '')
                report = create_report(obj=obj,
                                       user=request.user,
                                       reason=Report.DELETION_REQUEST,
                                       comment=comment)
                data_dict = {'next': 'showRequestFeedback', 'success': 'true'}
            else:
                logger.debug('user cannot delete the content. ' \
                        'asking to display the request dialog...')
                data_dict = {'next': 'request', 'success': 'true'}
Exemplo n.º 4
0
def moderation_delete(request, app_label, model_name, obj_id):
    logger.debug('accessing Moderation > moderation_delete : POST={}'.format(
        request.POST))
    model = get_model(app_label, model_name)
    data_dict = {'error': _('No data'), 'success': 'false'}
    if model:
        obj = get_object_or_404(model, id=obj_id)

        if can_delete(obj, request.user):
            logger.debug('user can delete the content {}'.format(obj))
            confirmed = (request.POST.get('confirmed', 'false') == 'true')
            if confirmed:
                logger.debug('deletion confirmed. deleting {}'.format(obj))
                try:
                    delete_object(obj)
                    data_dict = {'next': 'showDeleteFeedback',
                                 'success': 'true'}
                except Exception, e:
                    logger.debug('An unexpected error occurred while ' \
                            'deleting {} : {}'.format(obj, e.message))
                    data_dict = {'next': 'unexpectedError',
                                 'info': e.message, 'success': 'false'}
            else:
                logger.debug('asking to display the confirmation dialog...')
                data_dict = {'next': 'confirmation', 'success': 'true'}
        else:
            requesting = (request.POST.get('action', 'none') == 'request')
            if requesting:
                comment = request.POST.get('comment', '')
                report = create_report(obj=obj, user=request.user,
                        reason=Report.DELETION_REQUEST, comment=comment)
                data_dict = {'next': 'showRequestFeedback',
                             'success': 'true'}
            else:
                logger.debug('user cannot delete the content. ' \
                        'asking to display the request dialog...')
                data_dict = {'next': 'request', 'success': 'true'}