Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from typing import Optional
- from seo.models.url_based import UrlSeo
- from seo.utils import get_path_from_request
- def get_url_seo(request: 'HttpRequest') -> Optional['UrlSeo']:
- """
- Return `UrlSeo` instance filtered by the current path with or without
- an appended query string, if applicable by settings
- """
- path = str(get_path_from_request(request))
- for obj in UrlSeo.objects.exclude(is_default=True):
- pattern = str(obj.url).replace('*', '(.*)')
- if re.search(pattern, path):
- return obj
- return UrlSeo.objects.filter(is_default=True).first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement