def delete(self, request): reports_ids = set() for mark in MarkSafe.objects.filter( id__in=json.loads(self.request.POST['ids'])): reports_ids |= RemoveSafeMark(mark).destroy() RecalculateSafeCache(reports_ids) return Response(status=status.HTTP_204_NO_CONTENT)
def __recalc(self): if self.type == 'leaves': RecalculateLeaves(self._decisions) elif self.type == 'safe_links': recalculate_safe_links(self._decisions) elif self.type == 'unsafe_links': recalculate_unsafe_links(self._decisions) elif self.type == 'unknown_links': recalculate_unknown_links(self._decisions) elif self.type == 'safe_reports': reports_ids = list(ReportSafe.objects.filter(decision_id__in=self._decision_ids) .values_list('id', flat=True)) RecalculateSafeCache(reports_ids) elif self.type == 'unsafe_reports': reports_ids = list(ReportUnsafe.objects.filter(decision_id__in=self._decision_ids) .values_list('id', flat=True)) RecalculateUnsafeCache(reports_ids) elif self.type == 'unknown_reports': reports_ids = list(ReportUnknown.objects.filter(decision_id__in=self._decision_ids) .values_list('id', flat=True)) RecalculateUnknownCache(reports_ids) elif self.type == 'decision_cache': RecalculateDecisionCache(self._decisions) elif self.type == 'coverage': RecalculateCoverage(self._decisions) elif self.type == 'all': RecalculateLeaves(self._decisions) recalculate_safe_links(self._decisions) recalculate_unsafe_links(self._decisions) recalculate_unknown_links(self._decisions) RecalculateDecisionCache(self._decisions) RecalculateCoverage(self._decisions) else: logger.error('Wrong type of recalculation') raise BridgeException()
def connect_safe_report(report_id): report = ReportSafe.objects.select_related('cache').get(pk=report_id) marks_qs = MarkSafe.objects.filter( cache_attrs__contained_by=report.cache.attrs) MarkSafeReport.objects.bulk_create( list( MarkSafeReport(mark_id=m_id, report=report, associated=True) for m_id in marks_qs.values_list('id', flat=True))) RecalculateSafeCache(report.id)
def perform_destroy(self, instance): if not MarkAccess(self.request.user, mark=instance).can_delete: raise exceptions.PermissionDenied( _("You don't have an access to remove this mark")) reports_ids = RemoveSafeMark(instance).destroy() RecalculateSafeCache(reports_ids)
def recalculate_cache(self, report_id): RecalculateSafeCache(report_id)