Skip to content

Commit

Permalink
profile util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ramibch committed Jan 3, 2024
1 parent e8bc6e9 commit 8d90305
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 8 additions & 1 deletion core/models/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,15 @@ def fetch_cvs(self):
@cached_property
def has_children(self):
"""check if the object has 1 to many related objects (skill_set, education_set...)"""
return self.has_children_exclude()

def has_children_exclude(self, exclude: str | list = []):
links = [rel.get_accessor_name() for rel in self._meta.related_objects]
if isinstance(exclude, str):
exclude = [exclude]
for e in exclude:
links.remove(e)

links = (rel.get_accessor_name() for rel in self._meta.related_objects)
return any(getattr(self, link).exists() for link in links)

def save(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def notify_to_complete_profile():
# Collect emails depending on the profile completion
profiles_to_email = []
for p in profiles:
if not p.has_children:
if not p.has_children_exclude("cv_set"):
profiles_to_email.append(p)

# Send emails
Expand Down
8 changes: 2 additions & 6 deletions core/views/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def switch_language(request):
try:
page = Page.objects.get(id=request.POST.get("wagtail_page_id"))
except (Page.DoesNotExist, ValueError):
messages.error(
request,
_("We did not find the requested page."),
)
messages.error(request, _("We did not find the requested page."))
post["next"] = "/"
request.POST = post
return set_language(request)
Expand All @@ -28,8 +25,7 @@ def switch_language(request):
post["next"] = page.get_translation(locale).url
except (Page.DoesNotExist, Locale.DoesNotExist):
messages.warning(
request,
_("Page not available in the requested language."),
request, _("Page not available in the requested language.")
)
return set_language(request)

Expand Down

0 comments on commit 8d90305

Please sign in to comment.