コード例 #1
0
ファイル: models.py プロジェクト: sttwister/django-lean
    def _record(cls, goal_name, experiment_user):
        """
        Records a goal achievement for the experiment user.
        If the user does not have an anonymous visitor ID, does nothing.
        If the goal name is not known, throws an Exception.
        """

        # Create goal type if necesarry
        if getattr(settings, 'LEAN_AUTOCREATE_GOAL_TYPES', False):
            (goal_type, created) = GoalType.objects.get_or_create(name=goal_name)
        else:
            goal_type = GoalType.objects.get(name=goal_name)

        user = experiment_user.get_registered_user()
        if user:
            for participant in Participant.objects.filter(user=user):
                if participant.experiment.state == Experiment.ENABLED_STATE:
                    goal_record = GoalRecord.objects.create(
                        goal_type=goal_type, participant=participant
                    )
                    goal_recorded.send(sender=cls, goal_record=goal_record,
                                       experiment_user=experiment_user)
        else:
            anonymous_id = experiment_user.get_anonymous_id()
            anonymous_visitor = AnonymousVisitor.objects.get(id=anonymous_id)
            participant = Participant.objects.get(anonymous_visitor=anonymous_visitor)

            goal_record = GoalRecord.objects.create(
                goal_type=goal_type, participant=participant
            )
            goal_recorded.send(sender=cls, goal_record=goal_record,
                               experiment_user=experiment_user)
            return goal_record
コード例 #2
0
ファイル: models.py プロジェクト: pombredanne/django-lean
    def _record(cls, goal_name, experiment_user):
        """
        Records a goal achievement for the experiment user.
        If the user does not have an anonymous visitor ID, does nothing.
        If the goal name is not known, throws an Exception.
        """
        anonymous_id = experiment_user.get_anonymous_id()
        if anonymous_id:
            anonymous_visitor = AnonymousVisitor.objects.get(id=anonymous_id)
            if getattr(settings, "LEAN_AUTOCREATE_GOAL_TYPES", False):
                (goal_type, created) = GoalType.objects.get_or_create(name=goal_name)
            else:
                goal_type = GoalType.objects.get(name=goal_name)

            goal_record = GoalRecord.objects.create(goal_type=goal_type, anonymous_visitor=anonymous_visitor)
            goal_recorded.send(sender=cls, goal_record=goal_record, experiment_user=experiment_user)
            return goal_record
コード例 #3
0
    def _record(cls, goal_name, experiment_user):
        """
        Records a goal achievement for the experiment user.
        If the user does not have an anonymous visitor ID, does nothing.
        If the goal name is not known, creates a goal with that name.
        """
        anonymous_id = experiment_user.get_anonymous_id()
        if anonymous_id:
            anonymous_visitor = AnonymousVisitor.objects.get(id=anonymous_id)
            if getattr(settings, 'LEAN_AUTOCREATE_GOAL_TYPES', False):
                (goal_type,
                 created) = GoalType.objects.get_or_create(name=goal_name)
            else:
                goal_type = GoalType.objects.get(name=goal_name)

            goal_record = GoalRecord.objects.create(
                goal_type=goal_type, anonymous_visitor=anonymous_visitor)
            goal_recorded.send(sender=cls,
                               goal_record=goal_record,
                               experiment_user=experiment_user)
            return goal_record