def attach_all_event(): aux_weblogs = ModuleAuxWeblog.objects.filter( status=ModuleAuxWeblog.STATUS.seed) if aux_weblogs.exists(): weblogs_qs = Weblog.objects.filter( moduleauxweblog__in=aux_weblogs.values_list( 'id', flat=True)).distinct() weblogs_seed = WeblogSerializer(weblogs_qs, many=True).data weblogs_seed_json = json.dumps(weblogs_seed) ModulesManager.__attach_event( ModulesManager.MODULES_RUN_EVENTS.labelling, weblogs_seed_json) ModulesManager.__attach_event( ModulesManager.MODULES_RUN_EVENTS.bulk_labelling, weblogs_seed_json) weblogs_malicious = [ w.weblog for w in aux_weblogs.filter( weblog__verdict=Weblog.VERDICT_STATUS.malicious) ] if weblogs_malicious: weblogs_seed_json = serializers.serialize( 'json', weblogs_malicious) ModulesManager.__attach_event( ModulesManager.MODULES_RUN_EVENTS.labelling_malicious, weblogs_seed_json) aux_weblogs.delete()
def get_weblogs(request): try: if request.method == 'GET': user = request.user analysis_session_id = request.GET.get('analysis_session_id', '') analysis_session = AnalysisSession.objects.prefetch_related('weblog_set').get(id=analysis_session_id) headers = convert(analysis_session.get_columns_order_by(user)) weblogs_qs = analysis_session.weblog_set.all() weblogs_json = WeblogSerializer(weblogs_qs, many=True).data return JsonResponse(dict(weblogs=weblogs_json, analysissessionid=analysis_session_id, analysissessionuuid=analysis_session.uuid, name=analysis_session.name, headers=json.dumps(headers))) else: messages.error(request, 'Only GET request') return HttpResponseServerError("Only GET request") except Exception as e: print_exception() return HttpResponseServerError("There was a error in the Server")
def after_save_attach_event(analysis_session): # try: weblogs_qs = analysis_session.weblog_set.all() weblogs_json = json.dumps(WeblogSerializer(weblogs_qs, many=True).data) ModulesManager.__attach_event( ModulesManager.MODULES_RUN_EVENTS.after_save, weblogs_json)
def get_filtered_weblogs_json(**kwargs): weblogs_qs = Weblog.objects.filter(Q(**kwargs)) weblogs_json = WeblogSerializer(weblogs_qs, many=True).data return json.dumps(weblogs_json)
def get_all_weblogs_json(): weblogs_qs = Weblog.objects.all() weblogs_json = WeblogSerializer(weblogs_qs, many=True).data return json.dumps(weblogs_json)