Ejemplo n.º 1
0
def autocomplete(request):
	response = {}
	term = ''
	if request.method == 'GET':
		term = unaccent(request.GET['term']).lower()
	possible_brands = DallizBrand.objects.raw( "SELECT * FROM dalliz_brand WHERE LOWER(UNACCENT(name)) LIKE %s", ('%'+term+'%',))
	response = [{'id':b.id,'label':b.name,'value':b.name, 'name':b.name} for b in possible_brands]
	return HttpResponse(json.dumps(response))
Ejemplo n.º 2
0
	def get_documents(self, datetime = None):
		"""
			This method returns documents filtered by updated time lesser thant the 
			provided datetime.
		"""
		reg = re.compile(r'\b[a-zA-Z]{3,}\b')
		documents = self.Model.objects.all()
		if datetime is not None:
			documents = documents.filter(created__gte=datetime)
		return [{'id': d.id, 'tokens': reg.findall(unaccent(d.name.lower()))} for d in documents]
Ejemplo n.º 3
0
	def build_all_index(self):
		"""
			Building the index from scratch.

		"""
		reg = re.compile(r'\b[a-zA-Z]{3,}\b')
		documents = self.Model.objects.all()
		documents = [{'id': d.id, 'tokens': reg.findall(unaccent(d.name.lower()))} for d in documents]
		self.service.train(documents, method=IndexController.METHOD)
		self.service.index(documents)
Ejemplo n.º 4
0
def superautocomplete(request):
	"""
		Get all tags that are like term

		For instance : term = 'fr' -> resultats : 'fraise', 'africe' etc..
	"""
	term = ''
	if request.method == 'GET':
		term = unaccent(request.GET['term']).lower()
	# possible_tags = Tag.objects.raw( "SELECT DISTINCT * FROM tags_tag WHERE LOWER(UNACCENT(name)) LIKE %s", ('%'+term+'%',))
	possible_tags = Tag.objects.filter(name__icontains = term, is_super_tag = True).distinct('name')
	response = [{'id':t.id,'label':t.name,'value':t.name, 'is_super_tag': t.is_super_tag} for t in possible_tags]	
	return HttpResponse(json.dumps(response))
Ejemplo n.º 5
0
def autocomplete_category(request):
	"""
		Get all categories that are like term

		For instance : term = 'fr' -> resultats : 'fraise', 'africe' etc..
	"""
	term = ''
	if request.method == 'GET':
		term = unaccent(request.GET['term']).lower()
	possible_categories = DallizCategory.objects.raw( "SELECT * FROM dalliz_category WHERE LOWER(UNACCENT(name)) LIKE %s", ('%'+term+'%',))
	# Filtering possibile categories, removing categories with childs
	categories = []
	for p in possible_categories:
		if len(DallizCategory.objects.filter(parent_category = p))==0:
			categories.append(p)
	response = [{'id':t.id,'label':(lambda i: i.parent_category.name+' / '+i.name if i.parent_category is not None else i.name)(t)+' - '+str(t.id),'value':(lambda i: i.parent_category.name+' / '+i.name if i.parent_category is not None else i.name)(t)+' - '+str(t.id)} for t in categories]	
	return HttpResponse(json.dumps(response))
Ejemplo n.º 6
0
def change_name(request, id):
    response = {'status': 404}

    if request.method == 'POST':
        new_name = request.POST['name']
        category = Category.objects.filter(id=id)
        if len(category) == 1:
            category = category[0]
            category.name = new_name
            # Now working on url
            url = unaccent(new_name.lower())
            reg = r'[^a-z0-9]'
            url = '-'.join([x for x in re.split(reg, url) if x != ''])
            category.url = url
            category.save()
            response = {'status': 200, 'url': url}

    return HttpResponse(json.dumps(response))
Ejemplo n.º 7
0
def change_name(request, id):
	response = {'status': 404}

	if request.method == 'POST':
		new_name = request.POST['name']
		category = Category.objects.filter(id = id)
		if len(category) == 1:
			category = category[0]
			category.name = new_name
			# Now working on url
			url = unaccent(new_name.lower())
			reg = r'[^a-z0-9]'
			url = '-'.join([x for x in re.split(reg, url) if x != ''])
			category.url = url
			category.save()
			response = {'status': 200, 'url': url}

	return HttpResponse(json.dumps(response))
Ejemplo n.º 8
0
def autocomplete(request):
    """
		Get all tags that are like term

		For instance : term = 'fr' -> resultats : 'fraise', 'africe' etc..
	"""
    term = ''
    if request.method == 'GET':
        term = unaccent(request.GET['term']).lower()
    # possible_tags = Tag.objects.raw( "SELECT DISTINCT * FROM tags_tag WHERE LOWER(UNACCENT(name)) LIKE %s", ('%'+term+'%',))
    possible_tags = Tag.objects.filter(name__icontains=term).distinct('name')
    response = [{
        'id': t.id,
        'label': t.name,
        'value': t.name,
        'is_super_tag': t.is_super_tag
    } for t in possible_tags]
    return HttpResponse(json.dumps(response))