Anonymous avatar Anonymous committed c03c64b

Prevent duplicate enrollments in experiments.

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.