„Licenseserver/health_view/cron.py“ ändern

This commit is contained in:
Gabriel Kaufmann 2021-02-24 10:41:41 +00:00
parent 795c87e889
commit 10e859dcde

View File

@ -1,51 +1,53 @@
from health_view.models import * from health_view.models import *
from health_view.views import check_expiration_date import health_view.views
from datetime import datetime
from health_view.crypto_functions import * from health_view.crypto_functions import *
import requests import requests
import json import json
#needs logindata from admin account form Contentserver loginname_restapi = 'gabi'
loginname_restapi = '' passwort_restapi = 'Lolo7138'
passwort_restapi = ''
def check_exp_date(): def check_exp_date():
licenses = License.objects.all() licenses = License.objects.all()
date_now = datetime.now() print("did it")
for lic in licenses: for lic in licenses:
if check_expiration_date(lic): if health_view.views.check_expiration_date(lic):
continue continue
licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id) filter_license_and_delete(lic)
folderparts = lic.folder_parts.all().values_list()
parts_to_delete = list()
for part in folderparts: def filter_license_and_delete(lic):
delete = True print(lic.justified)
for license in licenses_same_owner: licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id)
if not check_expiration_date(license): folderparts = lic.folder_parts.all().values_list()
continue parts_to_delete = list()
for check_part in license.folder_parts.all().values_list(): for part in folderparts:
if check_part == part: delete = True
delete = False for license in licenses_same_owner:
if delete is True: if not health_view.views.check_expiration_date(license):
parts_to_delete.append(part[2]) continue
if not parts_to_delete: for check_part in license.folder_parts.all().values_list():
lic.delete() if check_part == part:
continue delete = False
new_total_key = make_encrypted_key_content_server() if delete is True:
post_content = { parts_to_delete.append(part[2])
'patient': lic.patient.username, if not parts_to_delete:
'justified': lic.justified.username,
'new_total_key': new_total_key,
'old_total_key': lic.patient.folderinfo.content_key,
'folder_parts': parts_to_delete,
}
lic.patient.folderinfo.content_key = new_total_key
lic.patient.folderinfo.save()
lic.delete() lic.delete()
request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi)) return
new_total_key = make_encrypted_key_content_server()
post_content = {
'patient': lic.patient.username,
'justified': lic.justified.username,
'new_total_key': new_total_key,
'old_total_key': lic.patient.folderinfo.content_key,
'folder_parts': parts_to_delete,
}
lic.patient.folderinfo.content_key = new_total_key
lic.patient.folderinfo.save()
lic.delete()
request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi))
return