Move filter logic inside query
This commit is contained in:
parent
f1f444b94d
commit
1a3e7c9169
|
|
@ -21,9 +21,6 @@ def handle_user_and_verify_products(user_data, token):
|
||||||
|
|
||||||
license = License.objects.get_active_license_for_user(user)
|
license = License.objects.get_active_license_for_user(user)
|
||||||
|
|
||||||
if license and not license.is_valid():
|
|
||||||
license = None
|
|
||||||
|
|
||||||
if not license:
|
if not license:
|
||||||
license, error_msg = check_and_create_licenses(hep_client, user, token)
|
license, error_msg = check_and_create_licenses(hep_client, user, token)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,10 @@ class LicenseManager(models.Manager):
|
||||||
isbn=isbn, hep_created_at=activation_date)
|
isbn=isbn, hep_created_at=activation_date)
|
||||||
|
|
||||||
def get_active_license_for_user(self, user):
|
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:
|
if len(licenses) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue