本文整理汇总了Python中student.models.UserAttribute类的典型用法代码示例。如果您正苦于以下问题:Python UserAttribute类的具体用法?Python UserAttribute怎么用?Python UserAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserAttribute类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _record_utm_registration_attribution
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
)
开发者ID:mitocw,项目名称:edx-platform,代码行数:28,代码来源:register.py
示例2: test_command_by_activation_keys
def test_command_by_activation_keys(self):
"""
Test population of created_on_site attribute by activation keys.
"""
call_command(
"populate_created_on_site_user_attribute",
"--activation-keys", self.activation_keys,
"--site-domain", self.site.domain
)
for register_user in self.registered_users:
self.assertEqual(UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE), self.site.domain)
# Populate 'created_on_site' attribute with different site domain
call_command(
"populate_created_on_site_user_attribute",
"--activation-keys", self.activation_keys,
"--site-domain", self.site_other.domain
)
for register_user in self.registered_users:
# 'created_on_site' attribute already exists. Attribute's value will not change
self.assertNotEqual(
UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE),
self.site_other.domain
)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:26,代码来源:test_populate_created_on_site_user_attribute.py
示例3: create_or_set_user_attribute_created_on_site
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)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:7,代码来源:helpers.py
示例4: _record_affiliate_registration_attribution
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)
开发者ID:mitocw,项目名称:edx-platform,代码行数:8,代码来源:register.py
示例5: create_or_set_user_attribute_created_on_site
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)
开发者ID:jolyonb,项目名称:edx-platform,代码行数:10,代码来源:helpers.py
示例6: _get_unsynced_users
def _get_unsynced_users(self, site_domain, last_synced_user, days_threshold):
"""
Args:
site_domain: site where we need unsynced users
last_synced_user: last synced user
days_threshold: number of days threshold to sync users in case we don't have last synced user
Returns: Ordered list of users needs to be synced
"""
if last_synced_user:
users = User.objects.select_related('profile').filter(id__gt=last_synced_user.id).order_by('pk')
else:
# If we don't have last synced user get all users who joined on between today and threshold days ago
start_date = datetime.now().date() - timedelta(days_threshold)
self.stdout.write(
'Started pulling unsynced contacts for site {site} from {start_date}'.format(
site=site_domain, start_date=start_date
)
)
users = User.objects.select_related('profile').filter(date_joined__date__gte=start_date).order_by('pk')
unsynced_users = [
user for user in use_read_replica_if_available(users)
if UserAttribute.get_user_attribute(user, 'created_on_site') == site_domain
]
return unsynced_users
开发者ID:jolyonb,项目名称:edx-platform,代码行数:27,代码来源:sync_hubspot_contacts.py
示例7: test_with_invalid_site_domain
def test_with_invalid_site_domain(self, populate):
"""
Test management command with invalid site domain.
"""
fake_site_domain = 'fake-site-domain'
with mock.patch('__builtin__.raw_input', return_value=populate):
call_command(
"populate_created_on_site_user_attribute",
"--users", self.user_ids,
"--site-domain", fake_site_domain
)
for user in self.users:
if populate == 'y':
self.assertEqual(UserAttribute.get_user_attribute(user, CREATED_ON_SITE), fake_site_domain)
else:
self.assertIsNone(UserAttribute.get_user_attribute(user, CREATED_ON_SITE))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:17,代码来源:test_populate_created_on_site_user_attribute.py
示例8: test_get_set_attribute
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)
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:7,代码来源:tests.py
示例9: test_affiliate_referral_attribution
def test_affiliate_referral_attribution(self):
"""
Verify that a referral attribution is recorded if an affiliate
cookie is present upon a new user's registration.
"""
affiliate_id = 'test-partner'
self.client.cookies[settings.AFFILIATE_COOKIE_NAME] = affiliate_id
user = self.create_account_and_fetch_profile().user
self.assertEqual(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID), affiliate_id)
开发者ID:edx,项目名称:edx-platform,代码行数:9,代码来源:test_register.py
示例10: test_command_with_invalid_arguments
def test_command_with_invalid_arguments(self):
"""
Test management command with invalid user ids and activation keys.
"""
user = self.users[0]
call_command(
"populate_created_on_site_user_attribute",
"--users", '9{id}'.format(id=user.id), # invalid id
"--site-domain", self.site.domain
)
self.assertIsNone(UserAttribute.get_user_attribute(user, CREATED_ON_SITE))
register_user = self.registered_users[0]
call_command(
"populate_created_on_site_user_attribute",
"--activation-keys", "invalid-{key}".format(key=register_user.activation_key), # invalid key
"--site-domain", self.site.domain
)
self.assertIsNone(UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:19,代码来源:test_populate_created_on_site_user_attribute.py
示例11: _create_users
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)
开发者ID:jolyonb,项目名称:edx-platform,代码行数:20,代码来源:test_sync_hubspot_contacts.py
示例12: handle
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))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:35,代码来源:populate_created_on_site_user_attribute.py
示例13: test_no_referral
def test_no_referral(self):
"""Verify that no referral is recorded when a cookie is not present."""
utm_cookie_name = 'edx.test.utm'
with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
instance = config.return_value
instance.utm_cookie_name = utm_cookie_name
self.assertIsNone(self.client.cookies.get(settings.AFFILIATE_COOKIE_NAME))
self.assertIsNone(self.client.cookies.get(utm_cookie_name))
user = self.create_account_and_fetch_profile().user
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign')))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')))
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT))
开发者ID:edx,项目名称:edx-platform,代码行数:17,代码来源:test_register.py
示例14: test_utm_referral_attribution
def test_utm_referral_attribution(self):
"""
Verify that a referral attribution is recorded if an affiliate
cookie is present upon a new user's registration.
"""
utm_cookie_name = 'edx.test.utm'
with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
instance = config.return_value
instance.utm_cookie_name = utm_cookie_name
timestamp = 1475521816879
utm_cookie = {
'utm_source': 'test-source',
'utm_medium': 'test-medium',
'utm_campaign': 'test-campaign',
'utm_term': 'test-term',
'utm_content': 'test-content',
'created_at': timestamp
}
created_at = datetime.fromtimestamp(timestamp / float(1000), tz=pytz.UTC)
self.client.cookies[utm_cookie_name] = json.dumps(utm_cookie)
user = self.create_account_and_fetch_profile().user
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')),
utm_cookie.get('utm_source')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')),
utm_cookie.get('utm_medium')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign')),
utm_cookie.get('utm_campaign')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')),
utm_cookie.get('utm_term')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')),
utm_cookie.get('utm_content')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT),
str(created_at)
)
开发者ID:edx,项目名称:edx-platform,代码行数:48,代码来源:test_register.py
示例15: _get_batched_users
def _get_batched_users(self, site_domain, users_queryset, offset, users_query_batch_size):
"""
Args:
site_domain: site where we need unsynced users
users_queryset: users_queryset to slice
users_query_batch_size: slice size
Returns: site users
"""
self.stdout.write(
u'Fetching Users for site {site} from {start} to {end}'.format(
site=site_domain, start=offset, end=offset + users_query_batch_size
)
)
users = users_queryset.select_related('profile')[offset: offset + users_query_batch_size]
site_users = [
user for user in users
if UserAttribute.get_user_attribute(user, 'created_on_site') == site_domain
]
self.stdout.write(u'\tSite Users={count}'.format(count=len(site_users)))
return site_users
开发者ID:edx,项目名称:edx-platform,代码行数:24,代码来源:sync_hubspot_contacts.py
示例16: test_incomplete_utm_referral
def test_incomplete_utm_referral(self):
"""Verify that no referral is recorded when a cookie is not present."""
utm_cookie_name = 'edx.test.utm'
with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
instance = config.return_value
instance.utm_cookie_name = utm_cookie_name
utm_cookie = {
'utm_source': 'test-source',
'utm_medium': 'test-medium',
# No campaign
'utm_term': 'test-term',
'utm_content': 'test-content',
# No created at
}
self.client.cookies[utm_cookie_name] = json.dumps(utm_cookie)
user = self.create_account_and_fetch_profile().user
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')),
utm_cookie.get('utm_source')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')),
utm_cookie.get('utm_medium')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')),
utm_cookie.get('utm_term')
)
self.assertEqual(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')),
utm_cookie.get('utm_content')
)
self.assertIsNone(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign'))
)
self.assertIsNone(
UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT)
)
开发者ID:edx,项目名称:edx-platform,代码行数:41,代码来源:test_register.py
示例17: test_unicode
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)))
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:4,代码来源:tests.py
示例18: test_no_referral
def test_no_referral(self):
"""Verify that no referral is recorded when a cookie is not present."""
self.assertIsNone(self.client.cookies.get(settings.AFFILIATE_COOKIE_NAME)) # pylint: disable=no-member
user = self.create_account_and_fetch_profile().user
self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID))
开发者ID:tanmaykm,项目名称:edx-platform,代码行数:5,代码来源:test_create_account.py
示例19: test_created_on_site_user_attribute_set
def test_created_on_site_user_attribute_set(self):
profile = self.create_account_and_fetch_profile(host=self.site.domain)
self.assertEqual(UserAttribute.get_user_attribute(profile.user, 'created_on_site'), self.site.domain)
开发者ID:edx,项目名称:edx-platform,代码行数:3,代码来源:test_register.py
注:本文中的student.models.UserAttribute类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论