def post(self, city = None): #this request can only be executed by admin #like he press a button and all devices of presence of new data on server #check if admin user = users.get_current_user() rootPath = os.path.split(os.path.dirname(__file__))[0] if user and users.is_current_user_admin(): #current user is admin #retrieve google auth token PostMessage.AUTH_TOKEN = self.getGoogleAuthToken() if PostMessage.AUTH_TOKEN is None: #can't retrieve token try after sometime logging.error("authentication token retrieval failed") template_values = { 'errorMsg' : "can't retrieve auth token try after sometime" } path = os.path.join(rootPath, "html/error.html") else: #use the retrieved auth_token to notify all reg devices db update logging.info("notify devices of update") C2dmUsers_query = C2dmUser.all() if city is not None: logging.info("fetching devices with city %s", city) C2dmUsers_query.filter("city =", city) try: for c2dmUser in C2dmUsers_query: #push msg to each device self.notifyDevice(c2dmUser.regId, c2dmUser.deviceId) #all devices pushed msgs template_values = { 'successMsg' : "messages pushed" } path = os.path.join(rootPath, "html/new_gig.html") except C2DMQuotaExceedError as e: template_values = { 'errorMsg' : "c2dm quota exceeded "+e.errorCode } path = os.path.join(rootPath, "html/error.html") else: #current user is not admin logging.error("not sufficient privileges") template_values = { 'errorMsg' : "Not sufficient privileges." } path = os.path.join(rootPath, "html/error.html") self.response.out.write(template.render(path, template_values))
def removeC2DMUser(self, regId): c2dmUser = C2dmUser.all().filter('regId=', regId).fetch(1) if len(c2dmUser) > 0: c2dmUser.delete()