Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
avresearcher/static/js/lib/* -diff
hunspell/** -diff
r.js -diff
14 changes: 7 additions & 7 deletions avresearcher/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@
' %s. After verification, a member of the '
'AVResearcherXL team will grant you access to the'
' AVResearcherXL application. You will be notified'
' by email as soon as your account is approved.'
' by email as soon as your account has been approved.'
'\n\nRegards,\nThe AVResearcherXL team',
'email_approval_subject': '[AVResearcherXL] New user registration',
'email_approval_body': 'The following user registered a new AVResearcherXL '
'account:\n\nName: %s\nOrganization: %s\nEmail '
'address: %s\n\nClick the following link to approve '
'this registration and grant the user access to the '
'application: %s',
'email_approved_subject': 'Your AVResearcherXL account is approved',
'email_approved_body': 'Dear %s,\n\nYour AVResearcherXL account is approved '
'email_approved_subject': 'Your AVResearcherXL account has been approved',
'email_approved_body': 'Dear %s,\n\nYour AVResearcherXL account has been approved '
'and activated.\n\nTo start using the AVResearcherXL '
'visit: %s\n\nRegards,\nThe AVResearcherXL team',
'invalid_email_or_password': 'Incorrect email or password',
'email_not_verified': 'You did not yet verifiy your email address. Please '
'click the link in the email you recieved.',
'email_not_verified': 'You did not yet verify your email address. Please '
'click the link in the email you received.',
'account_not_approved': 'Your account first needs to be approved by a '
'member of the AVResearcherXL team. You will recieve'
'member of the AVResearcherXL team. You will receive'
' an email as soon as permission is granted to use '
'the application.',
'email_verified_title': 'Hi %s, thanks for verifying your mail address',
'email_verified_content': 'A member of the AVResearcherXL team will review '
'your application. You will be notified by '
'email as soon as your account is approved.',
'email as soon as your account has been approved.',
'user_approved_title': '%s can now login to the application',
'login_failed': 'Incorrect email or password',
'login_required': 'You must be logged in to use this function'
Expand Down
4 changes: 2 additions & 2 deletions avresearcher/static/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body {
color: #e00034;
}

/* Login & registartion */
/* Login & registration */
.modal {
width: 400px;
margin: 0 auto;
Expand Down Expand Up @@ -1080,4 +1080,4 @@ ul.dropdown li {

#help .subject img.icon {
padding-top: 8px;
}
}
2 changes: 1 addition & 1 deletion avresearcher/static/js/models/avrapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function($, _, Backbone, app){
// Since we only have to replace hits, don't request aggregations.
// This is less expensive on the ES side, and reduces the
// size of the response.
delete payload.aggregations;
delete payload.aggs;

this.http_post('search', payload, function(data){
self.set({
Expand Down
18 changes: 11 additions & 7 deletions avresearcher/static/js/views/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ function($, _, Backbone, d3, aboutTemplate){

this.model.on('change:stats', this.renderIndexStats, this);

this.model.getTotalDocCount('kb');
this.model.getTotalDocCount('immix');

this.model.getFirstLastDocDates('kb');
this.model.getFirstLastDocDates('immix');
for (var i = 0; i < ENABLED_COLLECTIONS.length; i++) {
var coll = ENABLED_COLLECTIONS[i];
this.model.getTotalDocCount(coll);
this.model.getFirstLastDocDates(coll);
}

this.model.getImmixDocsWithSubtitleCount();
this.model.getKbDocsByTypeCount();
if (_.has(ENABLED_COLLECTIONS, 'immix')) {
this.model.getImmixDocsWithSubtitleCount();
}
if (_.has(ENABLED_COLLECTIONS, 'kb')) {
this.model.getKbDocsByTypeCount();
}
},

render: function(){
Expand Down
33 changes: 21 additions & 12 deletions avresearcher/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid
import json

from elasticsearch.helpers import bulk
from flask import (Blueprint, current_app, render_template, abort, request,
jsonify, url_for)
from flask.ext.login import login_user, logout_user, login_required, current_user
Expand Down Expand Up @@ -253,10 +254,10 @@ def logout():
def search():
payload = json.loads(request.form['payload'])

if type(payload) is dict:
if isinstance(payload, dict):
index = current_app.config['COLLECTIONS_CONFIG'].get(payload.pop('index'))['index_name']
results = current_app.es_search.search(index=index, body=payload)
elif type(payload) is list:
elif isinstance(payload, list):
body = []
for query in payload:
body.append({'index': current_app.config['COLLECTIONS_CONFIG'].get(query.pop('index'))['index_name']})
Expand All @@ -283,16 +284,24 @@ def count():
@views.route('/api/log_usage', methods=['POST'])
@login_required
def log_usage():
events = json.loads(request.form['events'])
user_id = current_user.id
user_id = getattr(current_user, 'id', 'anonymous') # For LOGIN_DISABLED.
bulk(current_app.es_log,
_gen_bulk_events(json.loads(request.form['events']),
user_id=current_user.id,
log_index=current_app.config['ES_LOG_INDEX']),
stats_only=True) # Don't care about errors.

bulkrequest = ''
# Add the user's ID to each event
for event in events:
event['user_id'] = user_id
bulkrequest = bulkrequest + '\n' + '{ "create" : { "_index" : "' + current_app.config['ES_LOG_INDEX'] + '", "_type" : "event" } }'
bulkrequest = bulkrequest + '\n' + json.dumps(event)
return jsonify({'success': True})

current_app.es_log.bulk(body=bulkrequest)

return jsonify({'success': True})
def _gen_bulk_events(events, user_id, log_index):
"""Updates events (in-place) with user_id + metadata for bulk transfer."""
metadata = [
('_op_type', 'create'),
('_index', log_index),
('_type', 'event'),
('user_id', user_id),
]
for event in events:
event.update(metadata)
yield event