Save new folder

This commit is contained in:
2025-11-09 10:02:18 +01:00
commit 5c733eac6b
21738 changed files with 4477854 additions and 0 deletions

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TicketsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'tickets'

View File

@ -0,0 +1,58 @@
# Generated by Django 3.2 on 2024-11-21 09:58
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='GlpiTickets',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255, null=True)),
('status', models.IntegerField()),
('itilcategories_id', models.IntegerField()),
('type', models.IntegerField()),
('global_validation', models.IntegerField()),
('date_creation', models.DateTimeField(blank=True, null=True)),
('content', models.TextField(blank=True, null=True)),
],
options={
'db_table': 'glpi_tickets',
'managed': False,
},
),
migrations.CreateModel(
name='GlpiTicketvalidations',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('comment_submission', models.TextField(blank=True, null=True)),
('comment_validation', models.TextField(blank=True, null=True)),
('status', models.IntegerField()),
('validation_date', models.DateTimeField(blank=True, null=True)),
],
options={
'db_table': 'glpi_ticketvalidations',
'managed': False,
},
),
migrations.CreateModel(
name='GlpiUsers',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('realname', models.CharField(blank=True, max_length=255, null=True)),
('firstname', models.CharField(blank=True, max_length=255, null=True)),
('registration_number', models.CharField(blank=True, max_length=255, null=True)),
],
options={
'db_table': 'glpi_users',
'managed': False,
},
),
]

View File

@ -0,0 +1,37 @@
from django.db import models
class GlpiUsers(models.Model):
realname = models.CharField(max_length=255, blank=True, null=True)
firstname = models.CharField(max_length=255, blank=True, null=True)
registration_number = models.CharField(max_length=255, blank=True, null=True)
class Meta:
managed = False # This prevents Django from creating migrations for this model
db_table = 'glpi_users' # Existing database table
class GlpiTickets(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
status = models.IntegerField()
itilcategories_id = models.IntegerField()
type = models.IntegerField()
global_validation = models.IntegerField()
date_creation = models.DateTimeField(blank=True, null=True)
content = models.TextField(blank=True, null=True)
class Meta:
managed = False # This prevents Django from creating migrations for this model
db_table = 'glpi_tickets' # Existing database table
class GlpiTicketvalidations(models.Model):
tickets_id = models.ForeignKey(GlpiTickets, on_delete=models.DO_NOTHING, db_column='tickets_id', related_name='validations')
validate_by_user = models.ForeignKey(GlpiUsers, on_delete=models.DO_NOTHING, db_column='users_id_validate', related_name='validations') # Updated this line
comment_submission = models.TextField(blank=True, null=True) # Added if you need to store submissions
comment_validation = models.TextField(blank=True, null=True)
status = models.IntegerField()
validation_date = models.DateTimeField(blank=True, null=True)
class Meta:
managed = False # This prevents Django from creating migrations for this model
db_table = 'glpi_ticketvalidations' # Existing database table

View File

@ -0,0 +1,620 @@
from rest_framework import serializers
from bs4 import BeautifulSoup
from html import unescape
from .models import GlpiTickets, GlpiTicketvalidations, GlpiUsers
def extract_information_aa_v1(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_aa_v2(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_absence = None
commentaire = None
# Iterate through each line and extract the data
for line in text_lines:
line = line.strip()
if line.startswith("Fonction"):
fonction = line.replace("Fonction :", "").strip()
elif line.startswith("Structure"):
structure = line.replace("Structure :", "").strip()
elif line.startswith("Est autorisé (e) à s'absenter la journée du"):
date_absence = line.replace("Est autorisé (e) à s'absenter la journée du :", "").strip()
elif line.startswith("Commentaire"):
commentaire = line.replace("Commentaire :", "").strip()
elif line.startswith("Matricule"):
matricule = line.replace("Matricule :", "").strip()
return matricule, fonction, structure, date_absence, commentaire
def extract_information_aa(content):
# First, try extracting using the first function
matricule, fonction, structure, date_absence, commentaire = extract_information_aa_v1(content)
# If any key field is not extracted, apply the second method
if not (matricule and date_absence):
matricule, fonction, structure, date_absence, commentaire = extract_information_aa_v2(content)
return matricule, fonction, structure, date_absence, commentaire
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_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_hs(content):
content = unescape(content)
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_requisition = None
motif_requisition = None
heure_debut = None
heure_fin = None
lieu_travail = 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("Date de réquisition :"):
date_requisition = line.replace("Date de réquisition :", "").strip()
elif line.startswith("Le motif de la réquisition :"):
motif_requisition = line.replace("Le motif de la réquisition :", "").strip()
elif line.startswith("Heure de début :"):
heure_debut = line.replace("Heure de début :", "").strip()
elif line.startswith("Heure de fin :"):
heure_fin = line.replace("Heure de fin :", "").strip()
elif line.startswith("Lieu de travail :"):
lieu_travail = line.replace("Lieu de travail :", "").strip()
return matricule, fonction, structure, date_requisition, motif_requisition, heure_debut, heure_fin, lieu_travail
def extract_information_co(content):
content = unescape(content) # Unescape HTML entities
soup = BeautifulSoup(content, "html.parser")
rows = soup.find_all('tr')
matricule = None
fonction = None
structure = None
exercice = None
date_depart = None
interim = None
adresse_conge = 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("Exercice"):
exercice = value
elif key.startswith("Date de Départ"):
date_depart = value
elif key.startswith("Intérimaire"):
interim = value
elif key.startswith("Adresse durant le Congé"):
adresse_conge = value
return matricule, fonction, structure, exercice, date_depart, interim, adresse_conge
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 GlpiTicketAESerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
validation_status = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
date_reprise = serializers.SerializerMethodField()
commentaire = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['id', 'name', 'date_creation', 'matricule', 'date_reprise', 'commentaire', 'validation_status', 'validate_by_user', 'validation_date', 'comment_validation',]
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'comment_validation', None) if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'validation_date', None) if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation.validate_by_user, 'registration_number', None) if latest_validation and latest_validation.validate_by_user else None
def get_validation_status(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'status', None) if latest_validation and latest_validation.validate_by_user else None
def get_matricule(self, obj):
matricule, _, _, _, _ = extract_information_ae(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _ = extract_information_ae(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _ = extract_information_ae(obj.content)
return structure
def get_date_reprise(self, obj):
_, _, _, date_reprise, _ = extract_information_ae(obj.content)
return date_reprise
def get_commentaire(self, obj):
_, _, _, _, commentaire = extract_information_ae(obj.content)
return commentaire
class GlpiTicketBSSerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_status = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
date_sortie = serializers.SerializerMethodField()
heure_sortie = serializers.SerializerMethodField()
motif = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['id', 'name', 'date_creation', 'matricule', 'date_sortie', 'heure_sortie', 'motif', 'validation_status', 'validation_date', 'validate_by_user', 'comment_validation']
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'comment_validation', None) if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'validation_date', None) if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation.validate_by_user, 'registration_number', None) if latest_validation and latest_validation.validate_by_user else None
def get_validation_status(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'status', None) if latest_validation and latest_validation.validate_by_user else None
def get_matricule(self, obj):
matricule, _, _, _, _, _ = extract_information_bs(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _, _ = extract_information_bs(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _, _ = extract_information_bs(obj.content)
return structure
def get_date_sortie(self, obj):
_, _, _, date_sortie, _, _ = extract_information_bs(obj.content)
return date_sortie
def get_heure_sortie(self, obj):
_, _, _, _, heure_sortie, _ = extract_information_bs(obj.content)
return heure_sortie
def get_motif(self, obj):
_, _, _, _, _, motif = extract_information_bs(obj.content)
return motif
class GlpiTicketHSSerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
validation_status = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
date_requisition = serializers.SerializerMethodField()
motif_requisition = serializers.SerializerMethodField()
heure_debut = serializers.SerializerMethodField()
heure_fin = serializers.SerializerMethodField()
lieu_travail = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['id', 'name', 'date_creation', 'matricule', 'date_requisition', 'motif_requisition', 'heure_debut', 'heure_fin', 'lieu_travail', 'validation_status' , 'validation_date', 'validate_by_user', 'comment_validation',]
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'comment_validation', None) if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'validation_date', None) if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation.validate_by_user, 'registration_number', None) if latest_validation and latest_validation.validate_by_user else None
def get_validation_status(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'status', None) if latest_validation and latest_validation.validate_by_user else None
def get_matricule(self, obj):
matricule, _, _, _, _, _, _, _ = extract_information_hs(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _, _, _, _ = extract_information_hs(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _, _, _, _ = extract_information_hs(obj.content)
return structure
def get_date_requisition(self, obj):
_, _, _, date_requisition, _, _, _, _ = extract_information_hs(obj.content)
return date_requisition
def get_motif_requisition(self, obj):
_, _, _, _, motif_requisition, _, _, _ = extract_information_hs(obj.content)
return motif_requisition
def get_heure_debut(self, obj):
_, _, _, _, _, heure_debut, _, _ = extract_information_hs(obj.content)
return heure_debut
def get_heure_fin(self, obj):
_, _, _, _, _, _, heure_fin, _ = extract_information_hs(obj.content)
return heure_fin
def get_lieu_travail(self, obj):
_, _, _, _, _, _, _, lieu_travail = extract_information_hs(obj.content)
return lieu_travail
class GlpiTicketAASerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_status = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
date_absence = serializers.SerializerMethodField()
commentaire = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['id', 'name', 'date_creation', 'matricule', 'date_absence', 'commentaire', 'validation_status', 'validate_by_user', 'validation_date', 'comment_validation',]
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'comment_validation', None) if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'validation_date', None) if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation.validate_by_user, 'registration_number', None) if latest_validation and latest_validation.validate_by_user else None
def get_validation_status(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'status', None) if latest_validation and latest_validation.validate_by_user else None
def get_matricule(self, obj):
matricule, _, _, _, _ = extract_information_aa(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _ = extract_information_aa(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _ = extract_information_aa(obj.content)
return structure
def get_date_absence(self, obj):
_, _, _, date_absence, _ = extract_information_aa(obj.content)
return date_absence
def get_commentaire(self, obj):
_, _, _, _, commentaire = extract_information_aa(obj.content)
return commentaire
class GlpiTicketCOSerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
exercice = serializers.SerializerMethodField()
date_depart = serializers.SerializerMethodField()
interim = serializers.SerializerMethodField()
adresse_conge = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['name', 'date_creation', 'matricule', 'exercice', 'date_depart', 'interim', 'adresse_conge', 'validation_date', 'validate_by_user', 'comment_validation',]
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return latest_validation.comment_validation if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return latest_validation.validation_date if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator
latest_validation = obj.validations.order_by('-validation_date').first()
return latest_validation.validate_by_user.registration_number
def get_matricule(self, obj):
matricule, _, _, _, _, _, _ = extract_information_co(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _, _, _ = extract_information_co(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _, _, _ = extract_information_co(obj.content)
return structure
def get_exercice(self, obj):
_, _, _, exercice, _, _, _ = extract_information_co(obj.content)
return exercice
def get_date_depart(self, obj):
_, _, _, _, date_depart, _, _ = extract_information_co(obj.content)
return date_depart
def get_interim(self, obj):
_, _, _, _, _, interim, _ = extract_information_co(obj.content)
return interim
def get_adresse_conge(self, obj):
_, _, _, _, _, _, adresse_conge = extract_information_co(obj.content)
return adresse_conge
class GlpiTicketCRSerializer(serializers.ModelSerializer):
# Include fields you want to extract outside of validations
comment_validation = serializers.SerializerMethodField()
validation_status = serializers.SerializerMethodField()
validate_by_user = serializers.SerializerMethodField()
validation_date = serializers.SerializerMethodField()
matricule = serializers.SerializerMethodField()
de = serializers.SerializerMethodField()
a = serializers.SerializerMethodField()
commentaire = serializers.SerializerMethodField()
class Meta:
model = GlpiTickets
fields = ['id', 'name', 'date_creation', 'matricule', 'de', 'a', 'commentaire', 'validation_status', 'validation_date', 'validate_by_user', 'comment_validation',]
def get_comment_validation(self, obj):
# Assuming you want the latest comment from the validations
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'comment_validation', None) if latest_validation else None
def get_validation_date(self, obj):
# Assuming you want the latest validation date
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'validation_date', None) if latest_validation else None
def get_validate_by_user(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation.validate_by_user, 'registration_number', None) if latest_validation and latest_validation.validate_by_user else None
def get_validation_status(self, obj):
# Assuming you want the latest validator's registration number
latest_validation = obj.validations.order_by('-validation_date').first()
return getattr(latest_validation, 'status', None) if latest_validation and latest_validation.validate_by_user else None
def get_matricule(self, obj):
matricule, _, _, _, _, _ = extract_information_cr(obj.content)
return matricule
def get_fonction(self, obj):
_, fonction, _, _, _, _ = extract_information_cr(obj.content)
return fonction
def get_structure(self, obj):
_, _, structure, _, _, _ = extract_information_cr(obj.content)
return structure
def get_de(self, obj):
_, _, _, de, _, _ = extract_information_cr(obj.content)
return de
def get_a(self, obj):
_, _, _, _, a, _ = extract_information_cr(obj.content)
return a
def get_commentaire(self, obj):
_, _, _, _, _, commentaire = extract_information_cr(obj.content)
return commentaire
'''
class GlpiUserSerializer(serializers.ModelSerializer):
validate_by_user = serializers.SerializerMethodField()
class Meta:
model = GlpiUsers
fields = ['realname', 'firstname', 'registration_number', 'validate_by_user']
def get_validate_by_user(self, obj):
return f"{obj.realname} {obj.firstname}"
class GlpiTicketValidationSerializer(serializers.ModelSerializer):
validate_by_user = GlpiUserSerializer(read_only=True)
class Meta:
model = GlpiTicketvalidations
fields = ['validate_by_user', 'validation_date', 'comment_validation']
'''

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,11 @@
from django.urls import path
from .views import AEListView, BSListView, HSListView, AAListView, COListView,CRListView
urlpatterns = [
path('tickets/bs/', BSListView.as_view(), name='ticket-bs'),
path('tickets/ae/', AEListView.as_view(), name='ticket-ae'),
path('tickets/hs/', HSListView.as_view(), name='ticket-hs'),
path('tickets/aa/', AAListView.as_view(), name='ticket-aa'),
path('tickets/co/', COListView.as_view(), name='ticket-co'),
path('tickets/cr/', CRListView.as_view(), name='ticket-cr')
]

View File

@ -0,0 +1,215 @@
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