本文整理汇总了Python中rogerthat.rpc.models.Mobile类的典型用法代码示例。如果您正苦于以下问题:Python Mobile类的具体用法?Python Mobile怎么用?Python Mobile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mobile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_unread_messages
def _create_unread_messages(stats, language, server_settings, user_profile):
sender_users = list({s[0] for s in stats[1] if s[0] != MC_DASHBOARD})
sender_profile_infos = dict(zip(sender_users, get_profile_infos(sender_users, allow_none_in_results=True)))
timezone_diff = 0
if user_profile.mobiles:
for mobile_detail in user_profile.mobiles:
mobile = Mobile.get(Mobile.create_key(mobile_detail.account))
timezone_diff = mobile.timezoneDeltaGMT or 0
break
avatars = dict() # { avatar_id : (avatar_data) }
def get_avatar_url(avatar_id):
avatar = avatars.get(avatar_id)
if not avatar:
if avatar_id in ('nuntiuz', 'unknown'):
if avatar == 'nuntiuz':
avatar = UNKNOWN_AVATAR
else:
avatar = NUNTIUZ_AVATAR
else:
avatar = get_avatar_cached(avatar_id, size=40)
avatars[avatar_id] = avatar
return 'cid:%s' % avatar_id
unread_messages = list() # sorted by message.creationTimestamp
for sender_user, message, broadcast_type, creation_time in sorted(stats[1], key=lambda x: x[3]):
sender_profile_info = sender_profile_infos.get(sender_user)
if sender_profile_info:
name = sender_profile_info.name
avatar_url = get_avatar_url(sender_profile_info.avatarId)
elif sender_user == MC_DASHBOARD:
name = get_profile_info_name(sender_user, user_profile.app_id)
avatar_url = get_avatar_url('nuntiuz')
else:
name = sender_user.email().split(':', 1)[0].split('/', 1)[0]
avatar_url = get_avatar_url('unknown')
creation_date_time = datetime.datetime.utcfromtimestamp(creation_time + timezone_diff)
creation_time_str = '%s, %s' % (format_date(creation_date_time, locale=language, format='short'),
format_time(creation_date_time, locale=language, format='short'))
if broadcast_type:
sender_user = add_slash_default(sender_user)
if len(name) > 43:
name = name[:40] + u'...'
unread_messages.append(UnreadMessage(name, avatar_url, message, broadcast_type, creation_time_str,
localize(language, 'email_reminder_unsubscribe_caption',
notification_type=xml_escape(broadcast_type) if broadcast_type else None,
service=xml_escape(name)),
generate_unsubscribe_broadcast_link(user_profile.user, sender_user, name,
broadcast_type)))
return unread_messages, avatars
示例2: get
def get(self):
now_ = now()
yesterday = datetime.datetime.fromtimestamp(now_ - 24 * 3600)
cleanup_size = 0
mobiles = Mobile.all().filter("status =", Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED).filter("timestamp <", yesterday)
for mobile in mobiles:
if mobile.status >= Mobile.STATUS_ACCOUNT_CREATED:
delete_xmpp_account(mobile.account , mobile.key())
else:
mobile.delete()
logging.info("Cleanup %s timedout unfinished registration Mobile records" % cleanup_size)
mobiles = Mobile.all().filter("status =", Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED | Mobile.STATUS_DELETE_REQUESTED | Mobile.STATUS_UNREGISTERED)
cleanup_size = self._cleanup_mobiles(mobiles)
mobiles = Mobile.all().filter("status =", Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED | Mobile.STATUS_DELETE_REQUESTED).filter("timestamp <", yesterday)
cleanup_size += self._cleanup_mobiles(mobiles)
logging.info("Cleanup %s to be deleted mobile records" % cleanup_size)
示例3: _send_notification_about_failed_location_fix
def _send_notification_about_failed_location_fix(user, friend, friend_mobile_key_name, target, error_status):
'''
@param user: The user who sent the location request.
@param friend: The user who failed to execute the location request.
@param friend_mobile_key_name: The key name of the friend's Mobile model.
@param target: The reason of the location request. One of GetLocationRequestTO.TARGET_*.
@param error_status: The reason of the failed location request. One of GetLocationErrorTO.STATUS_*.
'''
friend_profile, user_profile = get_profile_infos([friend, user], expected_types=[UserProfile, UserProfile])
app_name = get_app_name_by_id(user_profile.app_id)
friend_msg = None
user_reason_msg = None
if error_status in (GetLocationErrorTO.STATUS_AUTHORIZATION_DENIED,
GetLocationErrorTO.STATUS_AUTHORIZATION_ONLY_WHEN_IN_USE):
if error_status == GetLocationErrorTO.STATUS_AUTHORIZATION_DENIED:
friend_msg = localize(friend_profile.language, "_location_services_denied",
name=user_profile.name, app_name=app_name)
user_reason_msg = localize(user_profile.language, "_friend_denied_location_services",
name=friend_profile.name, app_name=app_name)
elif error_status == GetLocationErrorTO.STATUS_AUTHORIZATION_ONLY_WHEN_IN_USE:
friend_msg = localize(friend_profile.language, "_location_services_denied",
name=user_profile.name, app_name=app_name)
user_reason_msg = localize(user_profile.language, "_friend_denied_location_services",
name=friend_profile.name, app_name=app_name)
if friend_msg:
friend_mobile = Mobile.get_by_key_name(friend_mobile_key_name)
if friend_mobile.is_ios and friend_mobile.osVersion:
if friend_mobile.osVersion.startswith('7'):
friend_msg += "\n\n" + localize(friend_profile.language, "_enable_location_services_ios7",
app_name=app_name)
elif friend_mobile.osVersion.startswith('8'):
friend_msg += "\n\n" + localize(friend_profile.language, "_enable_location_services_ios8",
app_name=app_name)
if target == GetLocationRequestTO.TARGET_MOBILE:
user_msg = localize(user_profile.language,
"We could not determine the location of %(name)s.",
name=friend_profile.name)
elif target == GetLocationRequestTO.TARGET_MOBILE_FIRST_REQUEST_AFTER_GRANT:
user_msg = localize(user_profile.language,
"%(name)s accepted your location sharing request. Unfortunately we could not determine his/her location at this moment.",
name=friend_profile.name)
else:
logging.error("Don't know what to do in _send_notification_about_failed_location_fix.\n\nLocals:\n%s" % locals())
return
if user_reason_msg:
user_msg = u"%s (%s)" % (user_msg, user_reason_msg)
if user_msg and not friend_msg:
user_msg = u"%s\n\n%s" % (user_msg, localize(user_profile.language, "Please try again later."))
xg_on = db.create_transaction_options(xg=True)
db.run_in_transaction_options(xg_on, dashboardNotification, user, user_msg)
if friend_msg:
db.run_in_transaction_options(xg_on, dashboardNotification, friend, friend_msg)
示例4: push_app_settings_to_user
def push_app_settings_to_user(user_profile, app_id):
app_settings = get_app_settings(app_id)
if user_profile.mobiles:
mobiles = db.get([Mobile.create_key(mobile_detail.account) for mobile_detail in user_profile.mobiles])
for mobile in mobiles:
mobile_settings = get_mobile_settings_cached(mobile)
mobile_settings.version += 1
mobile_settings.put()
request = UpdateSettingsRequestTO()
request.settings = SettingsTO.fromDBSettings(app_settings, user_profile, mobile_settings)
updateSettings(update_settings_response_handler, logError, mobile.user, request=request)
示例5: push_app_settings_to_user
def push_app_settings_to_user(user_profile, app_id):
if user_profile.mobiles:
keys = [AppSettings.create_key(app_id)] + [Mobile.create_key(mobile_detail.account)
for mobile_detail in user_profile.mobiles]
entities = db.get(keys)
app_settings = entities.pop(0)
for mobile in entities:
mobile_settings = mobile.settings()
mobile_settings.version += 1
mobile_settings.put()
request = UpdateSettingsRequestTO()
request.settings = SettingsTO.fromDBSettings(mobile_settings, app_settings)
updateSettings(update_settings_response_handler, logError, mobile.user, request=request)
示例6: register_tst_mobile
def register_tst_mobile(email):
from rogerthat.rpc.models import Mobile
from rogerthat.rpc import users
from rogerthat.dal.profile import get_user_profile
from rogerthat.models.properties.profiles import MobileDetails
account = unicode(uuid.uuid4()) + u"@mc-tracker.com"
m = Mobile(key_name=account)
m.id = unicode(uuid.uuid4())
m.user = users.User(email)
m.account = account
m.description = email
m.status = Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED
m.type = Mobile.TYPE_ANDROID_HTTP
m.put()
p = get_user_profile(m.user)
if not p.mobiles:
p.mobiles = MobileDetails()
p.mobiles.addNew(account, Mobile.TYPE_ANDROID_HTTP, None, u"rogerthat")
p.put()
return m
示例7: set_json_rpc_user
def set_json_rpc_user(user, password, ignore_status=False):
from rogerthat.rpc.models import Mobile
try:
mobile = authenticate_user(user, password)
azzert(mobile)
_tlocal.set_user(mobile=mobile, user=mobile.user, app_id=None, mfr=False)
try:
mobile_string = Mobile.typeAsString(_tlocal.mobile.type)
except ValueError:
mobile_string = str(_tlocal.mobile.type)
logging.info("Request identity: %s (%s)", _tlocal.user, mobile_string)
return True
except:
logging.warn("set_json_rpc_user failed", exc_info=True)
clear_user()
return False
示例8: job
def job(message, filter_src, buttons, cursor=None):
from google.appengine.ext import deferred
filter_function = eval(filter_src)
query = Mobile.gql("WHERE status = %s" % (Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED))
query.with_cursor(cursor)
mobiles = query.fetch(100)
for m in mobiles:
logging.info("Applying filter on %s" % m.user.email())
# Patch because bad test data appears to be in the datastore
profile_info = get_profile_info(m.user)
if profile_info.isServiceIdentity:
continue
# End Patch
if filter_function(m):
deferred.defer(send_to_user, message, m.user, buttons, _transactional=db.is_in_transaction())
if len(mobiles) > 0:
return deferred.defer(job, message, filter_src, buttons, query.cursor(), _transactional=db.is_in_transaction())
示例9: user_statistic
def user_statistic():
qry1 = Mobile.all(keys_only=True).filter('status >=', 4).filter('status <', 8)
qry2 = FriendServiceIdentityConnection.all(keys_only=True)
qry3 = ServiceIdentity.all(keys_only=True)
qries = [ qry1, qry2, qry3 ]
def stats(qry):
cursor = None
fetched = 1
count = 0
while fetched != 0:
fetched = qry.with_cursor(cursor).count()
count += fetched
cursor = qry.cursor()
return count - 1
user_count, application_user_count, application_count = [stats(q) for q in qries]
us = UserStatisticsTO()
us.user_count = user_count
us.service_user_count = application_user_count
us.service_count = application_count
return us
示例10: get_active_mobiles_keys
def get_active_mobiles_keys():
return Mobile.all(keys_only=True).filter("status =", Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED | Mobile.STATUS_REGISTERED)
示例11: get_mobile_key_by_account
def get_mobile_key_by_account(email):
return db.Key.from_path(Mobile.kind(), email)
示例12: register_mobile
def register_mobile(human_user, name=None, app_id=App.APP_ID_ROGERTHAT, use_xmpp_kick_channel=True,
gcm_registration_id=None, language=None, ysaaa=False, firebase_registration_id=None,
hardware_model=None, sim_carrier_name=None, tos_version=None,
consent_push_notifications_shown=False, anonymous_account=None):
if anonymous_account:
anonymous_mobile = get_mobile_by_account(anonymous_account)
azzert(anonymous_mobile)
# First unregister currently registered mobiles
app_user = create_app_user(human_user, app_id)
mobiles = get_user_active_mobiles(app_user)
reason = None
device_name = get_device_name(hardware_model, sim_carrier_name)
if device_name:
reason = localize(language, u"Your device was unregistered because the same account was used to register the following device '%(device_name)s'",
device_name=device_name)
for m in mobiles:
unregister_mobile(app_user, m, reason)
# Create account
account = generate_account()
# Save mobile in datastore
mobile = Mobile(key_name=account.account)
mobile.id = unicode(uuid.uuid1())
mobile.description = "%s mobile" % app_user.email()
mobile.user = app_user
mobile.account = account.account
mobile.accountPassword = account.password
need_jabber_account = not APPSCALE and use_xmpp_kick_channel
if need_jabber_account:
mobile.status = Mobile.STATUS_NEW # Account created status is set as soon as the ejabberd account is ready
else:
mobile.status = Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED
if gcm_registration_id:
mobile.pushId = gcm_registration_id
if firebase_registration_id:
mobile.pushId = firebase_registration_id
mobile.put()
# AppScale deployments authenticate jabber users against rogerthat app directly
if need_jabber_account:
try_or_defer(create_jabber_account, account, mobile.key())
age_and_gender_set = False
app = get_app_by_id(app_id)
owncloud_password = unicode(uuid.uuid4()) if app.owncloud_base_uri else None
# Create profile for user if needed
deactivated_user_profile = get_deactivated_user_profile(app_user)
if deactivated_user_profile:
if deactivated_user_profile.birthdate is not None and deactivated_user_profile.gender is not None:
age_and_gender_set = True
if owncloud_password and not deactivated_user_profile.owncloud_password:
create_owncloud_account(
app_user, app.owncloud_base_uri, app.owncloud_admin_username, app.owncloud_admin_password, owncloud_password)
reactivate_user_profile(
deactivated_user_profile, app_user, owncloud_password, tos_version, consent_push_notifications_shown)
ActivationLog(timestamp=now(), email=app_user.email(), mobile=mobile,
description="Reactivate user account by registering a mobile").put()
else:
user_profile = get_user_profile(app_user)
if not user_profile:
create_user_profile(app_user, name or human_user.email(), language, ysaaa, owncloud_password, tos_version=tos_version,
consent_push_notifications_shown=consent_push_notifications_shown)
if owncloud_password:
create_owncloud_account(
app_user, app.owncloud_base_uri, app.owncloud_admin_username, app.owncloud_admin_password, owncloud_password)
else:
should_put = False
if user_profile.birthdate is not None and user_profile.gender is not None:
age_and_gender_set = True
if user_profile.isCreatedForService:
user_profile.isCreatedForService = False
should_put = True
if owncloud_password and not user_profile.owncloud_password:
user_profile.owncloud_password = owncloud_password
should_put = True
create_owncloud_account(
app_user, app.owncloud_base_uri, app.owncloud_admin_username, app.owncloud_admin_password, owncloud_password)
if tos_version:
user_profile.tos_version = tos_version
should_put = True
if should_put:
user_profile.put()
return account, mobile, age_and_gender_set
示例13: get_mobile_by_key
def get_mobile_by_key(key):
return Mobile.get(key)
示例14: finish_registration
def finish_registration(mobile_account, mobileInfo, accounts, invitor_code, invitor_secret, ipaddress):
from rogerthat.service.api import friends as service_api_friends
m = get_mobile_by_account(mobile_account)
mobile_key = m.key()
ms_key = MobileSettings.get(m).key()
profile_key = get_user_profile_key(m.user)
def trans():
mobile, ms, my_profile = db.get((mobile_key, ms_key, profile_key))
mobile.status = mobile.status | Mobile.STATUS_REGISTERED
mobile.type = mobileInfo.app_type
mobile.simCountry = mobileInfo.sim_country if mobileInfo.sim_country != MISSING else None
mobile.simCountryCode = mobileInfo.sim_country_code if mobileInfo.sim_country_code != MISSING else None
mobile.simCarrierCode = mobileInfo.sim_carrier_code if mobileInfo.sim_carrier_code != MISSING else None
mobile.simCarrierName = mobileInfo.sim_carrier_name if mobileInfo.sim_carrier_name != MISSING else None
mobile.netCountry = mobileInfo.net_country if mobileInfo.net_country != MISSING else None
mobile.netCountryCode = mobileInfo.net_country_code if mobileInfo.net_country_code != MISSING else None
mobile.netCarrierCode = mobileInfo.net_carrier_code if mobileInfo.net_carrier_code != MISSING else None
mobile.netCarrierName = mobileInfo.net_carrier_name if mobileInfo.net_carrier_name != MISSING else None
mobile.hardwareModel = mobileInfo.device_model_name
mobile.osVersion = mobileInfo.device_os_version if mobileInfo.device_os_version != MISSING else None
mobile.localeLanguage = mobileInfo.locale_language if mobileInfo.locale_language and mobileInfo.locale_language != MISSING else DEFAULT_LANGUAGE
mobile.localeCountry = mobileInfo.locale_country
mobile.timezone = mobileInfo.timezone if mobileInfo.timezone != MISSING else None
mobile.timezoneDeltaGMT = mobileInfo.timezone_delta_gmt if mobileInfo.timezone_delta_gmt != MISSING else None
if mobileInfo.app_major_version != MISSING and mobileInfo.app_minor_version != MISSING:
ms.majorVersion = mobileInfo.app_major_version
ms.minorVersion = mobileInfo.app_minor_version
# This is the official place where we set the profile language
my_profile.language = mobile.localeLanguage
my_profile.country = mobile.netCountry or mobile.simCountry or mobile.localeCountry
my_profile.timezone = mobile.timezone
my_profile.timezoneDeltaGMT = mobile.timezoneDeltaGMT
my_profile.mobiles = MobileDetails()
my_profile.mobiles.addNew(mobile.account, mobile.type, mobile.pushId, mobile.app_id)
mobile.put()
ms.put()
my_profile.put()
deferred.defer(_finishup_mobile_registration, mobile, accounts, invitor_code, invitor_secret, ipaddress,
ms_key, _transactional=True)
return mobile, my_profile
xg_on = db.create_transaction_options(xg=True)
mobile, my_profile = db.run_in_transaction_options(xg_on, trans)
channel.send_message(mobile.user, u'com.mobicage.registration.finished')
typestr = "Unknown type"
try:
typestr = Mobile.typeAsString(mobile.type)
except ValueError:
pass
server_settings = get_server_settings()
registration = get_registration_by_mobile(mobile)
if registration:
InstallationLog(parent=registration.installation, timestamp=now(), registration=registration,
mobile=mobile, profile=my_profile, description="Registration successful.").put()
if registration.installation and registration.installation.qr_url:
service_user = get_service_user_from_service_identity_user(registration.installation.service_identity_user)
service_identity = get_identity_from_service_identity_user(registration.installation.service_identity_user)
svc_profile = get_service_profile(service_user)
user_details = [UserDetailsTO.fromUserProfile(my_profile)]
if registration.installation.service_callback_result == ACCEPT_AND_CONNECT_ID:
service_identity_user = create_service_identity_user(service_user, service_identity)
si = get_service_identity(service_identity_user)
bizz_check(si, "ServiceIdentity %s not found" % service_identity_user)
xmpp.send_message(server_settings.xmppInfoMembers,
"User %s registered %s (%s) with account:\n%s\nFor service %s %s" % (
mobile.user, mobile.hardwareModel, typestr, mobile.account, si.name,
service_identity_user), message_type=xmpp.MESSAGE_TYPE_CHAT)
app_id = get_app_id_from_app_user(mobile.user)
if app_id not in si.appIds:
si.appIds.append(app_id)
put_and_invalidate_cache(si)
try_or_defer(makeFriends, mobile.user, service_identity_user, original_invitee=None, servicetag=None,
origin=None, notify_invitee=False, notify_invitor=False, user_data=None)
else:
xmpp.send_message(server_settings.xmppInfoMembers, "User %s registered %s (%s) with account:\n%s" % (
mobile.user, mobile.hardwareModel, typestr, mobile.account), message_type=xmpp.MESSAGE_TYPE_CHAT)
service_api_friends.register_result(register_result_response_receiver, logServiceError, svc_profile,
service_identity=service_identity,
user_details=user_details,
origin=REGISTRATION_ORIGIN_QR)
else:
xmpp.send_message(server_settings.xmppInfoMembers, "User %s registered %s (%s) with account:\n%s" % (
mobile.user, mobile.hardwareModel, typestr, mobile.account), message_type=xmpp.MESSAGE_TYPE_CHAT)
app = get_app_by_id(get_app_id_from_app_user(mobile.user))
if app.admin_services:
service_profiles = filter(None, db.get((get_profile_key(users.User(e)) for e in app.admin_services)))
if service_profiles:
user_details = [UserDetailsTO.fromUserProfile(my_profile)]
#.........这里部分代码省略.........
示例15: register_mobile
def register_mobile(human_user, name=None, app_id=App.APP_ID_ROGERTHAT, use_xmpp_kick_channel=True,
GCM_registration_id=None, language=None, ysaaa=False):
# First unregister currently registered mobiles
app_user = create_app_user(human_user, app_id)
mobiles = get_user_active_mobiles(app_user)
for m in mobiles:
unregister_mobile(app_user, m)
# Create account
account = generate_account()
# Save mobile in datastore
mobile = Mobile(key_name=account.account)
mobile.id = unicode(uuid.uuid1())
mobile.description = "%s mobile" % app_user.email()
mobile.user = app_user
mobile.account = account.account
mobile.accountPassword = account.password
need_jabber_account = not APPSCALE and use_xmpp_kick_channel
if need_jabber_account:
mobile.status = Mobile.STATUS_NEW # Account created status is set as soon as the ejabberd account is ready
else:
mobile.status = Mobile.STATUS_NEW | Mobile.STATUS_ACCOUNT_CREATED
if GCM_registration_id:
mobile.pushId = GCM_registration_id
mobile.put()
# AppScale deployments authenticate jabber users against rogerthat app directly
if need_jabber_account:
try_or_defer(create_jabber_account, account, mobile.key())
age_and_gender_set = False
# Create profile for user if needed
deactivated_user_profile = get_deactivated_user_profile(app_user)
if deactivated_user_profile:
if deactivated_user_profile.birthdate is not None and deactivated_user_profile.gender is not None:
age_and_gender_set = True
reactivate_user_profile(deactivated_user_profile, app_user)
ActivationLog(timestamp=now(), email=app_user.email(), mobile=mobile,
description="Reactivate user account by registering a mobile").put()
else:
user_profile = get_user_profile(app_user)
if not user_profile:
create_user_profile(app_user, name or human_user.email(), language, ysaaa)
else:
if user_profile.birthdate is not None and user_profile.gender is not None:
age_and_gender_set = True
if user_profile.isCreatedForService:
user_profile.isCreatedForService = False
user_profile.put()
return account, mobile, age_and_gender_set