Beispiel #1
0
    def get_context_data(self, request, **kwargs):
        context = super(UserDashboardLowFi, self).get_context_data(**kwargs)

        user_settings = UserSettings()
        user_settings = user_settings.get_settings_based_on_user(request.user)

        user_contracts_where_relationship_exists = Relationship.objects.filter(
            ContractUser=request.user)
        all_recipients = Recipient.objects.all()
        all_milestones = Milestone.objects.all().order_by("Deadline")

        context["needs_stripe"] = user_settings.does_this_user_need_stripe()
        context["call_state"] = settings.STRIPE_CALL_STATE
        context["stripe_acct"] = settings.STRIPE_ACCOUNT_ID
        context["first_name"] = request.user.first_name
        context["projects_in_progress"] = []
        context["upcoming_milestones"] = []

        for relationship in user_contracts_where_relationship_exists:
            if relationship.ContractForRelationship.StartDate <= timezone.now(
            ).date(
            ) and relationship.ContractForRelationship.EndDate >= timezone.now(
            ).date():
                # Get recipient and fill in entry for the in progress projects
                recipient_for_contract = all_recipients.filter(
                    ContractForRecipient=relationship.ContractForRelationship
                ).first()
                context["projects_in_progress"].append({
                    "name":
                    relationship.ContractForRelationship.Name,
                    "progress":
                    relationship.ContractForRelationship.
                    get_contract_state_view(),
                    "client":
                    recipient_for_contract.Name
                })

                # Get milestones for this contract that are still due
                contract_milestones = all_milestones.filter(
                    MilestoneContract=relationship.ContractForRelationship)

                for milestone in contract_milestones:
                    if milestone.Deadline >= timezone.now().date():
                        context["upcoming_milestones"].append({
                            "date":
                            milestone.Deadline.strftime("%b %d %Y"),
                            "name":
                            milestone.Name,
                            "project":
                            milestone.MilestoneContract.Name,
                            "amount":
                            "{0:.2f}".format(milestone.MilestonePaymentAmount)
                        })

        return context
Beispiel #2
0
    def get_context_data(self, request, **kwargs):
        # Get some necessary User Information
        user_settings = UserSettings()
        user_settings = user_settings.get_settings_based_on_user(request.user)

        # Set the context
        context = super(EditAccountView, self).get_context_data(**kwargs)

        # Call Stripe Settings For The Link Generation
        context["needs_stripe"] = user_settings.does_this_user_need_stripe()
        context["call_state"] = settings.STRIPE_CALL_STATE
        context["stripe_acct"] = settings.STRIPE_ACCOUNT_ID

        # If this is from a Stripe Auth Page
        comm = StripeCommunication()
        response_code = request.GET.get("code", "")
        stripe_state = request.GET.get("state", "")
        json_response = {}

        # We need to check if this request even came from Stripe
        if response_code != "":
            json_response = comm.create_new_stripe_custom_account(
                response_code)
            context["came_from_stripe"] = True

            if stripe_state != settings.STRIPE_CALL_STATE:
                context["error_message"] = "Bad Call State"
                context["needs_stripe"] = True
        else:
            context["came_from_stripe"] = False

        # Did we get the stripe User ID in the response?
        if "stripe_user_id" in json_response:
            context["user_stripe_acct"] = json_response["stripe_user_id"]
        else:
            context["user_stripe_acct"] = ""

        # Did the response come with an error description?
        if "error_description" in json_response:
            context["error_message"] = json_response["error_description"]
            context["needs_stripe"] = True

        return context