Skip to content

Instantly share code, notes, and snippets.

View ikks's full-sized avatar

Igor Támara ikks

View GitHub Profile
@ikks
ikks / search_indexes.py
Created February 10, 2012 23:06
Haystack search indexes sample
from haystack.indexes import RealTimeSearchIndex
from haystack.indexes import CharField
from haystack.indexes import RealTimeSearchIndex
from haystack.indexes import CharField
from haystack.indexes import MultiValueField
from haystack import site
from apps.informationgathering.models import RR
@ikks
ikks / gist:1793995
Created February 10, 2012 23:31
xapian backend in virtualenv
export MYENV=~/.virtualenvs/tr
export LOCALPYTHON=/usr/lib/python2.7
ln -s $LOCALPYTHON/dist-packages/xapian/__init__.py $MYENV/lib/python2.7/site-packages/xapian.py
ln -s $LOCALPYTHON/dist-packages/xapian/_xapian.so $MYENV/lib/python2.7/site-packages/
if [ ! -f $MYENV/lib/python2.7/site-packages/haystack/backends/xapian_backend.py ]
then
ln -s $MYENV/lib/python2.7/site-packages/xapian_backend.py $MYENV/lib/python2.7/site-packages/haystack/backends/
fi
@ikks
ikks / restitutionrequest_text.txt
Created February 10, 2012 23:52
sample template for haystack search
{{ object.assignednumber }}
{{ object.holderrightenterprise.nit }}
{{ object.territory }}
{{ object.people }}
@ikks
ikks / urls.py
Created February 10, 2012 23:56
Pattern for haystack with a custom form and login_required
from haystack.views import SearchView
from django.contrib.auth.decorators import login_required
from apps.informationgathering.forms import RtSearchForm
.
.
.
urlpatterns += patterns('haystack.views',
url(r'^$', login_required(SearchView(
@ikks
ikks / urls.py
Created February 10, 2012 23:58
from haystack.views import SearchView
.
.
.
urlpatterns += patterns('haystack.views',
url(r'^$', SearchView, name='haystack_search'),
)
@ikks
ikks / forms.py
Created February 11, 2012 00:03
Sample Search Form to avoid accents using translit
from haystack.forms import SearchForm
.
.
class RtSearchForm(SearchForm):
def search(self):
if hasattr(self,'cleaned_data') and self.cleaned_data['q']:
self.cleaned_data['q']=self.cleaned_data['q'].encode('translit/one/ascii', 'replace')
sqs = super(RtSearchForm, self).search()
@ikks
ikks / search.html
Created February 11, 2012 00:09
Sample for a search template using gist
{% extends "layout/base.html" %}
<div class="entry">
{% block body %}
<div class="register_init">
<div class="add_new">
<a href="/recolecta/nuevo">Nueva Solicitud de Inscripción en el Registro</a>
</div>
<form method="get" action=".">
{{ form.as_p }}
<input type="submit" value="Buscar">
@ikks
ikks / goo.gl.py
Created May 31, 2012 19:43
Using goo.gl from python 2.X Where X is 6 or more
#Given to the public domain
#No warranties
import urllib2
import simplejson
def shorturl(urltoshorten):
"""Compress the URL using goo.gl take a look at https://developers.google.com/url-shortener/v1/getting_started
>>> shorturl('http://igor.tamarapatino.org')
'http://goo.gl/FxHOn'
@ikks
ikks / gist:3344545
Created August 13, 2012 22:33
Creating extension hstore for Postgresql 9.X
CREATE EXTENSION hstore;
@ikks
ikks / gist:3344575
Created August 13, 2012 22:38
Tabla con hstore
CREATE TABLE producto (
id serial PRIMARY KEY,
nombre varchar,
atributos hstore
);