def get(self, *args, **kwargs): #@UnusedVariable ''' @keyword actor: @return: array of deal objects ''' user = kwargs.get('actor') try: deals = api_utils.fetch_all_users_deals(user) # package deals private = True packaged_deals = api_utils.package_deal_multi(deals, private) # return response = {'deals': packaged_deals} self.send_response(response, user) except Exception, e: levr.log_error(e) self.send_error()
def get(self,*args,**kwargs): #@UnusedVariable ''' @keyword actor: @return: array of deal objects ''' user = kwargs.get('actor') try: deals = api_utils.fetch_all_users_deals(user) # package deals private = True packaged_deals = api_utils.package_deal_multi(deals, private) # return response = { 'deals' : packaged_deals } self.send_response(response, user) except Exception,e: levr.log_error(e) self.send_error()
def post(self,*args,**kwargs): #@UnusedVariable ''' @keyword actor: required @keyword deal: required @keyword description: optional @keyword dealText: optional @var new_img_key: optional - the blob key of the uploaded image @return: the new deal object @rtype: dict ''' user = kwargs.get('actor') deal = kwargs.get('deal') description = kwargs.get('description',None) deal_text = kwargs.get('dealText',None) try: # assure that the user is the owner of the deal assert deal.parent_key() == user.key(), 'User does not own that deal' #=================================================================== # Check for image upload #=================================================================== if self.get_uploads(): new_img_key = self.get_uploads()[0].key() # grab old key so we can delete it old_img_key = deal.img # replace with new key deal.img = new_img_key # delete that old key old_img_key.delete() try: # Synchronously rotate the image api_utils.rotate_image(new_img_key) except: levr.log_error('An image could not be rotated. \ It was sent to the task que: '+str(new_img_key)) # Send the image to the img rotation task que task_params = { 'blob_key' : str(new_img_key) } logging.info('Sending this to the img rotation task: '+str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL,payload=json.dumps(task_params)) else: assert description or deal_text, 'Thanks for sending me something to update.' #=================================================================== # Update new deal informations #=================================================================== if description: deal.description = description if deal_text: deal.deal_text = deal_text # TODO: add new tags to the deal for the new information that was added deal.put() private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = { 'deals' : packaged_deals } api_utils.send_response(self,response, user) except AssertionError,e: api_utils.send_error(self,e.message)
def post(self,*args,**kwargs): #@UnusedVariable ''' @keyword actor: required @keyword business: required @keyword description: required @keyword deal_text: required @keyword development: required @requires: an image is uploaded - need the blob_key @return: the newly created deal object @rtype: dict ''' user = kwargs.get('actor') business = kwargs.get('business') description = kwargs.get('description') deal_text = kwargs.get('dealText') development = kwargs.get('development') img_key = '' try: #=================================================================== # Assure that an image was uploaded #=================================================================== if self.get_uploads(): upload = self.get_uploads()[0] blob_key= upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') #=================================================================== # Assemble the deal parameters! And create the deal!! #=================================================================== params = { 'user' : user, 'uid' : user.key(), 'business' : business, 'deal_description' : description, 'deal_line1' : deal_text, 'development' : development, 'img_key' : img_key } # TODO: add pin_color = 'green' to the deal # TODO: add origin = 'merchant' deal_entity = levr.dealCreate(params, 'phone_merchant', upload_flag) # if an image was uploaded, rotate it. if upload_flag == True: try: # Synchronously rotate the image api_utils.rotate_image(blob_key,deal_entity) except: levr.log_error('An image could not be rotated. It was sent to the task que: '+str(blob_key)) # Send the image to the img rotation task que task_params = { 'blob_key' : str(blob_key) } logging.info('Sending this to the img rotation task: '+str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL,payload=json.dumps(task_params)) #=================================================================== # Aw hell.. why not give them some karma too. #=================================================================== user.karma += 5 # no need to level_check on them though... user.put() #=================================================================== # Create some nifty notifications #=================================================================== try: levr.create_notification('followedUpload',user.followers,user.key(),deal_entity) except: levr.log_error() #=================================================================== # Respond with all of the users deals #=================================================================== private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = { 'deals' : packaged_deals } api_utils.send_response(self,response, user) except Exception,e: levr.log_error(e) api_utils.send_error(self,'Server Error')
def post(self, *args, **kwargs): #@UnusedVariable ''' @keyword actor: required @keyword deal: required @keyword description: optional @keyword dealText: optional @var new_img_key: optional - the blob key of the uploaded image @return: the new deal object @rtype: dict ''' user = kwargs.get('actor') deal = kwargs.get('deal') description = kwargs.get('description', None) deal_text = kwargs.get('dealText', None) try: # assure that the user is the owner of the deal assert deal.parent_key() == user.key( ), 'User does not own that deal' #=================================================================== # Check for image upload #=================================================================== if self.get_uploads(): new_img_key = self.get_uploads()[0].key() # grab old key so we can delete it old_img_key = deal.img # replace with new key deal.img = new_img_key # delete that old key old_img_key.delete() try: # Synchronously rotate the image api_utils.rotate_image(new_img_key) except: levr.log_error('An image could not be rotated. \ It was sent to the task que: ' + str(new_img_key)) # Send the image to the img rotation task que task_params = {'blob_key': str(new_img_key)} logging.info('Sending this to the img rotation task: ' + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) else: assert description or deal_text, 'Thanks for sending me something to update.' #=================================================================== # Update new deal informations #=================================================================== if description: deal.description = description if deal_text: deal.deal_text = deal_text # TODO: add new tags to the deal for the new information that was added deal.put() private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = {'deals': packaged_deals} api_utils.send_response(self, response, user) except AssertionError, e: api_utils.send_error(self, e.message)
def post(self, *args, **kwargs): #@UnusedVariable ''' @keyword actor: required @keyword business: required @keyword description: required @keyword deal_text: required @keyword development: required @requires: an image is uploaded - need the blob_key @return: the newly created deal object @rtype: dict ''' user = kwargs.get('actor') business = kwargs.get('business') description = kwargs.get('description') deal_text = kwargs.get('dealText') development = kwargs.get('development') img_key = '' try: #=================================================================== # Assure that an image was uploaded #=================================================================== if self.get_uploads(): upload = self.get_uploads()[0] blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') #=================================================================== # Assemble the deal parameters! And create the deal!! #=================================================================== params = { 'user': user, 'uid': user.key(), 'business': business, 'deal_description': description, 'deal_line1': deal_text, 'development': development, 'img_key': img_key } # TODO: add pin_color = 'green' to the deal # TODO: add origin = 'merchant' deal_entity = levr.dealCreate(params, 'phone_merchant', upload_flag) # if an image was uploaded, rotate it. if upload_flag == True: try: # Synchronously rotate the image api_utils.rotate_image(blob_key, deal_entity) except: levr.log_error( 'An image could not be rotated. It was sent to the task que: ' + str(blob_key)) # Send the image to the img rotation task que task_params = {'blob_key': str(blob_key)} logging.info('Sending this to the img rotation task: ' + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) #=================================================================== # Aw hell.. why not give them some karma too. #=================================================================== user.karma += 5 # no need to level_check on them though... user.put() #=================================================================== # Create some nifty notifications #=================================================================== try: levr.create_notification('followedUpload', user.followers, user.key(), deal_entity) except: levr.log_error() #=================================================================== # Respond with all of the users deals #=================================================================== private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = {'deals': packaged_deals} api_utils.send_response(self, response, user) except Exception, e: levr.log_error(e) api_utils.send_error(self, 'Server Error')