Exemple #1
0
 def create_campaign_goal_association(self, campaign, goal, user, participation, pledge=None):
     cga = CampaignGoalAssociation()
     cga.user_id = user.id
     cga.campaign_id = campaign.id
     cga.campaign_goal_id = goal.id
     cga.participation = participation
     if pledge is not None:
         cga.pledge = pledge
     self.commit_model(cga)
     return cga
Exemple #2
0
 def create_campaign_goal_association(self,
                                      campaign,
                                      goal,
                                      user,
                                      participation,
                                      pledge=None):
     cga = CampaignGoalAssociation()
     cga.user_id = user.id
     cga.campaign_id = campaign.id
     cga.campaign_goal_id = goal.id
     cga.participation = participation
     if pledge is not None:
         cga.pledge = pledge
     self.commit_model(cga)
     return cga
Exemple #3
0
def associate_user_with_goal(campaign_goal, user, participation, pledge=None):
    """Associate given user with ``campaign_goal``. The association will be described by
    ``participation``, which can be one of 'opted-in', 'opted-out', 'participating',
    'nonparticipating'. The values 'participating' and 'nonparticipating' should only be used
    for default participation descriptions.  If a use opts to change their participation, use
    appropriate descriptor of 'opted-in' or 'opted-out'. These rules should be followed precisely
    for reporting purposes.

    :param campaign: The campaign which to associate the user.
    :type campaign: :class:`pooldlib.postgresql.models.Campaign`
    :param user: The user to associate.
    :type user: :class:`pooldlib.postgresql.models.User`
    :param role: The role to assign the user (either `organizer` or `participant`)
    :type role: string
    :param pledge: The amount the user has pledged to the campaign (optional).
    :type pledge: Decimal

    :raises: :class:`pooldlib.exceptions.InvalidGoalParticipationNameError`
             :class:`pooldlib.exceptions.DuplicateCampaignGoalUserAssociationError`
    """
    cga = CampaignGoalAssociationModel()
    cga.campaign_id = campaign_goal.campaign.id
    cga.campaign_goal = campaign_goal
    cga.user = user
    cga.participation = participation
    cga.pledge = pledge

    with transaction_session() as session:
        session.add(cga)
        try:
            session.commit()
        except SQLAlchemyDataError:
            raise InvalidGoalParticipationNameError()
        except SQLAlchemyIntegrityError:
            raise DuplicateCampaignGoalUserAssociationError()
    return cga
Exemple #4
0
def associate_user_with_goal(campaign_goal, user, participation, pledge=None):
    """Associate given user with ``campaign_goal``. The association will be described by
    ``participation``, which can be one of 'opted-in', 'opted-out', 'participating',
    'nonparticipating'. The values 'participating' and 'nonparticipating' should only be used
    for default participation descriptions.  If a use opts to change their participation, use
    appropriate descriptor of 'opted-in' or 'opted-out'. These rules should be followed precisely
    for reporting purposes.

    :param campaign: The campaign which to associate the user.
    :type campaign: :class:`pooldlib.postgresql.models.Campaign`
    :param user: The user to associate.
    :type user: :class:`pooldlib.postgresql.models.User`
    :param role: The role to assign the user (either `organizer` or `participant`)
    :type role: string
    :param pledge: The amount the user has pledged to the campaign (optional).
    :type pledge: Decimal

    :raises: :class:`pooldlib.exceptions.InvalidGoalParticipationNameError`
             :class:`pooldlib.exceptions.DuplicateCampaignGoalUserAssociationError`
    """
    cga = CampaignGoalAssociationModel()
    cga.campaign_id = campaign_goal.campaign.id
    cga.campaign_goal = campaign_goal
    cga.user = user
    cga.participation = participation
    cga.pledge = pledge

    with transaction_session() as session:
        session.add(cga)
        try:
            session.commit()
        except SQLAlchemyDataError:
            raise InvalidGoalParticipationNameError()
        except SQLAlchemyIntegrityError:
            raise DuplicateCampaignGoalUserAssociationError()
    return cga