Adds a split_test_module XModule, that can choose one of its children
to display, based on a get_condition_for_user API added to the runtime.
To test, add something like this to an xml course, or make equivalent
tweaks in mongo.
<vertical url_name="split_test_vert">
<split_test url_name="split1" experiment_id="0" condition_id_to_child='{"0": "i4x://MITx/6.00x/html/split_test_cond0", "1": "i4x://MITx/6.00x/html/split_test_cond1"}'>
<html url_name="split_test_cond0">condition 0</html>
<html url_name="split_test_cond1">condition 1</html>
</split_test>
</vertical>
Also needs an experiment configured in the course policy json: e.g.
"user_partitions": [{"id": 0,
"name": "Experiment 0",
"description": "Unicorns?",
"version": 1,
"groups": [{"id": 0,
"name": "group 0",
"version": 1},
{"id": 1,
"name": "group 1",
"version": 1}]}]
(This particular snippet will work inside a course with org MITx
and course name 6.00x)
Co-Author: Sarina Canelake <sarina@edx.org>
Co-Author: Julia Hansbrough <julia@edx.org>
Co-Author: Diana Huang <diana@edx.org>
Co-Author: Calen Pennington <cale@edx.org>
[LMS-2095]
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from django.contrib.auth.models import User
|
|
from django.db import models
|
|
|
|
|
|
class UserPreference(models.Model):
|
|
"""A user's preference, stored as generic text to be processed by client"""
|
|
user = models.ForeignKey(User, db_index=True, related_name="+")
|
|
key = models.CharField(max_length=255, db_index=True)
|
|
value = models.TextField()
|
|
|
|
class Meta:
|
|
unique_together = ("user", "key")
|
|
|
|
@classmethod
|
|
def set_preference(cls, user, preference_key, preference_value):
|
|
"""
|
|
Sets the user preference for a given key
|
|
"""
|
|
user_pref, _ = cls.objects.get_or_create(user=user, key=preference_key)
|
|
user_pref.value = preference_value
|
|
user_pref.save()
|
|
|
|
@classmethod
|
|
def get_preference(cls, user, preference_key, default=None):
|
|
"""
|
|
Gets the user preference value for a given key
|
|
|
|
Returns the given default if there isn't a preference for the given key
|
|
"""
|
|
|
|
try:
|
|
user_pref = cls.objects.get(user=user, key=preference_key)
|
|
return user_pref.value
|
|
except cls.DoesNotExist:
|
|
return default
|
|
|
|
|
|
class UserCourseTag(models.Model):
|
|
"""
|
|
Per-course user tags, to be used by various things that want to store tags about
|
|
the user. Added initially to store assignment to experimental groups.
|
|
"""
|
|
user = models.ForeignKey(User, db_index=True, related_name="+")
|
|
key = models.CharField(max_length=255, db_index=True)
|
|
course_id = models.CharField(max_length=255, db_index=True)
|
|
value = models.TextField()
|
|
|
|
class Meta:
|
|
unique_together = ("user", "course_id", "key")
|