本文整理汇总了Python中student.models.UserAttribute.set_user_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python UserAttribute.set_user_attribute方法的具体用法?Python UserAttribute.set_user_attribute怎么用?Python UserAttribute.set_user_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.UserAttribute
的用法示例。
在下文中一共展示了UserAttribute.set_user_attribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def handle(self, *args, **options):
site_domain = options['site_domain']
user_ids = options['users'].split(',') if options['users'] else []
activation_keys = options['activation_keys'].split(',') if options['activation_keys'] else []
if not user_ids and not activation_keys:
raise CommandError('You must provide user ids or activation keys.')
try:
Site.objects.get(domain__exact=site_domain)
except Site.DoesNotExist:
question = "The site you specified is not configured as a Site in the system. " \
"Are you sure you want to continue? (y/n):"
if str(raw_input(question)).lower().strip()[0] != 'y':
return
for user_id in user_ids:
try:
user = User.objects.get(id=user_id)
if UserAttribute.get_user_attribute(user, CREATED_ON_SITE):
self.stdout.write("created_on_site attribute already exists for user id: {id}".format(id=user_id))
else:
UserAttribute.set_user_attribute(user, CREATED_ON_SITE, site_domain)
except User.DoesNotExist:
self.stdout.write("This user id [{id}] does not exist in the system.".format(id=user_id))
for key in activation_keys:
try:
user = Registration.objects.get(activation_key=key).user
if UserAttribute.get_user_attribute(user, CREATED_ON_SITE):
self.stdout.write("created_on_site attribute already exists for user id: {id}".format(id=user.id))
else:
UserAttribute.set_user_attribute(user, CREATED_ON_SITE, site_domain)
except Registration.DoesNotExist:
self.stdout.write("This activation key [{key}] does not exist in the system.".format(key=key))
示例2: test_get_set_attribute
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def test_get_set_attribute(self):
self.assertIsNone(UserAttribute.get_user_attribute(self.user, self.name))
UserAttribute.set_user_attribute(self.user, self.name, self.value)
self.assertEqual(UserAttribute.get_user_attribute(self.user, self.name), self.value)
new_value = 'new_value'
UserAttribute.set_user_attribute(self.user, self.name, new_value)
self.assertEqual(UserAttribute.get_user_attribute(self.user, self.name), new_value)
示例3: _record_utm_registration_attribution
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def _record_utm_registration_attribution(request, user):
"""
Attribute this user's registration to the latest UTM referrer, if
applicable.
"""
utm_cookie_name = RegistrationCookieConfiguration.current().utm_cookie_name
utm_cookie = request.COOKIES.get(utm_cookie_name)
if user and utm_cookie:
utm = json.loads(utm_cookie)
for utm_parameter_name in REGISTRATION_UTM_PARAMETERS:
utm_parameter = utm.get(utm_parameter_name)
if utm_parameter:
UserAttribute.set_user_attribute(
user,
REGISTRATION_UTM_PARAMETERS.get(utm_parameter_name),
utm_parameter
)
created_at_unixtime = utm.get('created_at')
if created_at_unixtime:
# We divide by 1000 here because the javascript timestamp generated is in milliseconds not seconds.
# PYTHON: time.time() => 1475590280.823698
# JS: new Date().getTime() => 1475590280823
created_at_datetime = datetime.datetime.fromtimestamp(int(created_at_unixtime) / float(1000), tz=UTC)
UserAttribute.set_user_attribute(
user,
REGISTRATION_UTM_CREATED_AT,
created_at_datetime
)
示例4: create_or_set_user_attribute_created_on_site
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def create_or_set_user_attribute_created_on_site(user, site):
"""
Create or Set UserAttribute indicating the microsite site the user account was created on.
User maybe created on 'courses.edx.org', or a white-label site
"""
if site:
UserAttribute.set_user_attribute(user, 'created_on_site', site.domain)
示例5: _record_affiliate_registration_attribution
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def _record_affiliate_registration_attribution(request, user):
"""
Attribute this user's registration to the referring affiliate, if
applicable.
"""
affiliate_id = request.COOKIES.get(settings.AFFILIATE_COOKIE_NAME)
if user and affiliate_id:
UserAttribute.set_user_attribute(user, REGISTRATION_AFFILIATE_ID, affiliate_id)
示例6: create_or_set_user_attribute_created_on_site
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def create_or_set_user_attribute_created_on_site(user, site):
"""
Create or Set UserAttribute indicating the microsite site the user account was created on.
User maybe created on 'courses.edx.org', or a white-label site. Due to the very high
traffic on this table we now ignore the default site (eg. 'courses.edx.org') and
code which comsumes this attribute should assume a 'created_on_site' which doesn't exist
belongs to the default site.
"""
if site and site.id != settings.SITE_ID:
UserAttribute.set_user_attribute(user, 'created_on_site', site.domain)
示例7: _create_users
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def _create_users(cls, site_conf):
# Create some test users
for i in range(1, 11):
profile_meta = {
"first_name": "First Name{0}".format(i),
"last_name": "Last Name{0}".format(i),
"company": "Company{0}".format(i),
"title": "Title{0}".format(i),
"state": "State{0}".format(i),
"country": "US",
}
loe = UserProfile.LEVEL_OF_EDUCATION_CHOICES[0][0]
date_joined = timezone.now() - timedelta(i)
user = UserFactory(date_joined=date_joined)
user_profile = user.profile
user_profile.level_of_education = loe
user_profile.meta = json.dumps(profile_meta)
user_profile.save() # pylint: disable=no-member
UserAttribute.set_user_attribute(user, 'created_on_site', site_conf.site.domain)
cls.users.append(user)
示例8: test_unicode
# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import set_user_attribute [as 别名]
def test_unicode(self):
UserAttribute.set_user_attribute(self.user, self.name, self.value)
for field in (self.name, self.value, self.user.username):
self.assertIn(field, unicode(UserAttribute.objects.get(user=self.user)))