Skip to content

Commit

Permalink
add user to tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKatsoulis committed Dec 17, 2017
1 parent 9de3631 commit 8e22960
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
21 changes: 13 additions & 8 deletions scrader_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ def development_mode(user):
button_dict_tmpl = {
'type': "json_plugin_url",
'title': 'Positive Predictions',
'url': "http://146.185.138.240/dev_news/{}/{}".format('POS', 1)
'url': "http://146.185.138.240/dev_news/{}/{}/{}".format('POS', 1,
user.
get('name'))
}
buttons.append(button_dict_tmpl)
button_dict_tmpl = {
'type': "json_plugin_url",
'title': 'Negative Predictions',
'url': "http://146.185.138.240/dev_news/{}/{}".format('NEG', 1)
'url': "http://146.185.138.240/dev_news/{}/{}/{}".format('NEG', 1,
user.
get('name'))
}
buttons.append(button_dict_tmpl)

Expand All @@ -212,15 +216,15 @@ def development_mode(user):
return flask.Response(js, status=status, mimetype='application/json')


@app.route('/dev_news/<news_type>/<page_num>'.format(methods=['GET']))
def get_development_news(news_type, page_num):
@app.route('/dev_news/<news_type>/<page_num>/<user>'.format(methods=['GET']))
def get_development_news(news_type, page_num, user):
""" GET Server Status API endpoint
Args:
Returns:
dict: A JSON object containing the nfvacc server status information
"""

response_data = utils.get_development_news(news_type, page_num)
response_data = utils.get_development_news(news_type, page_num, user)
status = 200 if response_data is not None else 403
js = json.dumps(response_data, indent=2)
return flask.Response(js, status=status, mimetype='application/json')
Expand Down Expand Up @@ -904,16 +908,17 @@ def get_news(company, news_type, page_num):


@app.route(
'/checked_article/<news_type>/<new_id>/<value>/<page_num>'.format(methods=['GET'])
'/checked_article/<news_type>/<new_id>/<value>/<page_num>/<user>'.
format(methods=['GET'])
)
def tag_article(news_type, new_id, value, page_num):
def tag_article(news_type, new_id, value, page_num, user):
""" GET Server Status API endpoint
Args:
Returns:
dict: A JSON object containing the nfvacc server status information
"""

utils.manually_tag_article(new_id, value)
utils.manually_tag_article(new_id, value, user)
return get_development_news(news_type, page_num)


Expand Down
14 changes: 8 additions & 6 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_companies_articles(company):
return list(mongo.find_matches('articles', {'company': company}))


def manually_tag_article(article_id, value):
def manually_tag_article(article_id, value, user):
article = mongo.find_one_match('dev_articles',
{"_id": ObjectId(article_id)})
if value == 'Wrong':
Expand All @@ -93,6 +93,8 @@ def manually_tag_article(article_id, value):
{'direction': 'POS'})
mongo.insert_one_in('dev_articles', {"_id": ObjectId(article_id)},
{'checked': True})
mongo.insert_one_in('dev_articles', {"_id": ObjectId(article_id)},
{'User': user})


def article_from_excel():
Expand Down Expand Up @@ -164,7 +166,7 @@ def start_scheduler_task():
gevent.spawn(start_scheduler)


def get_development_news(news_type, page_num):
def get_development_news(news_type, page_num, user):
elements = []
element = {
"title": '',
Expand Down Expand Up @@ -223,12 +225,12 @@ def get_development_news(news_type, page_num):
element['subtitle'] = new.get('subtitle')
element['item_url'] = str(new.get('item_url'))
id = str(new.get('_id'))
element['buttons'][0]['url'] = "http://146.185.138.240/checked_article/{}/{}/{}/{}".\
format(news_type, id, 'Correct', page_num)
element['buttons'][0]['url'] = "http://146.185.138.240/checked_article/{}/{}/{}/{}/{}".\
format(news_type, id, 'Correct', page_num, user)
element['buttons'][0]['title'] = "Correct Estim"
element['buttons'][0]['type'] = "json_plugin_url"
element['buttons'][1]['url'] = "http://146.185.138.240/checked_article/{}/{}/{}/{}".\
format(news_type, id, 'Wrong', page_num)
element['buttons'][1]['url'] = "http://146.185.138.240/checked_article/{}/{}/{}/{}/{}".\
format(news_type, id, 'Wrong', page_num, user)
element['buttons'][1]['title'] = "Wrong Estim"
element['buttons'][1]['type'] = "json_plugin_url"
elements.append(element)
Expand Down

0 comments on commit 8e22960

Please sign in to comment.