215 lines
8.4 KiB
Python
215 lines
8.4 KiB
Python
from rest_framework import generics
|
|
from .models import GlpiTickets
|
|
from .serializers import GlpiTicketAESerializer, GlpiTicketBSSerializer, GlpiTicketHSSerializer, GlpiTicketAASerializer, GlpiTicketCOSerializer, GlpiTicketCRSerializer
|
|
from datetime import datetime, timedelta
|
|
from bs4 import BeautifulSoup
|
|
from html import unescape
|
|
from django.utils.timezone import make_aware
|
|
|
|
|
|
def extract_information_bs(content):
|
|
content = unescape(content) # Unescape HTML entities
|
|
soup = BeautifulSoup(content, "html.parser")
|
|
rows = soup.find_all('tr')
|
|
|
|
# Initialize variables to hold the extracted data
|
|
matricule = None
|
|
fonction = None
|
|
structure = None
|
|
date_sortie = None
|
|
heure_sortie = None
|
|
motif = None
|
|
|
|
# Iterate through each row in the table and extract the data
|
|
for index, row in enumerate(rows):
|
|
columns = row.find_all('td')
|
|
|
|
if len(columns) == 2: # Ensure there are exactly 2 columns
|
|
key = columns[0].get_text(strip=True).replace(" :", "").strip()
|
|
value = columns[1].get_text(strip=True)
|
|
|
|
if key.startswith("Matricule"):
|
|
matricule = value
|
|
elif key.startswith("Fonction"):
|
|
fonction = value
|
|
elif key.startswith("Structure"):
|
|
structure = value
|
|
elif key.startswith("Est autorisé (e) de sortir le"):
|
|
date_sortie = value
|
|
elif key.startswith("A"):
|
|
heure_sortie = value
|
|
elif key.startswith("Pour affaire Personnelle"):
|
|
motif = value
|
|
|
|
return matricule, fonction, structure, date_sortie, heure_sortie, motif
|
|
|
|
def extract_information_aa(content):
|
|
soup = BeautifulSoup(content, "html.parser")
|
|
|
|
def extract_field(field_name):
|
|
field = soup.find(string=lambda text: field_name in text)
|
|
if field:
|
|
parts = field.split(':', 1)
|
|
if len(parts) > 1:
|
|
return parts[1].strip()
|
|
return None
|
|
|
|
matricule = extract_field("Matricule")
|
|
fonction = extract_field("Fonction")
|
|
structure = extract_field("Structure")
|
|
date_absence = extract_field("la journée du")
|
|
commentaire = extract_field("Commentaire")
|
|
|
|
return matricule, fonction, structure, date_absence, commentaire
|
|
|
|
def extract_information_hs(content):
|
|
soup = BeautifulSoup(content, "html.parser")
|
|
|
|
def extract_field(field_name):
|
|
field = soup.find(string=lambda text: field_name in text)
|
|
if field:
|
|
parts = field.split(':', 1)
|
|
if len(parts) > 1:
|
|
return parts[1].strip()
|
|
return None
|
|
|
|
matricule = extract_field("matricule")
|
|
fonction = extract_field("fonction")
|
|
structure = extract_field("structure")
|
|
date_requisition = extract_field("Date de réquisition")
|
|
motif_requisition = extract_field("motif de la réquisition")
|
|
heure_debut = extract_field("Heure de début")
|
|
heure_fin = extract_field("Heure de fin")
|
|
lieu_travail = extract_field("Lieu de travail")
|
|
|
|
return matricule, fonction, structure, date_requisition, motif_requisition, heure_debut, heure_fin, lieu_travail
|
|
|
|
def extract_information_ae(content):
|
|
content = unescape(content) # Unescape HTML entities
|
|
soup = BeautifulSoup(content, "html.parser")
|
|
|
|
# Extract the text and split by line breaks (<br />)
|
|
text_lines = soup.get_text(separator="\n").splitlines()
|
|
|
|
# Initialize variables to hold the extracted data
|
|
matricule = None
|
|
fonction = None
|
|
structure = None
|
|
date_reprise = None
|
|
commentaire = None
|
|
|
|
# Iterate through each line and extract the data
|
|
for line in text_lines:
|
|
line = line.strip()
|
|
if line.startswith("Matricule"):
|
|
matricule = line.replace("Matricule :", "").strip()
|
|
elif line.startswith("Fonction"):
|
|
fonction = line.replace("Fonction :", "").strip()
|
|
elif line.startswith("Structure"):
|
|
structure = line.replace("Structure :", "").strip()
|
|
elif line.startswith("Est autorisé (e) de reprendre à :"):
|
|
date_reprise = line.replace("Est autorisé (e) de reprendre à :", "").strip()
|
|
elif line.startswith("Commentaire :"):
|
|
commentaire = line.replace("Commentaire :", "").strip()
|
|
|
|
return matricule, fonction, structure, date_reprise, commentaire
|
|
|
|
def extract_information_cr(content):
|
|
content = unescape(content) # Unescape HTML entities
|
|
soup = BeautifulSoup(content, "html.parser")
|
|
|
|
# Extract the text and split by line breaks (<br />)
|
|
text_lines = soup.get_text(separator="\n").splitlines()
|
|
|
|
# Initialize variables to hold the extracted data
|
|
matricule = None
|
|
fonction = None
|
|
structure = None
|
|
de = None
|
|
a = None
|
|
commentaire = None
|
|
|
|
# Iterate through each line and extract the data
|
|
for line in text_lines:
|
|
line = line.strip()
|
|
if line.startswith("matricule"):
|
|
matricule = line.replace("matricule :", "").strip()
|
|
elif line.startswith("Fonction"):
|
|
fonction = line.replace("Fonction :", "").strip()
|
|
elif line.startswith("Structure"):
|
|
structure = line.replace("Structure :", "").strip()
|
|
elif line.startswith("De"):
|
|
de = line.replace("De :", "").strip()
|
|
elif line.startswith("A :"):
|
|
a = line.replace("A :", "").strip()
|
|
elif line.startswith("commentaire"):
|
|
commentaire = line.replace("commentaire :", "").strip()
|
|
|
|
return matricule, fonction, structure, de, a, commentaire
|
|
|
|
class AEListView(generics.ListAPIView):
|
|
serializer_class = GlpiTicketAESerializer
|
|
|
|
def get_queryset(self):
|
|
# Define the cutoff date (use make_aware if the field is timezone-aware)
|
|
cutoff_date = make_aware(datetime(2024, 8, 24))
|
|
#cutoff_date = make_aware(datetime.now() - timedelta(days=3))
|
|
|
|
# Get the base queryset and filter with correct syntax for date_creation
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=16, date_creation__gte=cutoff_date).order_by('id')
|
|
return queryset
|
|
|
|
class BSListView(generics.ListAPIView):
|
|
serializer_class = GlpiTicketBSSerializer
|
|
|
|
def get_queryset(self):
|
|
# Define the cutoff date (use make_aware if the field is timezone-aware)
|
|
cutoff_date = make_aware(datetime(2024, 8, 24))
|
|
#cutoff_date = make_aware(datetime.now() - timedelta(days=3))
|
|
|
|
# Get the base queryset and filter with correct syntax for date_creation
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=12, date_creation__gte=cutoff_date).order_by('id')
|
|
return queryset
|
|
|
|
class HSListView(generics.ListAPIView):
|
|
serializer_class = GlpiTicketHSSerializer
|
|
|
|
def get_queryset(self):
|
|
# Define the cutoff date (use make_aware if the field is timezone-aware)
|
|
cutoff_date = make_aware(datetime(2024, 8, 24))
|
|
#cutoff_date = make_aware(datetime.now() - timedelta(days=3))
|
|
|
|
# Get the base queryset and filter with correct syntax for date_creation
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=36, date_creation__gte=cutoff_date).order_by('id')
|
|
|
|
return queryset
|
|
|
|
class AAListView(generics.ListAPIView):
|
|
serializer_class = GlpiTicketAASerializer
|
|
|
|
def get_queryset(self):
|
|
# Define the cutoff date (use make_aware if the field is timezone-aware)
|
|
cutoff_date = make_aware(datetime(2024, 8, 24))
|
|
#cutoff_date = make_aware(datetime.now() - timedelta(days=3))
|
|
|
|
# Get the base queryset and filter with correct syntax for date_creation
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=15, date_creation__gte=cutoff_date).order_by('id')
|
|
|
|
return queryset
|
|
|
|
class CRListView(generics.ListAPIView):
|
|
serializer_class = GlpiTicketCRSerializer
|
|
|
|
def get_queryset(self):
|
|
# Define the cutoff date (use make_aware if the field is timezone-aware)
|
|
cutoff_date = make_aware(datetime(2024, 8, 24))
|
|
#cutoff_date = make_aware(datetime.now() - timedelta(days=3))
|
|
|
|
# Get the base queryset and filter with correct syntax for date_creation
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=38, date_creation__gte=cutoff_date).order_by('id')
|
|
|
|
return queryset
|
|
|
|
class COListView(generics.ListAPIView):
|
|
queryset = GlpiTickets.objects.filter(itilcategories_id=14, validations__status=3).order_by('-id')
|
|
serializer_class = GlpiTicketCOSerializer |