diff --git a/templates/users/sponsor_select.html b/templates/users/sponsor_select.html new file mode 100644 index 000000000..7c8185b8b --- /dev/null +++ b/templates/users/sponsor_select.html @@ -0,0 +1,30 @@ +{% extends "users/base.html" %} +{% load humanize pipeline %} + +{% block head %} + {% stylesheet 'font-awesome' %} +{% endblock %} + +{% block page_title %} + Select Sponsor | {{ SITE_INFO.site_name }} +{% endblock %} + +{% block body_attributes %}class="psf signup default-page"{% endblock %} + + +{% block main-nav_attributes %}psf-navigation{% endblock %} + +{% block user_content %} +

Select Sponsor to edit

+ +
+ +{% endblock %} + +{% block javascript %} + {{ block.super }} +{% endblock %} diff --git a/users/urls.py b/users/urls.py index e925838b5..3ca7eccb7 100644 --- a/users/urls.py +++ b/users/urls.py @@ -18,6 +18,11 @@ views.UpdateSponsorInfoView.as_view(), name="edit_sponsor_info", ), + path( + "sponsorships/sponsor/edit/", + views.edit_sponsor_info_implicit, + name="edit_sponsor_info_implicit", + ), path( "sponsorships//assets/", views.UpdateSponsorshipAssetsView.as_view(), diff --git a/users/views.py b/users/views.py index c56dbace4..23140853e 100644 --- a/users/views.py +++ b/users/views.py @@ -277,6 +277,18 @@ def get_success_url(self): messages.add_message(self.request, messages.SUCCESS, "Sponsor info updated with success.") return self.request.path +@login_required(login_url=settings.LOGIN_URL) +def edit_sponsor_info_implicit(request): + sponsors = Sponsor.objects.filter(contacts__user=request.user).all() + if len(sponsors) == 0: + messages.add_message(request, messages.INFO, "No Sponsors associated with your user.") + return redirect('users:user_profile_edit') + elif len(sponsors) == 1: + return redirect('users:edit_sponsor_info', pk=sponsors[0].id) + else: + messages.add_message(request, messages.INFO, "Multiple Sponsors associated with your user.") + return render(request, 'users/sponsor_select.html', context={"sponsors": sponsors}) + @method_decorator(login_required(login_url=settings.LOGIN_URL), name="dispatch") class UpdateSponsorshipAssetsView(UpdateView):