def moderation_report(request, app_label, model_name, obj_id): logger.debug('POST={}'.format( request.POST)) if request.user.is_anonymous(): return {'message': _('Please log in first to report a content'), 'success': 'false'} data_dict = {'error': _('No data'), 'success': 'false'} if request.method == 'POST': model = get_model(app_label, model_name) if model: obj = get_object_or_404(model, id=obj_id) reports = get_reports_by_user(request.user, obj) if reports: report = reports[0] message = _('You\'ve already reported this content') success = 'true' else: reason = request.POST.get('reason', 0) comment = request.POST.get('comment', '') report = create_report(obj=obj, user=request.user, reason=reason, comment=comment) message = _('The content was successfully reported') success = 'true' data_dict = {'id': report.id, 'message': message, 'success': success} return data_dict
def moderation_report(request, app_label, model_name, obj_id): logger.debug('POST={}'.format(request.POST)) if request.user.is_anonymous(): return { 'message': _('Please log in first to report a content'), 'success': 'false' } data_dict = {'error': _('No data'), 'success': 'false'} if request.method == 'POST': model = get_model(app_label, model_name) if model: obj = get_object_or_404(model, id=obj_id) reports = get_reports_by_user(request.user, obj) if reports: report = reports[0] message = _('You\'ve already reported this content') success = 'true' else: reason = request.POST.get('reason', 0) comment = request.POST.get('comment', '') report = create_report(obj=obj, user=request.user, reason=reason, comment=comment) message = _('The content was successfully reported') success = 'true' data_dict = { 'id': report.id, 'message': message, 'success': success } return data_dict
def report_content(context, obj, button_type='button'): """The syntax: {% report_content object %}""" user = context.get('user', None) reports = get_reports_by_user(user, obj) disabled = True if reports else False return dict(app_label=obj._meta.app_label, model_name=obj._meta.module_name, id=obj.id, disabled=disabled, button_type=button_type)
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)