Example #1
0
def pre_init_admin_reinvestment(**kwargs):
    """
    Raises a NotEnoughFundingException before __init__ if there are not enough
    funds for this AdminReinvestment.
    """
    if is_user_reinvestment_period():
        raise NotInAdminReinvestmentPeriodException()

    init_kwargs = kwargs.get('kwargs')
    # can't initialize admin_repayment without required 'amount' kwarg
    if not init_kwargs or not init_kwargs.get('amount'):
        raise NotEnoughFundingException()
    invest_amount = init_kwargs['amount']

    global_repay_amount = AdminRepayment.objects.aggregate(
        Sum('amount')
    )['amount__sum'] or 0.0
    global_reinvest_amount = AdminReinvestment.objects.aggregate(
        Sum('amount')
    )['amount__sum'] or 0.0
    global_user_reinvest_amount = UserReinvestment.objects.aggregate(
        Sum('amount')
    )['amount__sum'] or 0.0
    global_reinvest_pool = global_repay_amount - global_reinvest_amount - global_user_reinvest_amount
    if global_reinvest_pool - invest_amount < 0.0:
        raise NotEnoughFundingException()
Example #2
0
    def get_context_data(self, **kwargs):
        context = super(ProjectListReinvestmentView,
                        self).get_context_data(**kwargs)
        context["is_reinvestment"] = True
        if not is_user_reinvestment_period():
            if self.user_profile.reinvest_pool > 0.0:
                context["error_msg"] = "You have ${0} to reinvest, " \
                                       "but user reinvest period has been end for this month. " \
                                       "Please came back before date {1} in current month"\
                    .format(self.user_profile.reinvest_pool, settings.ADMIN_REINVESTMENT_DATE['day'])
            else:
                context["error_msg"] = "User reinvest period has been end for this month. " \
                                       "Please came back before date {0} in current month"\
                    .format(settings.ADMIN_REINVESTMENT_DATE['day'])

        else:
            active = Project.objects.get_eligible_projects_for_reinvestment()
            context["active_projects"] = filter(lambda p: p.amount_left > 0.0,
                                                active)
            if self.user_profile.reinvest_pool > 0.0:
                context[
                    "reinvestment_amount"] = self.user_profile.reinvest_pool
            else:
                context["error_msg"] = "You don't have fund to reinvest"
        return context
Example #3
0
def pre_init_user_reinvestment(**kwargs):
    """
    Raises a NotEnoughFundingException before __init__ if there are not enough
    funds for this UserReinvestment.
    """
    if not is_user_reinvestment_period():
        raise NotInUserReinvestmentPeriodException()

    init_kwargs = kwargs.get('kwargs')
    # can't initialize admin_repayment without required 'project' kwarg
    if not init_kwargs or not init_kwargs.get('user'):
        raise NotEnoughFundingException()
    user = init_kwargs['user']
    if user.reinvest_pool < 0.0:
        raise NotEnoughFundingException()
Example #4
0
def pre_init_user_reinvestment(**kwargs):
    """
    Raises a NotEnoughFundingException before __init__ if there are not enough
    funds for this UserReinvestment.
    """
    if not is_user_reinvestment_period():
        raise NotInUserReinvestmentPeriodException()

    init_kwargs = kwargs.get('kwargs')
    # can't initialize admin_repayment without required 'project' kwarg
    if not init_kwargs or not init_kwargs.get('user'):
        raise NotEnoughFundingException()
    user = init_kwargs['user']
    if user.reinvest_pool < 0.0:
        raise NotEnoughFundingException()
Example #5
0
 def get_context_data(self, **kwargs):
     context = super(ProjectListReinvestmentView, self).get_context_data(**kwargs)
     context["is_reinvestment"] = True
     if not is_user_reinvestment_period():
         if self.user_profile.reinvest_pool > 0.0:
             context["error_msg"] = "You have ${0} to reinvest, " \
                                    "but the reinvestment period has ended for this month. " \
                                    "Please come back next month!" \
                 .format(self.user_profile.reinvest_pool)
         else:
             context["error_msg"] = "The reinvestment period has ended for this month. " \
                                    "Please come back next month!"
     else:
         active = Project.objects.get_eligible_projects_for_reinvestment()
         context["active_projects"] = filter(lambda p: p.amount_left > 0.0, active)
         if self.user_profile.reinvest_pool > 0.0:
             context["reinvestment_amount"] = self.user_profile.reinvest_pool
         else:
             context["error_msg"] = "You don't have funds to reinvest."
     return context
Example #6
0
 def get_context_data(self, **kwargs):
     context = super(ProjectListReinvestmentView, self).get_context_data(**kwargs)
     context["is_reinvestment"] = True
     if not is_user_reinvestment_period():
         if self.user_profile.reinvest_pool > 0.0:
                 context["error_msg"] = "You have ${0} to reinvest, " \
                                        "but the reinvestment period has ended for this month. " \
                                        "Please come back next month!" \
                     .format(self.user_profile.reinvest_pool)
         else:
             context["error_msg"] = "The reinvestment period has ended for this month. " \
                                    "Please come back next month!"
     else:
         active = Project.objects.get_eligible_projects_for_reinvestment()
         context["active_projects"] = filter(lambda p: p.amount_left > 0.0, active)
         if self.user_profile.reinvest_pool > 0.0:
             context["reinvestment_amount"] = self.user_profile.reinvest_pool
         else:
             context["error_msg"] = "You don't have funds to reinvest."
     return context
Example #7
0
    def get_context_data(self, **kwargs):
        context = super(ProjectListReinvestmentView, self).get_context_data(**kwargs)
        context["is_reinvestment"] = True
        if not is_user_reinvestment_period():
            if self.user_profile.reinvest_pool > 0.0:
                    context["error_msg"] = "You have ${0} to reinvest, " \
                                           "but user reinvest period has been end for this month. " \
                                           "Please came back before date {1} in current month"\
                        .format(self.user_profile.reinvest_pool, settings.ADMIN_REINVESTMENT_DATE['day'])
            else:
                context["error_msg"] = "User reinvest period has been end for this month. " \
                                       "Please came back before date {0} in current month"\
                    .format(settings.ADMIN_REINVESTMENT_DATE['day'])

        else:
            active = Project.objects.get_eligible_projects_for_reinvestment()
            context["active_projects"] = filter(lambda p: p.amount_left > 0.0, active)
            if self.user_profile.reinvest_pool > 0.0:
                context["reinvestment_amount"] = self.user_profile.reinvest_pool
            else:
                context["error_msg"] = "You don't have fund to reinvest"
        return context
Example #8
0
def pre_init_admin_reinvestment(**kwargs):
    """
    Raises a NotEnoughFundingException before __init__ if there are not enough
    funds for this AdminReinvestment.
    """
    if is_user_reinvestment_period():
        raise NotInAdminReinvestmentPeriodException()

    init_kwargs = kwargs.get('kwargs')
    # can't initialize admin_repayment without required 'amount' kwarg
    if not init_kwargs or not init_kwargs.get('amount'):
        raise NotEnoughFundingException()
    invest_amount = init_kwargs['amount']

    global_repay_amount = AdminRepayment.objects.aggregate(
        Sum('amount'))['amount__sum'] or 0.0
    global_reinvest_amount = AdminReinvestment.objects.aggregate(
        Sum('amount'))['amount__sum'] or 0.0
    global_user_reinvest_amount = UserReinvestment.objects.aggregate(
        Sum('amount'))['amount__sum'] or 0.0
    global_reinvest_pool = global_repay_amount - global_reinvest_amount - global_user_reinvest_amount
    if global_reinvest_pool - invest_amount < 0.0:
        raise NotEnoughFundingException()