diff --git a/.gitignore b/.gitignore index 282649a..fe210c0 100644 --- a/.gitignore +++ b/.gitignore @@ -363,3 +363,5 @@ MigrationBackup/ FodyWeavers.xsd /venv/ +db.sqlite3 + diff --git a/collabs/migrations/0001_initial.py b/collabs/migrations/0001_initial.py index 4ab29de..716e957 100644 --- a/collabs/migrations/0001_initial.py +++ b/collabs/migrations/0001_initial.py @@ -1,8 +1,6 @@ -# Generated by Django 4.0 on 2022-03-06 19:55 +# Generated by Django 4.0 on 2022-01-31 15:05 -import django.core.validators from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): @@ -10,7 +8,6 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('auth', '0012_alter_user_first_name_max_length'), ] operations = [ @@ -18,21 +15,14 @@ class Migration(migrations.Migration): name='Collabs_hour', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('userName', models.CharField(max_length=100, verbose_name='Auteur')), - ('nHour', models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(23)], verbose_name='Heures')), - ('nMinutes', models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(60)], verbose_name='Minutes')), - ('sRemarques', models.TextField(blank=True, verbose_name='Remarques')), - ('bNoticed', models.BooleanField(blank=True, default=False, verbose_name='Vérifiée')), - ('dtDate', models.DateField(verbose_name='Date')), - ('sBases', models.CharField(choices=[('1', 'Monthey'), ('2', 'Uvrier')], default=1, max_length=1, verbose_name='Employé de la base de')), + ('userName', models.CharField(max_length=100, verbose_name="Nom d'utilisateur")), + ('collab', models.CharField(max_length=10, verbose_name='Collaborateur')), + ('nHour', models.IntegerField(default=0, verbose_name='Heure')), + ('nMinutes', models.IntegerField(default=0, verbose_name='Minutes')), + ('sRemarques', models.TextField(verbose_name='Remarques')), + ('bNoticed', models.BooleanField(default=0, verbose_name='Pris en compte')), ('dtUpdate', models.DateTimeField(auto_now=True, verbose_name='Date de modification')), - ('dtCreated', models.DateTimeField(auto_now_add=True, verbose_name='Date de création')), - ('user', models.ForeignKey(default=0, on_delete=django.db.models.deletion.DO_NOTHING, to='auth.user', verbose_name='Collaborateur')), + ('dtCreated', models.DateTimeField(auto_now_add=True)), ], - options={ - 'verbose_name': 'heure suplémentaire', - 'verbose_name_plural': 'heures suplémentaires', - 'permissions': (('can_notice', 'Peut noter comme traitée'),), - }, ), ] diff --git a/collabs/migrations_dev/0002_collabs_hour_user.py b/collabs/migrations/0002_collabs_hour_user.py similarity index 100% rename from collabs/migrations_dev/0002_collabs_hour_user.py rename to collabs/migrations/0002_collabs_hour_user.py diff --git a/collabs/migrations_dev/0003_remove_collabs_hour_collab.py b/collabs/migrations/0003_remove_collabs_hour_collab.py similarity index 100% rename from collabs/migrations_dev/0003_remove_collabs_hour_collab.py rename to collabs/migrations/0003_remove_collabs_hour_collab.py diff --git a/collabs/migrations_dev/0004_rename_user_collabs_hour_collaborateur.py b/collabs/migrations/0004_rename_user_collabs_hour_collaborateur.py similarity index 100% rename from collabs/migrations_dev/0004_rename_user_collabs_hour_collaborateur.py rename to collabs/migrations/0004_rename_user_collabs_hour_collaborateur.py diff --git a/collabs/migrations_dev/0005_remove_collabs_hour_collaborateur_collabs_hour_user.py b/collabs/migrations/0005_remove_collabs_hour_collaborateur_collabs_hour_user.py similarity index 100% rename from collabs/migrations_dev/0005_remove_collabs_hour_collaborateur_collabs_hour_user.py rename to collabs/migrations/0005_remove_collabs_hour_collaborateur_collabs_hour_user.py diff --git a/collabs/migrations_dev/0006_alter_collabs_hour_username.py b/collabs/migrations/0006_alter_collabs_hour_username.py similarity index 100% rename from collabs/migrations_dev/0006_alter_collabs_hour_username.py rename to collabs/migrations/0006_alter_collabs_hour_username.py diff --git a/collabs/migrations_dev/0007_rename_user_collabs_hour_collaborateur_and_more.py b/collabs/migrations/0007_rename_user_collabs_hour_collaborateur_and_more.py similarity index 100% rename from collabs/migrations_dev/0007_rename_user_collabs_hour_collaborateur_and_more.py rename to collabs/migrations/0007_rename_user_collabs_hour_collaborateur_and_more.py diff --git a/collabs/migrations_dev/0008_rename_collaborateur_collabs_hour_user.py b/collabs/migrations/0008_rename_collaborateur_collabs_hour_user.py similarity index 100% rename from collabs/migrations_dev/0008_rename_collaborateur_collabs_hour_user.py rename to collabs/migrations/0008_rename_collaborateur_collabs_hour_user.py diff --git a/collabs/migrations_dev/0009_alter_collabs_hour_dtcreated_and_more.py b/collabs/migrations/0009_alter_collabs_hour_dtcreated_and_more.py similarity index 100% rename from collabs/migrations_dev/0009_alter_collabs_hour_dtcreated_and_more.py rename to collabs/migrations/0009_alter_collabs_hour_dtcreated_and_more.py diff --git a/collabs/migrations_dev/0010_alter_collabs_hour_bnoticed.py b/collabs/migrations/0010_alter_collabs_hour_bnoticed.py similarity index 100% rename from collabs/migrations_dev/0010_alter_collabs_hour_bnoticed.py rename to collabs/migrations/0010_alter_collabs_hour_bnoticed.py diff --git a/collabs/migrations_dev/0011_alter_collabs_hour_options_alter_collabs_hour_nhour.py b/collabs/migrations/0011_alter_collabs_hour_options_alter_collabs_hour_nhour.py similarity index 100% rename from collabs/migrations_dev/0011_alter_collabs_hour_options_alter_collabs_hour_nhour.py rename to collabs/migrations/0011_alter_collabs_hour_options_alter_collabs_hour_nhour.py diff --git a/collabs/migrations_dev/0012_collabs_hour_dtdate_alter_collabs_hour_bnoticed.py b/collabs/migrations/0012_collabs_hour_dtdate_alter_collabs_hour_bnoticed.py similarity index 100% rename from collabs/migrations_dev/0012_collabs_hour_dtdate_alter_collabs_hour_bnoticed.py rename to collabs/migrations/0012_collabs_hour_dtdate_alter_collabs_hour_bnoticed.py diff --git a/collabs/migrations_dev/0013_alter_collabs_hour_dtdate.py b/collabs/migrations/0013_alter_collabs_hour_dtdate.py similarity index 100% rename from collabs/migrations_dev/0013_alter_collabs_hour_dtdate.py rename to collabs/migrations/0013_alter_collabs_hour_dtdate.py diff --git a/collabs/migrations_dev/0014_alter_collabs_hour_dtdate.py b/collabs/migrations/0014_alter_collabs_hour_dtdate.py similarity index 100% rename from collabs/migrations_dev/0014_alter_collabs_hour_dtdate.py rename to collabs/migrations/0014_alter_collabs_hour_dtdate.py diff --git a/collabs/migrations_dev/0015_alter_collabs_hour_dtdate_and_more.py b/collabs/migrations/0015_alter_collabs_hour_dtdate_and_more.py similarity index 100% rename from collabs/migrations_dev/0015_alter_collabs_hour_dtdate_and_more.py rename to collabs/migrations/0015_alter_collabs_hour_dtdate_and_more.py diff --git a/collabs/migrations_dev/0016_collabs_hour_sbases.py b/collabs/migrations/0016_collabs_hour_sbases.py similarity index 100% rename from collabs/migrations_dev/0016_collabs_hour_sbases.py rename to collabs/migrations/0016_collabs_hour_sbases.py diff --git a/collabs/migrations_dev/0017_alter_collabs_hour_options.py b/collabs/migrations/0017_alter_collabs_hour_options.py similarity index 100% rename from collabs/migrations_dev/0017_alter_collabs_hour_options.py rename to collabs/migrations/0017_alter_collabs_hour_options.py diff --git a/collabs/migrations_dev/0018_collabs_hour_types_alter_collabs_hour_options_and_more.py b/collabs/migrations/0018_collabs_hour_types_alter_collabs_hour_options_and_more.py similarity index 100% rename from collabs/migrations_dev/0018_collabs_hour_types_alter_collabs_hour_options_and_more.py rename to collabs/migrations/0018_collabs_hour_types_alter_collabs_hour_options_and_more.py diff --git a/collabs/migrations_dev/0001_initial.py b/collabs/migrations_dev/0001_initial.py deleted file mode 100644 index 716e957..0000000 --- a/collabs/migrations_dev/0001_initial.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 4.0 on 2022-01-31 15:05 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Collabs_hour', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('userName', models.CharField(max_length=100, verbose_name="Nom d'utilisateur")), - ('collab', models.CharField(max_length=10, verbose_name='Collaborateur')), - ('nHour', models.IntegerField(default=0, verbose_name='Heure')), - ('nMinutes', models.IntegerField(default=0, verbose_name='Minutes')), - ('sRemarques', models.TextField(verbose_name='Remarques')), - ('bNoticed', models.BooleanField(default=0, verbose_name='Pris en compte')), - ('dtUpdate', models.DateTimeField(auto_now=True, verbose_name='Date de modification')), - ('dtCreated', models.DateTimeField(auto_now_add=True)), - ], - ), - ] diff --git a/collabs/migrations_prod/0001_initial.py b/collabs/migrations_prod/0001_initial.py new file mode 100644 index 0000000..4ab29de --- /dev/null +++ b/collabs/migrations_prod/0001_initial.py @@ -0,0 +1,38 @@ +# Generated by Django 4.0 on 2022-03-06 19:55 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='Collabs_hour', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('userName', models.CharField(max_length=100, verbose_name='Auteur')), + ('nHour', models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(23)], verbose_name='Heures')), + ('nMinutes', models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(60)], verbose_name='Minutes')), + ('sRemarques', models.TextField(blank=True, verbose_name='Remarques')), + ('bNoticed', models.BooleanField(blank=True, default=False, verbose_name='Vérifiée')), + ('dtDate', models.DateField(verbose_name='Date')), + ('sBases', models.CharField(choices=[('1', 'Monthey'), ('2', 'Uvrier')], default=1, max_length=1, verbose_name='Employé de la base de')), + ('dtUpdate', models.DateTimeField(auto_now=True, verbose_name='Date de modification')), + ('dtCreated', models.DateTimeField(auto_now_add=True, verbose_name='Date de création')), + ('user', models.ForeignKey(default=0, on_delete=django.db.models.deletion.DO_NOTHING, to='auth.user', verbose_name='Collaborateur')), + ], + options={ + 'verbose_name': 'heure suplémentaire', + 'verbose_name_plural': 'heures suplémentaires', + 'permissions': (('can_notice', 'Peut noter comme traitée'),), + }, + ), + ] diff --git a/collabs/migrations/0002_collabs_hour_types_alter_collabs_hour_user.py b/collabs/migrations_prod/0002_collabs_hour_types_alter_collabs_hour_user.py similarity index 100% rename from collabs/migrations/0002_collabs_hour_types_alter_collabs_hour_user.py rename to collabs/migrations_prod/0002_collabs_hour_types_alter_collabs_hour_user.py diff --git a/collabs/migrations/0003_collabs_hour_type_alter_collabs_hour_user.py b/collabs/migrations_prod/0003_collabs_hour_type_alter_collabs_hour_user.py similarity index 100% rename from collabs/migrations/0003_collabs_hour_type_alter_collabs_hour_user.py rename to collabs/migrations_prod/0003_collabs_hour_type_alter_collabs_hour_user.py diff --git a/collabs/migrations/0004_alter_collabs_hour_type_alter_collabs_hour_user.py b/collabs/migrations_prod/0004_alter_collabs_hour_type_alter_collabs_hour_user.py similarity index 100% rename from collabs/migrations/0004_alter_collabs_hour_type_alter_collabs_hour_user.py rename to collabs/migrations_prod/0004_alter_collabs_hour_type_alter_collabs_hour_user.py diff --git a/collabs/migrations_dev/__init__.py b/collabs/migrations_prod/__init__.py similarity index 100% rename from collabs/migrations_dev/__init__.py rename to collabs/migrations_prod/__init__.py diff --git a/mycaldav/last_sync_config.bin b/mycaldav/last_sync_config.bin new file mode 100644 index 0000000..a2558d3 Binary files /dev/null and b/mycaldav/last_sync_config.bin differ diff --git a/mycaldav/models.py b/mycaldav/models.py index 7ab071f..d4a0e0c 100644 --- a/mycaldav/models.py +++ b/mycaldav/models.py @@ -1,5 +1,10 @@ from datetime import datetime, timedelta, time import datetime as Datetime +import pickle +import os +from dateutil.relativedelta import relativedelta + + from django.db import models import urllib.request @@ -30,7 +35,7 @@ class cls_caldav(): def sort_array(self): self.items.sort(key=lambda x: x.dtstamp, reverse=False) - def get_caldav_data(self,periode=1): + def get_caldav_data(self,periode=1,calendar=None): ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE @@ -96,8 +101,13 @@ class cls_caldav(): class cls_caldav_client(): caldav_url = "https://sync.infomaniak.com" - caldav_user = 'SC01066' - caldav_password = "mc144*1870CLERC" + #caldav_user = 'SC01066' #ambulanciers@ambulance-clerc.ch + #caldav_password = "mc144*1870CLERC" + + caldav_user = 'AA01593' #agenda@ambulance-clerc.ch + caldav_password = "Agendamc144" + + caldav_agenda_config_url = "https://sync.infomaniak.com/calendars/AA01593/29d5c8d0-9b86-4d45-bc2b-13585a2e78f8?export" @@ -105,11 +115,35 @@ class cls_caldav_client(): self.client = caldav.DAVClient(url=self.caldav_url, username=self.caldav_user, password=self.caldav_password) self.data = self.client.principal() - self.m38 = self.data.calendar(name="M38") - self.m37 = self.data.calendar(name="M37") - self.clear_all_events_by_Date(self.m38) - self.add_event_in_calandar(self.m38) - self.add_event_in_calandar(self.m37) + for cal in self.data.calendars(): + print(f"name: {cal.name}({cal.url})") + + self.a_task = self.data.calendar(name="Tâche") + + + if datetime.today().day == 29: + try: + with open(os.path.join("mycaldav", "last_sync_config.bin"), "rb") as file: + array = pickle.load(file) + except: + array = {"year": 0, "month": 0} + print("Erreur lecture fichier débiteur") + + if array["month"] == datetime.now().month: + if array["year"] == datetime.now().year: + print("pas de copy, sync déjà fait") + else: + self.get_caldav_data(self.a_task) + else: + self.get_caldav_data(self.a_task) + self.clear_all_events_by_Date(self.a_task) + + + + + + + def add_event_in_calandar(self, calandar): @@ -117,9 +151,53 @@ class cls_caldav_client(): dtstart=datetime(2022, 6, 30, 12), dtend=datetime(2022, 6, 30, 13), summary="Do the needful", + ) + + def get_caldav_data(self, calandar=None): + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + + + + o_url = urllib.request.urlopen(self.caldav_agenda_config_url, context=ctx) + data = o_url.read() + o_url.close() + + now = f"01.{datetime.now().month}.{datetime.now().year}" + + + next_month = datetime.strptime(f"1.{datetime.today().month}.{datetime.today().year}","%d.%m.%Y") + relativedelta(months=1) - relativedelta(days=1) + next_month = (next_month.year, next_month.month, next_month.day) + + today = (datetime.now().year, datetime.now().month, 1) + print(f"today:{today}") + print(f"next:{next_month}") + events = None + events = recurring_ical_events.of(Calendar.from_ical(data)).between(today, next_month) + cur_events = calandar.date_search(start=datetime(today[0],today[1],today[2]), end=datetime(next_month[0],next_month[1],next_month[2]), expand=True) + + for event in events: + print(f"copy de l'événement: {event['SUMMARY']}") + + + my_event = calandar.save_event( + dtstart=event["DTSTART"].dt, + dtend=event["DTEND"].dt, + summary= event["SUMMARY"], + description=event["DESCRIPTION"], + ) + + with open(os.path.join("mycaldav", "last_sync_config.bin"), "wb") as file: + array = {"year":datetime.now().year, "month":datetime.now().month} + pickle.dump(array, file) + + + + def clear_all_events_by_Date(self, calandar): - events = calandar.date_search(start=datetime(2022, 6, 30), end=datetime(2022, 7, 1), expand=True) + events = calandar.date_search(start=datetime(2000, 1, 1), end=datetime.now() - relativedelta(years=1), expand=True) for e in events: e.delete() print(events) diff --git a/mycaldav/templates/task/task.html b/mycaldav/templates/task/task.html index 3e000a3..7777725 100644 --- a/mycaldav/templates/task/task.html +++ b/mycaldav/templates/task/task.html @@ -2,7 +2,7 @@
Jour | {% for task in latest_task_list %} -|
{{task.key}} | {{ task.name }} {{task.desc}} |
{{task.key}} | {{ task.name }} {{task.desc}}{{task.dtstart}} |