-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(memberships): added smart after-login router
- Loading branch information
1 parent
601dbc9
commit ae88909
Showing
3 changed files
with
25 additions
and
13 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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
# class BuddySystemEntrance(EnsureInSectionSpaceViewMixin, PluginConfigurationViewMixin, TemplateView): | ||
# def get(self, request, *args, **kwargs): | ||
# if self.request.membership.is_international: | ||
# return HttpResponseRedirect(reverse("buddy_system:new-request")) | ||
# | ||
# c: BuddySystemConfiguration = self.configuration | ||
# if c.matching_policy_instance.can_member_match: | ||
# return HttpResponseRedirect(reverse("buddy_system:matching-requests")) | ||
# | ||
# return HttpResponseRedirect(reverse("buddy_system:index")) | ||
from django.urls import reverse | ||
from django.views.generic import RedirectView | ||
|
||
from apps.accounts.templatetags.memberships import section_membership_activation_url | ||
from apps.plugins.views import PluginConfigurationViewMixin | ||
from apps.sections.models import SectionMembership | ||
from apps.sections.views.mixins.section_space import EnsureNotInSectionSpaceViewMixin | ||
|
||
|
||
class AfterLoginRedirectView( | ||
EnsureNotInSectionSpaceViewMixin, | ||
PluginConfigurationViewMixin, | ||
RedirectView, | ||
): | ||
def get_redirect_url(self): | ||
active_memberships = self.request.all_memberships.filter(state=SectionMembership.State.ACTIVE) | ||
if active_memberships.count() == 1: | ||
m: SectionMembership = active_memberships.first() | ||
|
||
return section_membership_activation_url(dict(request=self.request), m) | ||
|
||
return reverse("accounts:membership") |
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