-
Notifications
You must be signed in to change notification settings - Fork 2
Forms for Tailwind #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sr/tw-forms
Are you sure you want to change the base?
Forms for Tailwind #552
Conversation
|
||
@override_settings(CRISPY_TEMPLATE_PACK="tailwind") | ||
@org_member_required | ||
def add_budget_existing_users(request, org_slug=None, pk=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be quite important as we are touching a lot of views, in case any of these views get updated on the main branch, we are going to hard time integrating these back in. Let's refactor the method based views also like this to be DRY.
from django.views.decorators.debug import sensitive_post_parameters
from django.shortcuts import render, redirect
from django.conf import settings
from django.test.utils import override_settings
@override_settings(CRISPY_TEMPLATE_PACK="tailwind")
def _add_budget_existing_users_view(request, org_slug, pk, form_class):
opportunity = get_opportunity_or_404(org_slug=org_slug, pk=pk)
opportunity_access = OpportunityAccess.objects.filter(opportunity=opportunity)
opportunity_claims = OpportunityClaim.objects.filter(opportunity_access__in=opportunity_access)
form = form_class(
opportunity_claims=opportunity_claims,
opportunity=opportunity,
data=request.POST or None,
)
if form.is_valid():
form.save()
return redirect("opportunity:detail", org_slug, pk)
return render(
request,
"tailwind/pages/add_visits_existing_users.html",
{
"form": form,
"opportunity_claims": opportunity_claims,
"budget_per_visit": opportunity.budget_per_visit_new,
"opportunity": opportunity,
},
)
And then use it like below in both the places.
@org_member_required
def add_budget_existing_users(request, org_slug=None, pk=None):
return _add_budget_existing_users_view(request, org_slug, pk, TWAddBudgetExistingUsersForm)
This PR adds