Skip to content

Commit

Permalink
Merge pull request #1175 from scieloorg/beta
Browse files Browse the repository at this point in the history
Incorporação de códigos estáveis
  • Loading branch information
gustavofonseca committed Aug 4, 2015
2 parents aab8409 + b481a02 commit dca2922
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 23 deletions.
3 changes: 3 additions & 0 deletions docs/dev/rpc_spec/getScanArticlesBatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Exemplo::

batch_id = result.next_batch_id


.. note:: A lista de resultados de um lote não é ordenada por data ou qualquer
campo.
37 changes: 35 additions & 2 deletions docs/dev/rpc_spec/scanArticles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Os índices que podem ser utilizados na consulta são:
+----------------------+------------------------------------------------------+
| source | O documento XML codificado em utf-8. |
+----------------------+------------------------------------------------------+
| timestamp | Data e hora conforme ISO-8601 (combined). |
+----------------------+------------------------------------------------------+


.. note:: A quantidade de registros por lote não é definida pelo cliente, e
Expand All @@ -51,8 +53,39 @@ Os índices que podem ser utilizados na consulta são:
Exemplo::

batch_id = client.scanArticles('{"query": {"match": {"year": "2013"}}}')
next_batch_id, articles = client.getScanArticlesBatch(batch_id)
results = client.getScanArticlesBatch(batch_id)

for article in articles:
for article in results.articles:
...


Casos de uso
------------

1. Coleta incremental de lotes, com base na data e hora de modificação dos
registros::

{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": {
"timestamp": {
"gte": "2015-08-04T02:04:37.993423",
"lte": "now"
}
}
}
}
}
}


É importante notar que os resultados da consulta '''não''' são ordenados, mesmo
quando utilizada a instrução ``sort``. O cliente deverá identificar o maior
valor de ``timestamp`` entre os registros recuperados para a recuperação do
próximo incremento.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django==1.4.10
Django<1.5
South
psycopg2==2.4.1
wsgiref==0.1.2
Expand Down
2 changes: 1 addition & 1 deletion scielomanager/accounts/templates/accounts/my_account.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h4>{% trans "API Token" %}:</h4>
<script>
$(document).ready(function() {
$('input', '#change_password_form').removeClass('span3').addClass('span12');
$('select', '#profile_form').addClass('span12').chosen();
$('select', '#profile_form').addClass('span12').chosen(defaultChosenOptions);
});
</script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ <h2>{% trans "Delete Board Member" %}?:</h2>
$('#board-member-form').find('form').submit();
});
$('input').addClass('span12');
$(".chzn-select").chosen({
no_results_text: "{% trans 'No results found for' %}:",
width: "100%",
});
var chosenOptions = defaultChosenOptions;
chosenOptions['width'] = "100%";
$(".chzn-select").chosen(chosenOptions);
});
</script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ <h2>{% trans "Edit Board Member" %}:</h2>
$('#board-member-form').find('form').submit();
});
$('input').addClass('span12');
$(".chzn-select").chosen({
no_results_text: "{% trans 'No results found for' %}:",
width: "100%",
});
var chosenOptions = defaultChosenOptions;
chosenOptions['width'] = "100%";
$(".chzn-select").chosen(chosenOptions);
{% include "includes/add_member_form_loaded_callbacks.js" %}
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h2>{% trans "Editor" %}:</h2>
prefix: '{{ missionformset.prefix }}'
});

$(".chzn-select").chosen({no_results_text: "{% trans 'No results found for' %}:"});
$(".chzn-select").chosen(defaultChosenOptions);

</script>
{% endblock %}
1 change: 1 addition & 0 deletions scielomanager/journalmanager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _gen_es_struct_from_article(article):
'is_aop': article.is_aop,
'source': article_as_octets,
'aid': article.aid,
'timestamp': datetime.datetime.now(),
}

es_struct.update(partial_struct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ <h2>{% trans "User Collections" %}:</h2>
{{ block.super }}
<script>
$(document).ready(function() {
$('.chosen-select').chosen()
$('.chosen-select').chosen(defaultChosenOptions)
$( "#id_user-collection" ).combobox({ autoFocus: true });
$(".help-text").popover('hide');
$( "#toggle" ).click(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@

});

$(".chzn-select").chosen({no_results_text: "Nenhum resultado encontrado para: "})
$(".chzn-select").chosen(defaultChosenOptions)

$('#modal').on('shown', function () {

$("select[name='editor']").attr('class', 'chzn-select span12');
$(".chzn-select").chosen({no_results_text: "Nenhum resultado encontrado para: "});
$(".chzn-select").chosen(defaultChosenOptions);

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@

{% block extrafooter %}
<script>
$(".chzn-select").chosen({no_results_text: "No users found for:"})
$(".chzn-select").chosen(defaultChosenOptions)
</script>
{% endblock %}
7 changes: 6 additions & 1 deletion scielomanager/scielomanager/connectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
Um conector é apenas um link entre dois ou mais elementos conectáveis (e.g.,
portas, interfaces etc).
"""
import os

# se apoia na definição da variável __all__ nos módulos.
from .storage import *


__all__ = (storage.__all__,)
_CWD = os.path.dirname(os.path.abspath(__file__))
ES_ARTICLE_MAPPING_PATH = os.path.join(_CWD, 'article_mapping.json')


__all__ = (storage.__all__, ES_ARTICLE_MAPPING_PATH)

59 changes: 59 additions & 0 deletions scielomanager/scielomanager/connectors/article_mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"article": {
"_timestamp": {
"enabled": true,
"path": "timestamp"
},
"properties": {
"abbrev_journal_title": {
"type": "string"
},
"aid": {
"type": "string",
"index": "not_analyzed"
},
"article_type": {
"type": "string",
"index": "not_analyzed"
},
"doi": {
"type": "string",
"index": "not_analyzed"
},
"epub": {
"type": "string",
"index": "not_analyzed"
},
"head_subject": {
"type": "string"
},
"is_aop": {
"type": "boolean"
},
"issue": {
"type": "string",
"index": "not_analyzed"
},
"pid": {
"type": "string",
"index": "not_analyzed"
},
"ppub": {
"type": "string",
"index": "not_analyzed"
},
"version": {
"type": "string",
"index": "not_analyzed"
},
"volume": {
"type": "string",
"index": "not_analyzed"
},
"year": {
"type": "date",
"format": "yyyy"
}
}
}
}
Empty file.
Empty file.
90 changes: 90 additions & 0 deletions scielomanager/scielomanager/management/commands/es.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# coding: utf-8
"""Tarefas de manutenção da integração com o Elasticsearch.
"""
from django.core.management.base import BaseCommand, CommandError
import elasticsearch

from scielomanager import connectors


_TYPE_CLIENT_MAP = {
'article': connectors.ArticleElasticsearch,
}


_HELP = u"""\
Executa tarefas de manutenção da integração com o Elasticsearch.
Os comandos são:
putmapping <type> Adiciona ou atualiza o mapping de um tipo.
createindex <type> Cria o índice e define o mapping do tipo.
Os valores de <type> são:
%s
""" % (_TYPE_CLIENT_MAP.keys(),)


def _to_bytestring(text):
return text.encode('utf-8')


def _get_article_mapping():
with open(connectors.ES_ARTICLE_MAPPING_PATH, 'r') as mapping_file:
mapping_data = mapping_file.read()

return mapping_data


def _put_mapping(type):
"""
"""
client_cls = _TYPE_CLIENT_MAP.get(type)
if client_cls is None:
raise CommandError(
_to_bytestring(u'"%s" não é um tipo válido' % type))

client = client_cls()
mapping_data = _get_article_mapping()

client.es_client.indices.put_mapping(index=client.index,
doc_type=client.doctype, body=mapping_data, ignore_conflicts=False,
timeout=2)


def _create_index(type):
client_cls = _TYPE_CLIENT_MAP.get(type)
if client_cls is None:
raise CommandError(
_to_bytestring(u'"%s" não é um tipo válido' % type))

client = client_cls()

client.es_client.indices.create(index=client.index, timeout=2)
_put_mapping(type)


class Command(BaseCommand):
args = '<command> [<args>]'
help = _HELP
requires_model_validation = False

def handle(self, *args, **options):
if not args:
raise CommandError(
_to_bytestring("'./manage.py help es' para ajuda."))

command = args[0]
arguments = args[1:]

try:
if command == 'putmapping':
_put_mapping(*arguments)
elif command == 'createindex':
_create_index(*arguments)
else:
raise CommandError(
_to_bytestring(u'Comando inválido'))

except elasticsearch.exceptions.TransportError as exc:
raise CommandError(str(exc))

1 change: 1 addition & 0 deletions scielomanager/scielomanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
'export',
'health',
'thrift',
'scielomanager', # apenas para management commands
)

TEMPLATE_CONTEXT_PROCESSORS = (
Expand Down
7 changes: 3 additions & 4 deletions scielomanager/scielomanager/static/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ $(function() {
});
$('.modal').on('loaded', function () {
$(this).find('input').addClass('span12');
$(this).find(".chzn-select").chosen({
no_results_text: "{% trans 'No results found for' %}:",
width: "100%",
});
var chosenOptions = defaultChosenOptions;
chosenOptions['width'] = "100%";
$(this).find(".chzn-select").chosen(chosenOptions);
})

/* actions: */
Expand Down
3 changes: 3 additions & 0 deletions scielomanager/scielomanager/templates/base_lv0.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
<script type="text/javascript">
var defaultChosenOptions = {
'no_results_text': "{% trans 'No results found for' %}:",
}
$(document).ready(function(){
$('#list_model').change(function(){
$('#search-form').attr('action', $('#list_model :selected').val());
Expand Down
3 changes: 2 additions & 1 deletion scielomanager/thrift/scielomanager.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace py scielomanager
* IMPORTANTE! Alterar o valor de VERSION após qualquer alteração na interface.
* Regras em: http://semver.org/lang/pt-BR/
*/
const string VERSION = "1.0.0"
const string VERSION = "1.1.0"


#
Expand Down Expand Up @@ -72,6 +72,7 @@ struct Article {
12: required string version;
13: optional bool is_aop;
14: required string source;
15: required string timestamp;
}

/*
Expand Down

0 comments on commit dca2922

Please sign in to comment.