Commits

Anonymous committed c03c64b

Prevent duplicate enrollments in experiments.

  • Participants
  • Parent commits cc7e51c

Comments (0)

Files changed (2)

django_lean/experiments/templatetags/experiments.py

     def create_user(self, context):
         return self.__user_factory.create_user(context)
 
+    def get_user(self, context):
+        request = context.get('request', None)
+        if request is None:
+            return self.create_user(context)
+        if not hasattr(request, 'experiment_user'):
+            request.experiment_user = self.create_user(context)
+        return request.experiment_user
+
 
 class ExperimentNode(BaseExperimentNode):
     def __init__(self, node_list, experiment_name, group_name, user_factory):
         self.node_list = node_list
         self.experiment_name = experiment_name
         self.group_name = group_name
-    
+
     def render(self, context):
-        user = self.create_user(context)
+        user = self.get_user(context)
         should_render = False
         
         if self.group_name == "test":

django_lean/experiments/tests/test_tags.py

         internal_render_result = "rendered"
         parser = self.mox.CreateMockAnything()
         child_node_list = self.mox.CreateMockAnything()
-        context = self.mox.CreateMockAnything()
+        context = {}
         user_factory = self.mox.CreateMockAnything()
         token = self.mox.CreateMockAnything()
         token.split_contents().AndReturn(token_tuple)