From 476713840d94542c13eb461a09982015d5be6137 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Tue, 3 Dec 2024 18:16:51 +0800 Subject: [PATCH 1/8] Create clean_privatedocuments.py --- .../commands/clean_privatedocuments.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ledger/accounts/management/commands/clean_privatedocuments.py diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py new file mode 100644 index 000000000..57fd5c022 --- /dev/null +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -0,0 +1,34 @@ +from ledger.address.models import UserAddress +from ledger.accounts.models import PrivateDocument,EmailUser + +class Command(BaseCommand): + help = 'Cleans up private documents table.' + + def add_arguments(self, parser): + pass + + def handle(self, *args, **options): + try: + pd = PrivateDocument.objects.filter(extension='') + print (pd.count()) + for p in pd: + + print (p.id) + print (p.upload.path) + ext = '' + if p.upload.path[-4] == '.': + ext = p.upload.path[-4:] + if p.upload.path[-5] == '.': + ext = p.upload.path[-5:] + + print (ext) + if len(ext) > 0: + p.extension = ext + p.name = 'file'+ext + eu = EmailUser.objects.filter(identification2=p.id) + print (eu) + if eu.count() > 0: + p.file_group=1 + p.save() + except Exception as e: + raise CommandError(e) From 284fdf7b58f403867babcd7f3b127b33dae27c89 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:06:27 +0800 Subject: [PATCH 2/8] Patching Packages --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6fd813959..91a170c39 100755 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ git+https://github.com/scottp-dpaw/social-core.git@email_fix#egg=social-auth-cor webtemplate-dbca==0.6.0 coverage==4.3.1 coveralls==1.1 -reportlab==3.5.26 +reportlab==4.2.5 #django_bootstrap3==7.1.0 django_bootstrap3==12.0.3 django-braces>=1.8.1 @@ -34,7 +34,6 @@ django-ical==1.4 django-taggit==0.21.3 geojson==1.3.3 unicodecsv==0.14.1 -PyPDF2==1.26.0 django-extra-fields==0.9 django-crispy-forms==1.9.0 django-reset-migrations==0.3.1 From d5d317f8c46758826e215e4c3c4f4f771a311d39 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:10:41 +0800 Subject: [PATCH 3/8] Add missing module --- ledger/accounts/management/commands/clean_privatedocuments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py index 57fd5c022..9dfae9556 100644 --- a/ledger/accounts/management/commands/clean_privatedocuments.py +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -1,3 +1,4 @@ +from django.core.management.base import BaseCommand, CommandError from ledger.address.models import UserAddress from ledger.accounts.models import PrivateDocument,EmailUser From 09000bc063b4a5a1515c8c8940a0901536688d3a Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:14:50 +0800 Subject: [PATCH 4/8] Add Query String --- ledger/accounts/management/commands/clean_privatedocuments.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py index 9dfae9556..0b0148794 100644 --- a/ledger/accounts/management/commands/clean_privatedocuments.py +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand, CommandError from ledger.address.models import UserAddress from ledger.accounts.models import PrivateDocument,EmailUser +from django.db.models import Q class Command(BaseCommand): help = 'Cleans up private documents table.' @@ -10,7 +11,8 @@ def add_arguments(self, parser): def handle(self, *args, **options): try: - pd = PrivateDocument.objects.filter(extension='') + query_string = Q(extension='') | Q(extension=None) + pd = PrivateDocument.objects.filter(query_string) print (pd.count()) for p in pd: From 32ed73a14e8fe104e26f565e3b7f75076f9ad828 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:16:35 +0800 Subject: [PATCH 5/8] Clean script --- .../accounts/management/commands/clean_privatedocuments.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py index 0b0148794..abf24f4c2 100644 --- a/ledger/accounts/management/commands/clean_privatedocuments.py +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -13,11 +13,10 @@ def handle(self, *args, **options): try: query_string = Q(extension='') | Q(extension=None) pd = PrivateDocument.objects.filter(query_string) - print (pd.count()) + print ("Total Results"+pd.count()) for p in pd: - print (p.id) - print (p.upload.path) + ext = '' if p.upload.path[-4] == '.': ext = p.upload.path[-4:] @@ -26,6 +25,8 @@ def handle(self, *args, **options): print (ext) if len(ext) > 0: + print (p.id) + print (p.upload.path) p.extension = ext p.name = 'file'+ext eu = EmailUser.objects.filter(identification2=p.id) From e1d8c1f12ed82259b5a402ad27c68239ef650ed2 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:17:01 +0800 Subject: [PATCH 6/8] Fix str error --- ledger/accounts/management/commands/clean_privatedocuments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py index abf24f4c2..423270b16 100644 --- a/ledger/accounts/management/commands/clean_privatedocuments.py +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -13,7 +13,7 @@ def handle(self, *args, **options): try: query_string = Q(extension='') | Q(extension=None) pd = PrivateDocument.objects.filter(query_string) - print ("Total Results"+pd.count()) + print ("Total Results"+str(pd.count())) for p in pd: From 9d5bf9f66b67b6d1a0a6251e9d9999dbf0d3871c Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:18:00 +0800 Subject: [PATCH 7/8] Clean script --- ledger/accounts/management/commands/clean_privatedocuments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledger/accounts/management/commands/clean_privatedocuments.py b/ledger/accounts/management/commands/clean_privatedocuments.py index 423270b16..1771242fe 100644 --- a/ledger/accounts/management/commands/clean_privatedocuments.py +++ b/ledger/accounts/management/commands/clean_privatedocuments.py @@ -13,7 +13,7 @@ def handle(self, *args, **options): try: query_string = Q(extension='') | Q(extension=None) pd = PrivateDocument.objects.filter(query_string) - print ("Total Results"+str(pd.count())) + print ("Total Results: "+str(pd.count())) for p in pd: @@ -23,7 +23,7 @@ def handle(self, *args, **options): if p.upload.path[-5] == '.': ext = p.upload.path[-5:] - print (ext) + if len(ext) > 0: print (p.id) print (p.upload.path) From 07e92f18ed1db07e430e2d85d383b1b33365e415 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Wed, 4 Dec 2024 12:19:26 +0800 Subject: [PATCH 8/8] Add cronjob --- python-cron | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python-cron b/python-cron index 2be0d07ce..5ded43798 100644 --- a/python-cron +++ b/python-cron @@ -24,3 +24,6 @@ # App Monitor Client 10 9 * * * python3 /app/manage_ledgergw.py appmonitor_check >> /app/logs/appmonitor_client.log 2>&1 + +# Fix private documents information +10 * * * * python /app/manage_ledgergw.py clean_privatedocuments >> /app/logs/clean_privatedocuments.log