-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix suggest_registrars so it ignores path after base domain
- Loading branch information
Showing
2 changed files
with
7 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1992,19 +1992,18 @@ def firm_request_response(request): | |
def suggest_registrars(user: LinkUser, limit: int = 5) -> BaseManager[Registrar]: | ||
"""Suggest potential registrars for a user based on email domain. | ||
This queries the database for registrars whose website URL matches | ||
the base domain from the user's email address. For example, if the | ||
This queries the database for registrars whose website matches the | ||
base domain from the user's email address. For example, if the | ||
user's email is `[email protected]`, this will suggest | ||
registrars whose URLs end with `harvard.edu`. | ||
registrars whose domains end with `harvard.edu`. | ||
""" | ||
_, email_domain = user.email.split('@') | ||
base_domain = '.'.join(email_domain.rsplit('.', 2)[-2:]) | ||
pattern = f'{re.escape(base_domain)}/?$' | ||
pattern = f'^https?://([a-zA-Z0-9\\-\\.]+\\.)?{re.escape(base_domain)}(/.*)?$' | ||
registrars = ( | ||
Registrar.objects.exclude(status='pending') | ||
.filter(website__iregex=pattern) | ||
.order_by('-link_count') | ||
.all()[:limit] | ||
.order_by('-link_count', 'name')[:limit] | ||
) | ||
return registrars | ||
|
||
|