Move filter logic inside query

This commit is contained in:
Ramon Wenger 2023-08-16 15:30:21 +02:00
parent f1f444b94d
commit 1a3e7c9169
2 changed files with 4 additions and 4 deletions

View File

@ -21,9 +21,6 @@ def handle_user_and_verify_products(user_data, token):
license = License.objects.get_active_license_for_user(user)
if license and not license.is_valid():
license = None
if not license:
license, error_msg = check_and_create_licenses(hep_client, user, token)

View File

@ -160,7 +160,10 @@ class LicenseManager(models.Manager):
isbn=isbn, hep_created_at=activation_date)
def get_active_license_for_user(self, user):
licenses = self.filter(licensee=user, expire_date__gte=timezone.now()).order_by('-expire_date')
licenses = self.filter(licensee=user, expire_date__gte=timezone.now()).order_by(
"-expire_date"
)
licenses = [license for license in licenses if license.is_valid()]
if len(licenses) == 0:
return None