Exemplo n.º 1
0
 def upload(self):
     new_leaves = []
     for rep_id in self._data:
         for unsafe in self._data[rep_id]['unsafes']:
             new_leaves.append(
                 ReportComponentLeaf(report_id=rep_id, unsafe_id=unsafe))
         for safe in self._data[rep_id]['safes']:
             new_leaves.append(
                 ReportComponentLeaf(report_id=rep_id, safe_id=safe))
         for unknown in self._data[rep_id]['unknowns']:
             new_leaves.append(
                 ReportComponentLeaf(report_id=rep_id, unknown_id=unknown))
     ReportComponentLeaf.objects.bulk_create(new_leaves)
     self.__init__()
Exemplo n.º 2
0
    def __create_report_unknown(self, data):
        data['attr_data'] = self.__upload_attrs_files(
            self.__get_archive(data.get('attr_data')))
        data['problem_description'] = self.__get_archive(
            data['problem_description'])
        serializer = ReportUnknownSerializer(data=data, decision=self.decision)
        serializer.is_valid(raise_exception=True)
        report = serializer.save()

        # Get ancestors before parent might me changed
        ancestors_ids = self.__ancestors_for_cache(report)

        if self.decision.is_lightweight and not report.parent.verification:
            # Change parent to Core
            report.parent_id = ancestors_ids[0]
            report.save()

        # Caching leaves for each tree branch node
        ReportComponentLeaf.objects.bulk_create(
            list(
                ReportComponentLeaf(report_id=parent_id, content_object=report)
                for parent_id in ancestors_ids))

        # Connect report with marks
        connect_unknown_report.delay(report.id)
Exemplo n.º 3
0
 def add_leaf(self, report):
     parent_id = report.parent_id
     while parent_id is not None:
         self._leaves_cache.append(
             ReportComponentLeaf(report_id=parent_id,
                                 object_id=report.id,
                                 content_type=self.__content_type(report)))
         parent_id = self._tree[parent_id]
Exemplo n.º 4
0
    def __create_report_safe(self, data):
        data['attr_data'] = self.__upload_attrs_files(
            self.__get_archive(data.get('attr_data')))
        serializer = ReportSafeSerializer(data=data, decision=self.decision)
        serializer.is_valid(raise_exception=True)
        report = serializer.save()

        # Caching leaves for each tree branch node
        ReportComponentLeaf.objects.bulk_create(
            list(
                ReportComponentLeaf(report_id=parent_id, content_object=report)
                for parent_id in self.__ancestors_for_cache(report)))

        # Connect report with marks
        connect_safe_report.delay(report.id)
Exemplo n.º 5
0
    def __fill_unsafes_cache(self, reports):
        if self.job.weight == JOB_WEIGHT[1][0]:
            self.__cut_parents_branch()
            if self.parent.verifier_input or self.parent.covnum > 0:
                # After verification finish report self.parent.parent will be Core/first-level report
                self._parents_branch.append(self.parent)
            else:
                ReportUnsafe.objects.filter(id__in=list(
                    r.id
                    for r in reports)).update(parent=self._parents_branch[-1])

        leaves = []
        for p in self._parents_branch:
            leaves.extend(
                list(
                    ReportComponentLeaf(report=p, unsafe=unsafe)
                    for unsafe in reports))
        ReportComponentLeaf.objects.bulk_create(leaves)
        for leaf in reports:
            UnsafeUtils.ConnectReport(leaf)
        UnsafeUtils.RecalculateTags(reports)
Exemplo n.º 6
0
    def __create_report_unsafe(self, data):
        self._logger.log("UF0", data.get('parent'))

        data['attr_data'] = self.__upload_attrs_files(self.__get_archive(data.get('attr_data')))
        data['error_trace'] = self.__get_archive(data.get('error_trace'))
        serializer = ReportUnsafeSerializer(data=data, decision=self.decision)
        serializer.is_valid(raise_exception=True)
        report = serializer.save()

        self._logger.log("UF1", report.pk, report.parent_id)

        # Caching leaves for each tree branch node
        ReportComponentLeaf.objects.bulk_create(list(
            ReportComponentLeaf(report_id=parent_id, content_object=report)
            for parent_id in self.__ancestors_for_cache(report)
        ))

        # Connect new unsafe with marks
        connect_unsafe_report.delay(report.id)

        self._logger.log("UF2", report.pk)