functions.py 1.06 KB
from .serializers import AgentCmdSerializer, AgentSurveySerializer
from common.models import AgentCmd, AgentSurvey
from datetime import datetime, timezone, timedelta


def get_list_agent_cmd(agent_name):
    commands_sent_by_agent = AgentCmd.get_commands_sent_by_agent(agent_name)
    commands_recivied_by_agent = AgentCmd.get_commands_sent_to_agent(agent_name)
    number = 20
    agent_cmds = commands_sent_by_agent | commands_recivied_by_agent
    agent_cmds = agent_cmds.exclude(full_name="get_specific_cmds")
    agent_cmds = agent_cmds.exclude(full_name="get_all_cmds")
    agent_cmds = agent_cmds.order_by("-s_deposit_time")
    agent_cmds = agent_cmds[:number]
    return AgentCmdSerializer(agent_cmds,many=True).data


def get_agent_survey_instance():
    agents = AgentSurvey.objects.all()
    datetime_now = datetime.utcnow()
    date_minus_two_days =  datetime_now - timedelta(days=2)
    date_minus_two_days = date_minus_two_days.replace(tzinfo=timezone.utc)
    agents = agents.exclude(updated__lt=date_minus_two_days)
    return AgentSurveySerializer(agents,many=True).data