Skip to content

Commit

Permalink
Merge pull request #376 from DataViva/release
Browse files Browse the repository at this point in the history
Release v2.1
  • Loading branch information
diogolundberg committed Jan 10, 2016
2 parents b7fa829 + 77fb815 commit e0bfbe2
Show file tree
Hide file tree
Showing 30 changed files with 2,637 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ db
dataviva/static/json/coords/*.json
dataviva/static/json/networks/*.json
.htpasswd
dump.rdb
11 changes: 5 additions & 6 deletions dataviva/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def get_env_variable(var_name, default=-1):
# Initialize app
app = Flask(__name__, template_folder=os.path.join(datavivadir, 'html'))



# Load default configuration from config.py
app.config.from_object('config')

Expand Down Expand Up @@ -79,11 +77,12 @@ def get_env_variable(var_name, default=-1):

# Load the modules for each different section of the site
''' data API view/models '''
data_api = ['attrs', 'hedu', 'rais', 'sc', 'secex', 'stats']
from dataviva.attrs.views import mod as attrs_module
from dataviva.secex.views import mod as secex_module
from dataviva.rais.views import mod as rais_module
from dataviva.hedu.views import mod as hedu_module
from dataviva.rais.views import mod as rais_module
from dataviva.sc.views import mod as sc_module
from dataviva.secex.views import mod as secex_module
from dataviva.stats.views import mod as stats_module

''' front facing views/models of site '''
Expand All @@ -99,10 +98,10 @@ def get_env_variable(var_name, default=-1):

''' Register these modules as blueprints '''
app.register_blueprint(attrs_module)
app.register_blueprint(secex_module)
app.register_blueprint(rais_module)
app.register_blueprint(hedu_module)
app.register_blueprint(rais_module)
app.register_blueprint(sc_module)
app.register_blueprint(secex_module)
app.register_blueprint(stats_module)

app.register_blueprint(general_module)
Expand Down
10 changes: 8 additions & 2 deletions dataviva/about/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flask.ext.babel import gettext
from dataviva import db, view_cache

from dataviva.general.views import get_locale
from dataviva.attrs.models import Bra, Wld, Course_hedu, Hs
from dataviva.rais.models import Cnae, Cbo

Expand All @@ -18,15 +19,20 @@
from config import ADMINISTRATOR_EMAIL, basedir
import os

mod = Blueprint('about', __name__, url_prefix='/about')
mod = Blueprint('about', __name__, url_prefix='/<lang_code>/about')

@mod.before_request
def before_request():
g.page_type = mod.name
g.color = "#d67ab0"

@mod.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', get_locale())


@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.locale = values.pop('lang_code')

@mod.route('/crosswalk/<attr1>/<attr2>/')
def crosswalk(attr1, attr2):
Expand Down
11 changes: 10 additions & 1 deletion dataviva/account/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataviva import db, lm
from dataviva.general.views import get_locale
from dataviva.account.login_providers import facebook, twitter, google
from dataviva.account.models import User, Starred, ROLE_USER, ROLE_ADMIN
from dataviva.ask.forms import AskForm
Expand All @@ -22,10 +23,18 @@
# from config import SITE_MIRROR
# import urllib2, urllib

mod = Blueprint('account', __name__, url_prefix='/account')
mod = Blueprint('account', __name__, url_prefix='/<lang_code>/account')

RESULTS_PER_PAGE = 10

@mod.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', get_locale())

@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.locale = values.pop('lang_code')

@mod.route('/status/')
def check_status():
result = g.user.is_authenticated()
Expand Down
61 changes: 35 additions & 26 deletions dataviva/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask.ext.babel import gettext
from dataviva import db
from datetime import datetime
from dataviva.general.views import get_locale
# models
from dataviva.account.models import User
from dataviva.ask.models import Question, Status, Reply, Flag, Vote
Expand All @@ -20,7 +21,7 @@
# import urllib2, urllib
# from config import SITE_MIRROR

mod = Blueprint('admin', __name__, url_prefix='/admin')
mod = Blueprint('admin', __name__, url_prefix='/<lang_code>/admin')

def get_current_user_role():
return g.user.role
Expand All @@ -39,6 +40,14 @@ def wrapped(*args, **kwargs):
def before_request():
g.page_type = "admin"

@mod.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', get_locale())

@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.locale = values.pop('lang_code')

###############################
# Views for ALL logged in users
# ---------------------------
Expand Down Expand Up @@ -193,8 +202,8 @@ def admin_questions_edit(status, question_id):

return render_template("admin/admin_questions_edit.html",
question=q, status=status, form=form)


@mod.route('/questions/delete/<int:question_id>/', methods=['GET', 'POST'])
@required_roles(1)
def admin_questions_delete(question_id):
Expand All @@ -205,9 +214,9 @@ def admin_questions_delete(question_id):
db.session.delete(q)
db.session.commit()
flash(gettext('The item was successfully deleted.'))

return redirect(url_for(".admin_questions", status=status))


@mod.route('/replies/')
@login_required
Expand All @@ -231,7 +240,7 @@ def admin_replies_list():
limit = 50

# get all users EXCEPT the logged in user

reply = Reply.query.filter_by(hidden=2)
question = Question.query

Expand All @@ -241,7 +250,7 @@ def admin_replies_list():
i["body"] = strip_html(i["body"])
q = question.get(i["question_id"])
i['question_title'] = q.question

ret = jsonify({"activities":items})

ret.headers.add('Last-Modified', datetime.now())
Expand All @@ -255,16 +264,16 @@ def admin_replies_list():
@login_required
@required_roles(1)
def admin_replies_question(question_id):

questions = Question.query.get_or_404(question_id)
reply = Reply.query.filter_by(question_id=question_id)
replies = reply.order_by(Reply.hidden.asc(), Reply.timestamp.desc()).limit(50).offset(0).all()
user = User.query.get(questions.user_id)
questions.replies = replies
#questions.user = user

return render_template("admin/admin_replies_question.html", q=questions)


@mod.route('/replieslist/question/<int:questionid>/')
@login_required
Expand All @@ -275,16 +284,16 @@ def admin_replies_question_list(questionid):
limit = 50

# get all users EXCEPT the logged in user

reply = Reply.query.filter_by(question_id=questionid)
items = reply.order_by(Reply.hidden.desc(), Reply.timestamp.desc()).limit(limit).offset(offset).all()

items = [i.serialize() for i in items]

for i in items:
i["body"] = strip_html(i["body"])


ret = jsonify({"activities":items})

ret.headers.add('Last-Modified', datetime.now())
Expand All @@ -296,33 +305,33 @@ def admin_replies_question_list(questionid):
@mod.route('/replies/delete/<int:reply_id>/')
@required_roles(1)
def delete_reply_question(reply_id):

vote = Vote.query.filter_by(type_id=reply_id).delete()

reply = Reply.query.get(reply_id)
question = reply.question_id

db.session.delete(reply)
db.session.commit()

flash(gettext('The item was successfully deleted.'))

return redirect(url_for(".admin_replies_question", question_id=question))



@mod.route('/reply/delete/<int:reply_id>/', methods = ['GET'])
@required_roles(1)
def delete_reply(reply_id):



reply = Reply.query.get(reply_id)

db.session.delete(reply)
db.session.commit()
flash(gettext('The item was successfully deleted.'))

return redirect(url_for(".admin_replies"))


Expand Down
1 change: 1 addition & 0 deletions dataviva/apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def slug(self, **kwargs):

slug = getattr(self, "slug_{}".format(g.locale))
slug = self.format_text(slug, kwargs)

return slug

def slug2(self):
Expand Down
19 changes: 14 additions & 5 deletions dataviva/apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask.ext.babel import gettext

from dataviva import db, datavivadir, __year_range__, view_cache
from dataviva.general.views import get_locale
from dataviva.data.forms import DownloadForm
from dataviva.account.models import User, Starred
from dataviva.attrs.models import Bra, Cnae, Hs, Cbo, Wld, University, Course_hedu, Course_sc, Search
Expand All @@ -25,7 +26,7 @@
import os, urlparse, random, zipfile, sys, gzip
from dataviva.utils.cached_query import api_cache_key

mod = Blueprint('apps', __name__, url_prefix='/apps')
mod = Blueprint('apps', __name__, url_prefix='/<lang_code>/apps')

@mod.before_request
def before_request():
Expand All @@ -39,6 +40,14 @@ def before_request():
"hat": "glasses"
}

@mod.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', get_locale())

@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.locale = values.pop('lang_code')

def filler(dataset, filter1, filter2):

'''Since the "builds" are held in the database with placeholders for
Expand Down Expand Up @@ -457,17 +466,17 @@ def get_geo_location(ip):
"filter1": "all", "filter2": "all", "output": "balance", "params": ""})
@mod.route('/builder/box/', defaults={"app_name": "box", "dataset": "sc", "bra_id": "4mg",
"filter1": "all", "filter2": "all", "output": "age", "params": ""})
@mod.route('/builder/bar/', defaults={"app_name": "box", "dataset": "rais", "bra_id": "4mg",
@mod.route('/builder/bar/', defaults={"app_name": "bar", "dataset": "rais", "bra_id": "4mg",
"filter1": "all", "filter2": "all", "output": "bra", "params": ""})
@mod.route('/builder/<app_name>/<dataset>/<bra_id>/<filter1>/<filter2>/<output>/')
@view_cache.cached(key_prefix=api_cache_key("apps:builder"))
def builder(app_name=None, dataset=None, bra_id=None, filter1=None,
filter2=None, output=None, params=None):
if bra_id == 'bra':
bra_id = 'all'
return redirect('/{0}/{1}/{2}/{3}/{4}/{5}/{6}?{7}'.format('apps/builder',app_name,dataset,bra_id,filter1,filter2,output,request.query_string))
if len(request.path.split("/")) == 5:
return redirect('{0}{1}/{2}/{3}/{4}/{5}/{6}'.format(request.path,dataset,bra_id,filter1,filter2,output,request.query_string))
return redirect('/{0}/{1}/{2}/{3}/{4}/{5}/{6}/{7}?{8}'.format(g.locale, 'apps/builder', app_name, dataset, bra_id, filter1, filter2, output, request.query_string))
if len(request.path.split("/")) == 6:
return redirect('{0}{1}/{2}/{3}/{4}/{5}/{6}'.format(request.path, dataset, bra_id, filter1, filter2, output, request.query_string))
g.page_type = "builder"
builds = Build.query.all()
builds = [b.json(fill=False) for b in builds]
Expand Down
10 changes: 9 additions & 1 deletion dataviva/ask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@

import urllib2, urllib

mod = Blueprint('ask', __name__, url_prefix='/ask')
mod = Blueprint('ask', __name__, url_prefix='/<lang_code>/ask')

RESULTS_PER_PAGE = 10

@mod.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', g.locale)

@mod.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.locale = values.pop('lang_code')

@mod.route('/questions/', methods=['GET', 'POST'], defaults={'page': 1})
def question_list(page):

Expand Down
Loading

0 comments on commit e0bfbe2

Please sign in to comment.