Skip to content

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

Draft
wants to merge 10 commits into
base: sr/tw-forms
Choose a base branch
from
Draft

Forms for Tailwind #552

wants to merge 10 commits into from

Conversation

pxwxnvermx
Copy link
Contributor

@pxwxnvermx pxwxnvermx commented Apr 8, 2025

This PR adds

  • Add budget Form
  • Add/Edit Payment Invoice
  • Added Opportunity Create forms -> Init, AddPaymentUnits and Finalize
  • Program Create and Edit forms
  • Invite network manager form
  • Visit Export form


@override_settings(CRISPY_TEMPLATE_PACK="tailwind")
@org_member_required
def add_budget_existing_users(request, org_slug=None, pk=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pxwxnvermx

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants