Digital Rights Management für elektronische Patientenakten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cron.py 1.7KB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from health_view.models import *
  2. from health_view.views import check_expiration_date
  3. from datetime import datetime
  4. from health_view.crypto_functions import *
  5. import requests
  6. import json
  7. #logindata for admin acc on Contentserver
  8. loginname_restapi = ''
  9. passwort_restapi = ''
  10. def check_exp_date():
  11. licenses = License.objects.all()
  12. date_now = datetime.now()
  13. for lic in licenses:
  14. if check_expiration_date(lic):
  15. continue
  16. licenses_same_owner = License.objects.filter(justified=lic.justified, patient=lic.patient).exclude(id=lic.id)
  17. folderparts = lic.folder_parts.all().values_list()
  18. parts_to_delete = list()
  19. for part in folderparts:
  20. delete = True
  21. for license in licenses_same_owner:
  22. if not check_expiration_date(license):
  23. continue
  24. for check_part in license.folder_parts.all().values_list():
  25. if check_part == part:
  26. delete = False
  27. if delete is True:
  28. parts_to_delete.append(part[2])
  29. if not parts_to_delete:
  30. lic.delete()
  31. continue
  32. new_total_key = make_encrypted_key_content_server()
  33. post_content = {
  34. 'patient': lic.patient.username,
  35. 'justified': lic.justified.username,
  36. 'new_total_key': new_total_key,
  37. 'old_total_key': lic.patient.folderinfo.content_key,
  38. 'folder_parts': parts_to_delete,
  39. }
  40. lic.patient.folderinfo.content_key = new_total_key
  41. lic.patient.folderinfo.save()
  42. lic.delete()
  43. request = requests.post('http://192.168.192.75:8000/manage/delete/', json=post_content, auth=(loginname_restapi, passwort_restapi))