當前位置: 首頁>>代碼示例>>Python>>正文


Python MobileClient.query方法代碼示例

本文整理匯總了Python中models.mobile_client.MobileClient.query方法的典型用法代碼示例。如果您正苦於以下問題:Python MobileClient.query方法的具體用法?Python MobileClient.query怎麽用?Python MobileClient.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.mobile_client.MobileClient的用法示例。


在下文中一共展示了MobileClient.query方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def post(self):
        if not self.user_bundle.user:
            self.response.set_status(401)
            return

        user_id = self.user_bundle.user.user_id()
        fcm_token = self.request.get('fcm_token')
        uuid = self.request.get('uuid')
        display_name = self.request.get('display_name')
        client_type = ClientType.WEB

        query = MobileClient.query(
                MobileClient.user_id == user_id,
                MobileClient.device_uuid == uuid,
                MobileClient.client_type == client_type)
        if query.count() == 0:
            # Record doesn't exist yet, so add it
            MobileClient(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                messaging_id=fcm_token,
                client_type=client_type,
                device_uuid=uuid,
                display_name=display_name).put()
        else:
            # Record already exists, update it
            client = query.fetch(1)[0]
            client.messaging_id = fcm_token
            client.display_name = display_name
            client.put()
開發者ID:CarlColglazier,項目名稱:the-blue-alliance,代碼行數:32,代碼來源:ajax_controller.py

示例2: ping_client

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def ping_client(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to ping client")

        user_id = PushHelper.user_email_to_id(current_user.email())
        gcm_id = request.mobile_id

        # Find a Client for the current user with the passed GCM ID
        clients = MobileClient.query(MobileClient.messaging_id == gcm_id, ancestor=ndb.Key(Account, user_id)).fetch(1)
        if len(clients) == 0:
            # No Client for user with that push token - bailing
            return BaseResponse(code=404, message="Invalid push token for user")
        else:
            client = clients[0]
            response = NotificationHelper.send_ping(client)
            # If we got a response from the send_ping method, it was sent via TBANS
            # We'll bubble up any errors we got back
            if response:
                if response.code == 200:
                    return BaseResponse(code=200, message="Ping sent")
                else:
                    return BaseResponse(code=response.code, message="Error pinging client - {}".format(response.message))
            else:
                return BaseResponse(code=200, message="Ping sent")
開發者ID:ZachOrr,項目名稱:the-blue-alliance,代碼行數:27,代碼來源:mobile_main.py

示例3: post

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def post(self):
        self._require_login("/account/register")
        self._require_registration("/account/register")

        # Check to make sure that they aren't trying to edit another user
        current_user_account_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get("account_id")
        if target_account_id == current_user_account_id:
            url = self.request.get("url")
            secret_key = self.request.get("secret")
            query = MobileClient.query(
                MobileClient.messaging_id == url, ancestor=ndb.Key(Account, current_user_account_id)
            )
            if query.count() == 0:
                # Webhook doesn't exist, add it
                verification_key = NotificationHelper.verify_webhook(url, secret_key)
                client = MobileClient(
                    parent=self.user_bundle.account.key,
                    user_id=current_user_account_id,
                    messaging_id=url,
                    display_name=self.request.get("name"),
                    secret=secret_key,
                    client_type=ClientType.WEBHOOK,
                    verified=False,
                    verification_code=verification_key,
                )
                client.put()
            else:
                # Webhook already exists. Update the secret
                current = query.fetch()[0]
                current.secret = secret_key
                current.put()
            self.redirect("/account")
        else:
            self.redirect("/")
開發者ID:cmlicata,項目名稱:the-blue-alliance,代碼行數:37,代碼來源:webhook_controller.py

示例4: register_client

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def register_client(self, request):
        user_id = get_current_user_id(self.headers)
        if user_id is None:
            return BaseResponse(code=401, message="Unauthorized to register")
        gcm_id = request.mobile_id
        os = ClientType.enums[request.operating_system]
        name = request.name
        uuid = request.device_uuid

        query = MobileClient.query(
                MobileClient.user_id == user_id,
                MobileClient.device_uuid == uuid,
                MobileClient.client_type == os)
        # trying to figure out an elusive dupe bug
        logging.info("DEBUGGING")
        logging.info("User ID: {}".format(user_id))
        logging.info("UUID: {}".format(uuid))
        logging.info("Count: {}".format(query.count()))
        if query.count() == 0:
            # Record doesn't exist yet, so add it
            MobileClient(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                messaging_id=gcm_id,
                client_type=os,
                device_uuid=uuid,
                display_name=name).put()
            return BaseResponse(code=200, message="Registration successful")
        else:
            # Record already exists, update it
            client = query.fetch(1)[0]
            client.messaging_id = gcm_id
            client.display_name = name
            client.put()
            return BaseResponse(code=304, message="Client already exists")
開發者ID:ZachOrr,項目名稱:the-blue-alliance,代碼行數:37,代碼來源:clientapi_service.py

示例5: get_client_ids_for_users

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def get_client_ids_for_users(cls, os_type, user_list):
     output = []
     for user in user_list:
         client_list = MobileClient.query(MobileClient.user_id == user, MobileClient.client_type == ClientType.enums[os_type]).fetch()
         for client in client_list:
             output.append(client.messaging_id)
     return output
開發者ID:dewdn2,項目名稱:the-blue-alliance,代碼行數:9,代碼來源:push_helper.py

示例6: get

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def get(self):
        self._require_admin()

        all_clients = MobileClient.query()
        android = all_clients.filter(MobileClient.client_type == ClientType.OS_ANDROID).count()
        ios = all_clients.filter(MobileClient.client_type == ClientType.OS_IOS).count()
        webhook = all_clients.filter(MobileClient.client_type == ClientType.WEBHOOK).count()

        var = Sitevar.get_by_id('notifications.enable')
        if var is None or not var.values_json == "true":
            push_enabled = False
        else:
            push_enabled = True

        self.template_values.update({
            'mobile_users': all_clients.count(),
            'android_users': android,
            'ios_users': ios,
            'webhooks': webhook,
            'broadcast_success': self.request.get('broadcast_success'),
            'push_enabled': push_enabled,
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/mobile_dashboard.html')
        self.response.out.write(template.render(path, self.template_values))
開發者ID:brycematsuda,項目名稱:the-blue-alliance,代碼行數:27,代碼來源:admin_mobile_controller.py

示例7: get_all_mobile_clients

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def get_all_mobile_clients(cls, client_types=[]):
     output = []
     if client_types == []:
         return output
     clients = MobileClient.query(MobileClient.client_type.IN(client_types))
     for user in clients:
         output.append(user.user_id)
     return output
開發者ID:BowlesCR,項目名稱:the-blue-alliance,代碼行數:10,代碼來源:push_helper.py

示例8: get_client_ids_for_users

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def get_client_ids_for_users(cls, user_list, os_types=None):
     if os_types is None:
         os_types = ClientType.names.keys()
     output = defaultdict(list)
     clients = MobileClient.query(MobileClient.user_id.IN(user_list), MobileClient.client_type.IN(os_types), MobileClient.verified == True).fetch()
     for client in clients:
         if client.client_type == ClientType.WEBHOOK:
             output[client.client_type].append((client.messaging_id, client.secret))
         else:
             output[client.client_type].append(client.messaging_id)
     return output
開發者ID:BowlesCR,項目名稱:the-blue-alliance,代碼行數:13,代碼來源:push_helper.py

示例9: unregister_client

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def unregister_client(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         return BaseResponse(code=401, message="Unauthorized to unregister")
     userID = PushHelper.user_email_to_id(current_user.email())
     gcmId = request.mobile_id
     query = MobileClient.query(MobileClient.messaging_id == gcmId, MobileClient.user_id == userID).fetch(keys_only=True)
     if len(query) == 0:
         # Record doesn't exist, so we can't remove it
         return BaseResponse(code=404, message="User doesn't exist. Can't remove it")
     else:
         ndb.delete_multi(query)
         return BaseResponse(code=200, message="User deleted")
開發者ID:dewdn2,項目名稱:the-blue-alliance,代碼行數:15,代碼來源:mobile_main.py

示例10: unregister_client

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def unregister_client(self, request):
     user_id = get_current_user_id(self.headers)
     if user_id is None:
         return BaseResponse(code=401, message="Unauthorized to unregister")
     gcm_id = request.mobile_id
     query = MobileClient.query(MobileClient.messaging_id == gcm_id, ancestor=ndb.Key(Account, user_id))\
         .fetch(keys_only=True)
     if len(query) == 0:
         # Record doesn't exist, so we can't remove it
         return BaseResponse(code=404, message="User doesn't exist. Can't remove it")
     else:
         ndb.delete_multi(query)
         return BaseResponse(code=200, message="User deleted")
開發者ID:ZachOrr,項目名稱:the-blue-alliance,代碼行數:15,代碼來源:clientapi_service.py

示例11: register_client

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def register_client(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         return BaseResponse(code=401, message="Unauthorized to register")
     userId = PushHelper.user_email_to_id(current_user.email())
     gcmId = request.mobile_id
     os = ClientType.enums[request.operating_system]
     if MobileClient.query( MobileClient.messaging_id==gcmId ).count() == 0:
         # Record doesn't exist yet, so add it
         MobileClient(   messaging_id = gcmId,
                         user_id = userId,
                         client_type = os ).put()
         return BaseResponse(code=200, message="Registration successful")
     else:
         # Record already exists, don't bother updating it again
         return BaseResponse(code=304, message="Client already exists")
開發者ID:dewdn2,項目名稱:the-blue-alliance,代碼行數:18,代碼來源:mobile_main.py

示例12: get

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def get(self):
        webhooks = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
        failures = []

        for client in webhooks:
            response = TBANSHelper.ping_webhook(client)
            if not response.code == 200:
                failures.append(client.key)

        count = len(failures)
        if failures:
            ndb.delete_multi(failures)
        logging.info("Deleted {} broken webhooks".format(count))

        template_values = {'count': count}
        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/webhooks_clear_do.html')
        self.response.out.write(template.render(path, template_values))
開發者ID:ZachOrr,項目名稱:the-blue-alliance,代碼行數:19,代碼來源:admin_cron_controller.py

示例13: get

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def get(self):
     clients = MobileClient.query().fetch()
     clients = sorted(clients, key=lambda x: (x.messaging_id, x.updated))
     last = None
     to_remove = []
     last = None
     for client in clients:
         if last is not None and client.messaging_id == last.messaging_id:
             logging.info("Removing")
             to_remove.append(client.key)
         last = client
     count = len(to_remove)
     if to_remove:
         ndb.delete_multi(to_remove)
     logging.info("Removed {} duplicate mobile clients".format(count))
     template_values = {'count': count}
     path = os.path.join(os.path.dirname(__file__), '../../templates/admin/mobile_clear_do.html')
     self.response.out.write(template.render(path, template_values))
開發者ID:MC42,項目名稱:the-blue-alliance,代碼行數:20,代碼來源:admin_cron_controller.py

示例14: post

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
    def post(self):
        self._require_registration()
        self._require_request_user_is_bundle_user()

        # Name and URL must be non-None
        url = self.request.get('url', None)
        name = self.request.get('name', None)
        if not url or not name:
            return self.redirect('/webhooks/add?error=1')

        # Secret may be none - but we'll generate a secret for the user
        secret = self.request.get('secret', None)
        if not secret:
            import uuid
            secret = uuid.uuid4().hex

        current_user_account_id = self.user_bundle.account.key.id()
        query = MobileClient.query(MobileClient.messaging_id == url, ancestor=ndb.Key(Account, current_user_account_id))
        if query.count() == 0:
            # Webhook doesn't exist, add it
            from helpers.tbans_helper import TBANSHelper
            response = TBANSHelper.verify_webhook(url, secret)

            client = MobileClient(
                parent=self.user_bundle.account.key,
                user_id=current_user_account_id,
                messaging_id=url,
                display_name=name,
                secret=secret,
                client_type=ClientType.WEBHOOK,
                verified=False,
                verification_code=response.verification_key)
            client.put()
        else:
            # Webhook already exists. Update the secret
            current = query.fetch()[0]
            current.secret = secret
            current.put()

        self.redirect('/account')
開發者ID:ZachOrr,項目名稱:the-blue-alliance,代碼行數:42,代碼來源:webhook_controller.py

示例15: mobile_clients

# 需要導入模塊: from models.mobile_client import MobileClient [as 別名]
# 或者: from models.mobile_client.MobileClient import query [as 別名]
 def mobile_clients(self):
     user_id = self.user.user_id()
     return MobileClient.query(ancestor=ndb.Key(Account, user_id)).fetch()
開發者ID:CarlColglazier,項目名稱:the-blue-alliance,代碼行數:5,代碼來源:user_bundle.py


注:本文中的models.mobile_client.MobileClient.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。