]> git.parisson.com Git - teleforma.git/commitdiff
archive messages rather than delate
authorGuillaume Pellerin <yomguy@parisson.com>
Sun, 14 Feb 2021 23:07:31 +0000 (00:07 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Sun, 14 Feb 2021 23:07:31 +0000 (00:07 +0100)
teleforma/management/commands/teleforma-archive-old-messages.py [new file with mode: 0644]
teleforma/management/commands/teleforma-delete-old-messages.py [deleted file]

diff --git a/teleforma/management/commands/teleforma-archive-old-messages.py b/teleforma/management/commands/teleforma-archive-old-messages.py
new file mode 100644 (file)
index 0000000..97266a8
--- /dev/null
@@ -0,0 +1,28 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+from teleforma.models import *
+from postman.models import Message
+import logging
+import datetime
+
+
+class Command(BaseCommand):
+    help = "Archive postman messages olders than one year"
+    admin_email = 'webmaster@parisson.com'
+
+    def handle(self, *args, **options):
+        date_now = datetime.datetime.now()
+        date_old = date_now.replace(year=date_now.year-1)
+        print(date_old)
+        messages = Message.objects.filter(sent_at__lte=date_old)
+        print(messages.count())
+        for message in messages:
+            message.sender_archived = True
+            message.recipient_archived = True
+            message.save()
+
diff --git a/teleforma/management/commands/teleforma-delete-old-messages.py b/teleforma/management/commands/teleforma-delete-old-messages.py
deleted file mode 100644 (file)
index e5edb2c..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-from optparse import make_option
-from django.conf import settings
-from django.core.management.base import BaseCommand, CommandError
-from django.contrib.auth.models import User
-from django.template.defaultfilters import slugify
-from telemeta.models import *
-from telemeta.util.unaccent import unaccent
-from teleforma.models import *
-from postman.models import Message
-import logging
-import datetime
-
-
-class Command(BaseCommand):
-    help = "Delete postman messages olders than one year"
-    admin_email = 'webmaster@parisson.com'
-
-    def handle(self, *args, **options):
-        date = datetime.datetime.now()
-        date.year = date.year - 1
-        print(date)
-        messages = Message.objects.filter(sent_at__lte=datetime_now)
-        print(messages.count())
-        for message in messages:
-            print(message.sent_at)
-            message.delete()
-