Example #1
0
    def ajouter_command(self, message=None):
        #who = db.IM("xmpp", message.sender)
        url = message.arg
        logging.debug('Wants to add present from URL ' + url)
        data = {"isAdded": False}
        email = message.sender.split("/")[0]
        logging.debug('XMPP handler started via /ajouter command. User ' +
                      email + ". URL: " + url)
        try:
            info = utils.get_image_urls_and_title_from_page(url)
            if info['title']:
                present = Present(title=info['title'], user=users.User(email))
                present.approximatePrice = int(info['price'])
                present.url = url
                # We're going to have to choose the first image anyway ...
                present.image = info['img'][0]
                present.imageFixed = False
                present.put()

                data["isAdded"] = True
                data["present"] = present
            else:
                data["error"] = "Could not parse website"
        except StandardError, e:
            data["error"] = e
Example #2
0
def is_username_in_datamodel(username):
	query = Present.all().filter("user = ", username)
	logging.info(query.fetch(1))
	presents = query.fetch(1)
	if len(presents) == 1:
		return True
	else:
		return False
Example #3
0
def is_username_in_datamodel(username):
    query = Present.all().filter("user = ", username)
    logging.info(query.fetch(1))
    presents = query.fetch(1)
    if len(presents) == 1:
        return True
    else:
        return False
Example #4
0
	def ajouter_command(self, message=None):
		#who = db.IM("xmpp", message.sender)
		url = message.arg
		logging.debug('Wants to add present from URL ' + url)
		data = {
			"isAdded": False
		}
		email = message.sender.split("/")[0]
		logging.debug('XMPP handler started via /ajouter command. User ' + email + ". URL: " + url)
		try:
			info = utils.get_image_urls_and_title_from_page(url)
			if info['title']:
				present = Present(title=info['title'], user=users.User(email))
				present.approximatePrice = int(info['price'])
				present.url = url
				# We're going to have to choose the first image anyway ...
				present.image = info['img'][0]
				present.imageFixed = False
				present.put()
				
				data["isAdded"] = True
				data["present"] = present
			else:
				data["error"] = "Could not parse website"
		except StandardError, e:
			data["error"] = e
Example #5
0
def get_presents_and_pages(username, order):
	query = Present.all().order(order).filter("user = ", username)

	presents = prepare_present_list_for_template(query.fetch(1000))

	return {
		'presents': presents,
		'atLeastOnePresent': len(presents),
	}
Example #6
0
def get_presents_and_pages(username, order):
    query = Present.all().order(order).filter("user = ", username)

    presents = prepare_present_list_for_template(query.fetch(1000))

    return {
        'presents': presents,
        'atLeastOnePresent': len(presents),
    }
 def get(self):
     session = get_current_session()
     if session.is_active():
         present = Present.get(self.request.get('key'))
         if present.user == session["user_info"]["username"]:
             present.delete()
             #increment counter
             counter = PresentCounter.all().fetch(1)[0]
             counter.count -= 1
             counter.put()
     self.redirect('/?msg=deleteOk')
	def get(self):
		session = get_current_session()
		if session.is_active():
			present = Present.get(self.request.get('key'))
			if present.user == session["user_info"]["username"]:
				present.delete();
				#increment counter
				counter = PresentCounter.all().fetch(1)[0]
				counter.count -= 1
				counter.put()
		self.redirect('/?msg=deleteOk')
    def post(self):
        session = get_current_session()
        if session.is_active() and self.request.get('title'):
            present = Present(title=self.request.get('title'),
                              user=session["user_info"]["username"])
            if self.request.get('approximatePrice'):
                present.approximatePrice = int(
                    self.request.get('approximatePrice'))
            if self.request.get('url'):
                present.url = self.request.get('url')
            if self.request.get('image'):
                present.image = self.request.get('image')
            present.imageFixed = False
            present.put()

            #increment counter
            try:
                counter = PresentCounter.all().fetch(1)[0]
            except:
                counter = PresentCounter(count=0)
            counter.count += 1
            counter.put()

        self.redirect('/?msg=addOk')
	def post(self):
		session = get_current_session()
		if session.is_active() and self.request.get('title'):
			present = Present(title=self.request.get('title'), user=session["user_info"]["username"])
			if self.request.get('approximatePrice'):
				present.approximatePrice = int(self.request.get('approximatePrice'))
			if self.request.get('url'):
				present.url = self.request.get('url')
			if self.request.get('image'):
				present.image = self.request.get('image')
			present.imageFixed = False
			present.put()
			
			#increment counter
			try:
				counter = PresentCounter.all().fetch(1)[0]
			except:
				counter = PresentCounter(count=0)
			counter.count += 1
			counter.put()
			
		self.redirect('/?msg=addOk')
Example #11
0
	def get(self):
		# Show some presents on the home page
		data = utils.prepare_base_template_values(self)
		data['presents'] = utils.prepare_present_list_for_template(Present.all().order("-dateAdded").fetch(12))

		self.writeTemplateToResponse('pages/Home.html', data)