-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb1215b
commit acefa54
Showing
12 changed files
with
144 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from haystack.forms import HighlightedSearchForm | ||
|
||
|
||
class CazadorForm(HighlightedSearchForm): | ||
def search(self): | ||
sqs = super(CazadorForm, self).search() | ||
|
||
if not self.is_valid(): | ||
return self.no_query_found() | ||
|
||
if not self.cleaned_data.get('q'): | ||
return self.no_query_found() | ||
|
||
sqs = self.searchqueryset.auto_query(self.cleaned_data['q']) | ||
|
||
if self.load_all: | ||
sqs = sqs.load_all() | ||
|
||
return sqs |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Add deudores al Estado to index""" | ||
from tqdm import tqdm | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from cazador.models import Cazador | ||
|
||
|
||
DBS = ['deudores', 'candidato_2014', 'narcoindultos', 'redam'] | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('-i', | ||
action='store', | ||
dest='input_file', | ||
help='Enter filename with data to import.', | ||
) | ||
parser.add_argument('-db', | ||
action='store', | ||
dest='database', | ||
help='Enter database, options: {}'.format( | ||
', '.join(DBS))) | ||
|
||
def handle(self, *args, **options): | ||
if not options['input_file']: | ||
raise CommandError("Input Filename does not exist.") | ||
if options['database'] not in DBS: | ||
raise CommandError("Name of database is incorrect. Use one of the " | ||
"following options: {}".format( | ||
', '.join(DBS))) | ||
|
||
input_file = options['input_file'] | ||
database = options['database'] | ||
self.process_file(input_file, database) | ||
|
||
def process_file(self, input_file, database): | ||
print(input_file, database) | ||
with open(input_file, "r") as handle: | ||
data = handle.readlines() | ||
|
||
entries = [] | ||
for raw_line in tqdm(data): | ||
line = raw_line.strip() | ||
fields = line.split("\t") | ||
if database == 'candidato_2014': | ||
c = Cazador( | ||
raw_data=" ".join([ | ||
fields[2], | ||
fields[3], | ||
fields[4], | ||
fields[1], | ||
fields[7], | ||
]), | ||
source=database, | ||
) | ||
elif database == 'redam': | ||
c = Cazador( | ||
raw_data=", ".join(fields), | ||
source=database, | ||
) | ||
elif database == 'narcoindultos': | ||
c = Cazador( | ||
raw_data=" ".join(fields), | ||
source=database, | ||
) | ||
else: | ||
c = Cazador( | ||
raw_data=" ".join([fields[2], fields[10], fields[1]]), | ||
source=database, | ||
) | ||
entries.append(c) | ||
Cazador.objects.bulk_create(entries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Cazador', | ||
fields=[ | ||
('id', models.AutoField(serialize=False, primary_key=True)), | ||
('raw_data', models.TextField()), | ||
('source', models.TextField()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from haystack import indexes | ||
from .models import Cazador | ||
|
||
|
||
class CazadorIndex(indexes.SearchIndex, indexes.Indexable): | ||
text = indexes.CharField(document=True, use_template=True) | ||
|
||
def get_model(self): | ||
return Cazador |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
from django.shortcuts import render_to_response, redirect | ||
from django.shortcuts import render_to_response | ||
|
||
from .utils import search | ||
from cazador.forms import CazadorForm | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
|
||
@csrf_exempt | ||
def index(request): | ||
if 'q' in request.GET: | ||
name = request.GET['q'].strip() | ||
results = search(name) | ||
form = CazadorForm(request.GET) | ||
query = request.GET['q'] | ||
|
||
return render_to_response('cazador/results.html', {'results': results}) | ||
all_items = form.search() | ||
all_items = [i.object for i in all_items] | ||
|
||
return render_to_response('cazador/index.html') | ||
return render_to_response("cazador/results.html", | ||
{ | ||
"results": all_items, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import models | ||
import hashlib | ||
|
||
|
||
class Visitor(models.Model): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ object.raw_data }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ python-slugify==0.1.0 | |
six==1.9 | ||
elasticsearch==1.4.0 | ||
wheel==0.24.0 | ||
tqdm |