예제 #1
0
    def add_followers(self, to_be_connected):
        '''
		Takes a list of user entities, checks if they are already following the user
		If not already following, they follow and are notified
		If they are already following, nothing happens
		'''
        #		#add actor to the list of followers
        #		for user in to_be_connected:
        #			if self.user.key() not in user.followers:
        #				user.followers.append(actor)
        logging.debug('\n\n ADD FOLLOWERS \n\n')

        logging.debug([user.key() for user in to_be_connected])
        to_be_notified = []
        #if the user has not been stored yet, it will not have a key
        try:
            actor_id = self.user.key()
        except:
            raise Exception('User does not exist in db yet. ')
            actor_id = db.Key()
        #for each user entity that has been identified as a potential new friend
        for u in to_be_connected:
            #they will be added as a follower if they are not already one and the user is not itself
            if actor_id not in u.followers and u.key() != actor_id:
                #add the actor to the list of the found users followers
                u.followers.append(actor_id)
                to_be_notified.append(u)

        if to_be_notified:
            logging.debug(to_be_notified)
            logging.debug(type(to_be_notified[0]))
            logging.debug([user.key() for user in to_be_notified])
            #place the list of user entities, and get a list of ids in return
            to_be_notified = db.put(to_be_notified)
            #			to_be_notified = [friend.key() for friend in to_be_notified]

            #only notify/add follower if the user is not already following
            logging.debug(to_be_notified)

            #replace all of the notified users

            #add the actors friends to their list of followers
            self.user.followers.extend(to_be_notified)

            #create a notification if there are users to be notified
            if to_be_notified:
                levr.create_notification('newFollower', to_be_notified,
                                         self.user.key())
        else:
            pass
        logging.debug("To be notified: " + str(to_be_notified))
        logging.debug(type(to_be_notified))
        return to_be_notified
예제 #2
0
	def add_followers(self, to_be_connected):
		'''
		Takes a list of user entities, checks if they are already following the user
		If not already following, they follow and are notified
		If they are already following, nothing happens
		'''
#		#add actor to the list of followers
#		for user in to_be_connected:
#			if self.user.key() not in user.followers:
#				user.followers.append(actor)
		logging.debug('\n\n ADD FOLLOWERS \n\n')
		
		logging.debug([user.key() for user in to_be_connected])
		to_be_notified = []
		#if the user has not been stored yet, it will not have a key
		try:	actor_id = self.user.key()
		except:
			raise Exception('User does not exist in db yet. ')
			actor_id = db.Key()
		#for each user entity that has been identified as a potential new friend
		for u in to_be_connected:
			#they will be added as a follower if they are not already one and the user is not itself
			if actor_id not in u.followers and u.key() != actor_id:
				#add the actor to the list of the found users followers
				u.followers.append(actor_id)
				to_be_notified.append(u)
		
		if to_be_notified:
			logging.debug(to_be_notified)
			logging.debug(type(to_be_notified[0]))
			logging.debug([user.key() for user in to_be_notified])
			#place the list of user entities, and get a list of ids in return
			to_be_notified = db.put(to_be_notified)
#			to_be_notified = [friend.key() for friend in to_be_notified]
			
			#only notify/add follower if the user is not already following
			logging.debug(to_be_notified)
			
			#replace all of the notified users
			
			
			#add the actors friends to their list of followers
			self.user.followers.extend(to_be_notified)
			
			
			#create a notification if there are users to be notified
			if to_be_notified: levr.create_notification('newFollower', to_be_notified, self.user.key())
		else:
			pass
		logging.debug("To be notified: "+str(to_be_notified))
		logging.debug(type(to_be_notified))
		return to_be_notified
예제 #3
0
	def get(self):
		
		logging.info('WTFFFF')
		logging.debug('HOLY SHIT NEW NOTIFICATIONS OMG OMG OMG')
		
		#go get the ninja
		user = levr.Customer.gql('WHERE email=:1','q').get()
		#go get the user
		actor = levr.Customer.gql('WHERE email=:1','*****@*****.**').get()
		#go get the deal
		deal = levr.Deal.all().ancestor(user.key()).get()
		
		if not deal:
			deal = levr.Deal.all().get()
		
		assert deal, 'Cannot find any deals. Try uploading one. If that doesnt work, abandon all hope.' 
		
		#new follower notification
		levr.create_notification('newFollower',user.key(),actor)
		
		#followed upload notification
		levr.create_notification('followedUpload',user.key(),actor,deal.key())
		
		#favorite notification
		levr.create_notification('favorite',user.key(),actor,deal.key())
		
		#levelup notification
		user.new_notifications += 1
		levr.create_notification('levelup',user.key(),actor,new_level='inf')
		user.put()
		self.response.out.write('HOLY SHIT NEW NOTIFICATIONS OMG OMG OMG')
예제 #4
0
    def get(self, *args, **kwargs):
        '''
		A user (specified in ?uid=USER_ID) follows the user specified in (/api/USER_ID/follow)
		
		inputs: uid(required)
		
		Response:{
			None
			}
		'''
        try:
            logging.info('\n\n\n\t\t\t USER ADD FOLLOWER\n\n\n')
            user = kwargs.get('user')
            #			uid 	= user.key()
            actor = kwargs.get('actor')
            actorID = actor.key()
            private = kwargs.get('private')

            #add actor to the list of followers
            if actorID not in user.followers:
                user.followers.append(actorID)

            #PERFORM ACTIONS
            if not levr.create_notification('newFollower', user.key(),
                                            actorID):
                api_utils.send_error(self, 'Server Error')
                return

            #get notifications
            db.put([user, actor])

            #respond
            api_utils.send_response(self,
                                    {'dt': str(actor.date_last_notified)},
                                    actor)

        except:
            levr.log_error()
            api_utils.send_error(self, 'Server Error')
예제 #5
0
파일: api_user.py 프로젝트: holmesal/levr-2
	def get(self,*args,**kwargs):
		'''
		A user (specified in ?uid=USER_ID) follows the user specified in (/api/USER_ID/follow)
		
		inputs: uid(required)
		
		Response:{
			None
			}
		'''
		try:
			logging.info('\n\n\n\t\t\t USER ADD FOLLOWER\n\n\n')
			user 	= kwargs.get('user')
#			uid 	= user.key()
			actor	= kwargs.get('actor')
			actorID = actor.key()
			private = kwargs.get('private')
			
			#add actor to the list of followers
			if actorID not in user.followers:
				user.followers.append(actorID)
			
			#PERFORM ACTIONS
			if not levr.create_notification('newFollower',user.key(),actorID):
				api_utils.send_error(self,'Server Error')
				return
			
			#get notifications
			db.put([user,actor])
			
			#respond
			api_utils.send_response(self,{'dt':str(actor.date_last_notified)},actor)
			
		except:
			levr.log_error()
			api_utils.send_error(self,'Server Error')
예제 #6
0
    def get(self, dealID, *args, **kwargs):
        try:
            logging.debug('UPVOTE\n\n\n')
            logging.debug(kwargs)

            user = kwargs.get('actor')
            uid = user.key()
            deal = kwargs.get('deal')
            dealID = deal.key()

            #===================================================================
            # Note, if this code changes, you should also change the code in /cronjobs/undeadActivity because it was copied and pasted...
            #===================================================================

            #favorite
            logging.debug(
                levr.log_model_props(user,
                                     ['upvotes', 'downvotes', 'favorites']))
            logging.debug(levr.log_model_props(deal, ['upvotes', 'downvotes']))

            if dealID in user.upvotes:
                logging.debug('flag deal in upvotes')
                #user is removing the upvote
                #remove the offending deal from the user upvotes
                user.upvotes.remove(dealID)

                #decrement the deal upvotes
                deal.upvotes -= 1
                #do not change the karma of the user who uploaded it
                #do not remove from favorites
                #do not remove notification

                db.put([user, deal])

            elif dealID in user.downvotes:
                logging.debug('flag deal is in downvotes')
                #remove deal from downvotes
                user.downvotes.remove(dealID)
                #decrement the deals downvotes
                deal.downvotes -= 1

                #add deal to upvotes
                user.upvotes.append(dealID)
                #increment the number of upvotes
                deal.upvotes += 1
                #add deal to favorites
                if dealID not in user.favorites:
                    user.favorites.append(dealID)

                #do not change the karma of the user who uploaded
                #do not add notification for the ninja
                db.put([user, deal])
                pass
            else:
                logging.debug('flag deal not in upvotes or downvotes')

                # If the deal is in the users favorites, then they upvoted the deal at one point and then
                # removed that upvote either via another upvote or a downvote, and they are trying to upvote again
                # At this point, the deal should get its upvote back, but the ninja gets no karma because they do not
                # lose a karma point when the deal is downloaded
                if dealID not in user.favorites:
                    #get owner of the deal
                    ninja = levr.Customer.get(deal.key().parent())
                    #check owner. if the owner is a dummy owner left over from an account transfer, grab the real owner.
                    if ninja.email == '*****@*****.**':
                        logging.debug(
                            '\n\n\n \t\t\t DUMMY NINJA! REDIRECTING REFERENCE TO THE REAL ONE!!! \n\n\n'
                        )
                        ninja = levr.Customer.get(ninja.pw)

                    #compare owner to user doing the voting
                    if ninja.key() == user.key():
                        #ninja is upvoting his own deal
                        #increase that users karma! reward for uploading a deal!
                        user.karma += 1
                        #level check!
                        levr.level_check(user)
                    else:
                        #increase the ninjas karma
                        ninja.karma += 1
                        #level check!
                        levr.level_check(ninja)
                        #replace ninja. we dont want him anymore
                        ninja.put()

                #add to upvote list
                user.upvotes.append(dealID)

                #				#increase the deal upvotes
                deal.upvotes += 1

                #add to users favorites list if not there already
                if dealID not in user.favorites:
                    user.favorites.append(dealID)
                    #create favorite notification for the ninja that uploaded
                    levr.create_notification('favorite', ninja.key(), uid,
                                             dealID)

                db.put([user, deal])
                #put actor and ninja and deal back

            assert deal, 'Deal was not found'
            response = {'deal': api_utils.package_deal(deal)}
            api_utils.send_response(self, response, user)
        except AssertionError, e:
            levr.log_error(e)
            api_utils.send_error(self, e.message)
예제 #7
0
	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')
예제 #8
0
    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')
예제 #9
0
    def post(self, *args, **kwargs):
        try:
            logging.info("uploadDeal\n\n\n")
            logging.info(kwargs)
            user = kwargs.get("actor")
            uid = user.key()
            # make sure than an image is uploaded
            logging.debug(self.get_uploads())
            if self.get_uploads():  # will this work?
                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")

            params = {
                "uid": uid,
                "business_name": kwargs.get("businessName"),
                "geo_point": kwargs.get("geoPoint"),
                "vicinity": kwargs.get("vicinity"),
                "types": kwargs.get("types"),
                "deal_description": kwargs.get("description"),
                "deal_line1": kwargs.get("dealText"),
                "distance": kwargs.get("distance"),  # is -1 if unknown = double
                "shareURL": kwargs.get("shareURL"),
                "development": kwargs.get("development"),
                "img_key": img_key,
            }

            # create the deal using the origin specified
            deal_entity = levr.dealCreate(params, "phone_new_business", upload_flag)

            # fire off a task to rotate the image
            task_params = {"blob_key": str(deal_entity.img.key())}

            logging.info("Sending this to the task: " + str(task_params))

            taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params))

            # give the user some karma
            user.karma += 5
            # level check!
            user = api_utils.level_check(user)
            user.put()

            # go notify everyone that should be informed
            try:
                levr.create_notification("followedUpload", user.followers, user.key(), deal_entity)
            except:
                levr.log_error()

                # grab deal information for sending back to phone
            deal = api_utils.package_deal(deal_entity, True)

            response = {"deal": deal}

            # ===================================================================
            # Send notification to founders
            # ===================================================================
            try:
                # 		approve_link = 'http://www.levr.com/admin/deal/{}/approve'.format(enc.encrypt_key(deal_entity.key()))
                base_url = "http://www.levr.com/admin/deal/{}/expiration?daysToExpire=".format(
                    enc.encrypt_key(deal_entity.key())
                )
                today_only_link = base_url + "0"
                one_week_link = base_url + "7"
                one_month_link = base_url + "30"
                three_month_link = base_url + "90"
                six_month_link = base_url + "180"
                one_year_link = base_url + "360"
                never_link = base_url + "-1"
                reject_link = "http://www.levr.com/admin/deal/{}/reject".format(enc.encrypt_key(deal_entity.key()))
                message = mail.AdminEmailMessage()
                message.sender = "*****@*****.**"
                message.subject = "New Upload"

                message.html = '<img src="{}"><br>'.format(deal.get("smallImg"))
                message.html += "<h2>{}</h2>".format(deal_entity.deal_text)
                message.html += "<h3>{}</h3>".format(deal_entity.description)
                message.html += "<h4>Uploaded by: {}</h4>".format(user.display_name)
                message.html += "<h5>deal_status: {}</h5>".format(deal_entity.deal_status)
                message.html += "<br/><p>Set deal expiration.</p>"
                message.html += '<br><a href="{}">Reject</a><br><br>'.format(reject_link)
                message.html += '<br><a href="{}">Today Only</a><br><br>'.format(today_only_link)
                message.html += '<br><a href="{}">One Week</a><br><br>'.format(one_week_link)
                message.html += '<br><a href="{}">One Month</a><br><br>'.format(one_month_link)
                message.html += '<br><a href="{}">Three Month</a><br><br>'.format(three_month_link)
                message.html += '<br><a href="{}">Six Month</a><br><br>'.format(six_month_link)
                message.html += '<br><a href="{}">One Year</a><br><br>'.format(one_year_link)
                message.html += '<br><a href="{}">Forever!!!</a><br><br>'.format(never_link)
                message.html += levr.log_dict(deal, None, "<br>")
                # 		message.body += '\n\n\n\n\n\nApprove: {}'.format(approve_link)

                message.check_initialized()
                message.send()
            except:
                levr.log_error()

            api_utils.send_response(self, response)

        except KeyError, e:
            logging.info("Key Error")
            logging.info(str(e))
            levr.log_error()
            api_utils.send_error(self, str(e))
예제 #10
0
파일: api_deal.py 프로젝트: holmesal/levr-2
	def get(self,dealID,*args,**kwargs):
		try:
			logging.debug('UPVOTE\n\n\n')
			logging.debug(kwargs)
			
			
			user 	= kwargs.get('actor')
			uid 	= user.key()
			deal 	= kwargs.get('deal')
			dealID 	= deal.key()
			
			
			#===================================================================
			# Note, if this code changes, you should also change the code in /cronjobs/undeadActivity because it was copied and pasted...
			#===================================================================
			
			#favorite
			logging.debug(levr.log_model_props(user,['upvotes','downvotes','favorites']))
			logging.debug(levr.log_model_props(deal,['upvotes','downvotes']))
				
				
				
			if dealID in user.upvotes:
				logging.debug('flag deal in upvotes')
				#user is removing the upvote
				#remove the offending deal from the user upvotes
				user.upvotes.remove(dealID)
				
				#decrement the deal upvotes
				deal.upvotes -= 1
				#do not change the karma of the user who uploaded it
				#do not remove from favorites
				#do not remove notification
				
				db.put([user,deal])
				
			elif dealID in user.downvotes:
				logging.debug('flag deal is in downvotes')
				#remove deal from downvotes
				user.downvotes.remove(dealID)
				#decrement the deals downvotes
				deal.downvotes -= 1
				
				#add deal to upvotes
				user.upvotes.append(dealID)
				#increment the number of upvotes
				deal.upvotes += 1
				#add deal to favorites
				if dealID not in user.favorites:
					user.favorites.append(dealID)
				
				#do not change the karma of the user who uploaded
				#do not add notification for the ninja
				db.put([user,deal])
				pass
			else:
				logging.debug('flag deal not in upvotes or downvotes')
				
				# If the deal is in the users favorites, then they upvoted the deal at one point and then
				# removed that upvote either via another upvote or a downvote, and they are trying to upvote again
				# At this point, the deal should get its upvote back, but the ninja gets no karma because they do not
				# lose a karma point when the deal is downloaded
				if dealID not in user.favorites:
					#get owner of the deal
					ninja = levr.Customer.get(deal.key().parent())
					#check owner. if the owner is a dummy owner left over from an account transfer, grab the real owner.
					if ninja.email == '*****@*****.**':
						logging.debug('\n\n\n \t\t\t DUMMY NINJA! REDIRECTING REFERENCE TO THE REAL ONE!!! \n\n\n')
						ninja = levr.Customer.get(ninja.pw)
					
					#compare owner to user doing the voting
					if ninja.key() == user.key():
						#ninja is upvoting his own deal
						#increase that users karma! reward for uploading a deal!
						user.karma += 1
						#level check!
						levr.level_check(user)
					else:
						#increase the ninjas karma
						ninja.karma += 1
						#level check!
						levr.level_check(ninja)
						#replace ninja. we dont want him anymore
						ninja.put()
				
				
				#add to upvote list
				user.upvotes.append(dealID)
				
#				#increase the deal upvotes
				deal.upvotes += 1
				
				
				
				
				#add to users favorites list if not there already
				if dealID not in user.favorites:
					user.favorites.append(dealID)
					#create favorite notification for the ninja that uploaded
					levr.create_notification('favorite',ninja.key(),uid,dealID)
				
				
				db.put([user,deal])
				#put actor and ninja and deal back
			
			
			assert deal, 'Deal was not found'
			response = {
					'deal':api_utils.package_deal(deal)
					}
			api_utils.send_response(self,response,user)
		except AssertionError,e:
			levr.log_error(e)
			api_utils.send_error(self,e.message)
예제 #11
0
    def post(self, *args, **kwargs):
        try:
            logging.info('uploadDeal\n\n\n')
            logging.info(kwargs)
            user = kwargs.get('actor')
            uid = user.key()
            #make sure than an image is uploaded
            logging.debug(self.get_uploads())
            if self.get_uploads():  #will this work?
                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')

            params = {
                'uid': uid,
                'business_name': kwargs.get('businessName'),
                'geo_point': kwargs.get('geoPoint'),
                'vicinity': kwargs.get('vicinity'),
                'types': kwargs.get('types'),
                'deal_description': kwargs.get('description'),
                'deal_line1': kwargs.get('dealText'),
                'distance': kwargs.get('distance'),  #is -1 if unknown = double
                'shareURL': kwargs.get('shareURL'),
                'development': kwargs.get('development'),
                'img_key': img_key
            }

            #create the deal using the origin specified
            deal_entity = levr.dealCreate(params, 'phone_new_business',
                                          upload_flag)

            #fire off a task to rotate the image
            task_params = {'blob_key': str(deal_entity.img.key())}

            logging.info('Sending this to the task: ' + str(task_params))

            taskqueue.add(url=IMAGE_ROTATION_TASK_URL,
                          payload=json.dumps(task_params))

            #give the user some karma
            user.karma += 5
            #level check!
            user = api_utils.level_check(user)
            user.put()

            #go notify everyone that should be informed
            try:
                levr.create_notification('followedUpload', user.followers,
                                         user.key(), deal_entity)
            except:
                levr.log_error()

            #grab deal information for sending back to phone
            deal = api_utils.package_deal(deal_entity, True)

            response = {'deal': deal}

            #===================================================================
            # Send notification to founders
            #===================================================================
            try:
                #		approve_link = 'http://www.levr.com/admin/deal/{}/approve'.format(enc.encrypt_key(deal_entity.key()))
                base_url = 'http://www.levr.com/admin/deal/{}/expiration?daysToExpire='.format(
                    enc.encrypt_key(deal_entity.key()))
                today_only_link = base_url + '0'
                one_week_link = base_url + '7'
                one_month_link = base_url + '30'
                three_month_link = base_url + '90'
                six_month_link = base_url + '180'
                one_year_link = base_url + '360'
                never_link = base_url + '-1'
                reject_link = 'http://www.levr.com/admin/deal/{}/reject'.format(
                    enc.encrypt_key(deal_entity.key()))
                message = mail.AdminEmailMessage()
                message.sender = '*****@*****.**'
                message.subject = 'New Upload'

                message.html = '<img src="{}"><br>'.format(
                    deal.get('smallImg'))
                message.html += '<h2>{}</h2>'.format(deal_entity.deal_text)
                message.html += '<h3>{}</h3>'.format(deal_entity.description)
                message.html += '<h4>Uploaded by: {}</h4>'.format(
                    user.display_name)
                message.html += '<h5>deal_status: {}</h5>'.format(
                    deal_entity.deal_status)
                message.html += '<br/><p>Set deal expiration.</p>'
                message.html += '<br><a href="{}">Reject</a><br><br>'.format(
                    reject_link)
                message.html += '<br><a href="{}">Today Only</a><br><br>'.format(
                    today_only_link)
                message.html += '<br><a href="{}">One Week</a><br><br>'.format(
                    one_week_link)
                message.html += '<br><a href="{}">One Month</a><br><br>'.format(
                    one_month_link)
                message.html += '<br><a href="{}">Three Month</a><br><br>'.format(
                    three_month_link)
                message.html += '<br><a href="{}">Six Month</a><br><br>'.format(
                    six_month_link)
                message.html += '<br><a href="{}">One Year</a><br><br>'.format(
                    one_year_link)
                message.html += '<br><a href="{}">Forever!!!</a><br><br>'.format(
                    never_link)
                message.html += levr.log_dict(deal, None, '<br>')
                #		message.body += '\n\n\n\n\n\nApprove: {}'.format(approve_link)

                message.check_initialized()
                message.send()
            except:
                levr.log_error()

            api_utils.send_response(self, response)

        except KeyError, e:
            logging.info('Key Error')
            logging.info(str(e))
            levr.log_error()
            api_utils.send_error(self, str(e))