From 2b735e3b97edbe303cca734399782757ca073b3c Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 20 Jan 2020 15:13:03 +0100 Subject: [PATCH] chg: [UI item tags search] refractor: search item tag by object, use new functions --- bin/packages/Date.py | 2 + bin/packages/Tag.py | 21 +- var/www/blueprints/tags_ui.py | 25 +- .../PasteSubmit/templates/submit_items.html | 2 +- var/www/modules/Tags/Flask_Tags.py | 268 +++++++++--------- .../modules/Tags/templates/header_Tags.html | 2 +- .../hiddenServices/templates/domains.html | 2 +- .../modules/hunter/templates/showTracker.html | 4 +- .../hunter/templates/trackersManagement.html | 4 +- var/www/modules/search/templates/search.html | 4 +- var/www/modules/showpaste/Flask_showpaste.py | 1 + .../crawler/crawler_splash/showDomain.html | 2 +- var/www/templates/modals/show_min_item.html | 114 ++++++++ var/www/templates/nav_bar.html | 4 +- .../templates/tags/block_obj_tags_search.html | 100 ++++--- var/www/templates/tags/menu_sidebar.html | 18 +- .../templates/tags/search_obj_by_tags.html | 46 +++ 17 files changed, 404 insertions(+), 215 deletions(-) create mode 100644 var/www/templates/modals/show_min_item.html diff --git a/bin/packages/Date.py b/bin/packages/Date.py index 74563cb5..14be5b6b 100644 --- a/bin/packages/Date.py +++ b/bin/packages/Date.py @@ -126,6 +126,8 @@ def validate_str_date(str_date, separator=''): return True except ValueError: return False + except TypeError: + return False def sanitise_date_range(date_from, date_to, separator=''): ''' diff --git a/bin/packages/Tag.py b/bin/packages/Tag.py index f011bb41..dba1b26e 100755 --- a/bin/packages/Tag.py +++ b/bin/packages/Tag.py @@ -446,7 +446,7 @@ def delete_obj_tags(object_id, object_type, tags=[]): return res def sanitise_tags_date_range(l_tags, date_from=None, date_to=None): - if date_from and date_to is None: + if date_from or date_to is None: date_from = get_tags_min_last_seen(l_tags, r_int=False) date_to = date_from return Date.sanitise_date_range(date_from, date_to) @@ -473,7 +473,7 @@ def get_obj_by_tags(object_type, l_tags, date_from=None, date_to=None, nb_obj=50 if object_type=='item': #sanityze date date_range = sanitise_tags_date_range(l_tags, date_from=date_from, date_to=date_to) - l_dates = Date.substract_date(date_from, date_to) + l_dates = Date.substract_date(date_range['date_from'], date_range['date_to']) for date_day in l_dates: l_set_keys = get_obj_keys_by_tags(object_type, l_tags, date_day) @@ -499,12 +499,21 @@ def get_obj_by_tags(object_type, l_tags, date_from=None, date_to=None, nb_obj=50 if page > nb_pages: page = nb_pages - # select index start = nb_obj*(page -1) - stop = (nb_obj*page) -1 - l_tagged_obj = l_tagged_obj[start:stop] + if nb_pages > 1: + stop = (nb_obj*page) + l_tagged_obj = l_tagged_obj[start:stop] + # only one page + else: + stop = nb_all_elem + l_tagged_obj = l_tagged_obj[start:] - return {"tagged_obj":l_tagged_obj, "page":page, "nb_pages":nb_pages, "nb_first_elem":start+1, "nb_last_elem":stop+1, "nb_all_elem":nb_all_elem} + if stop > nb_all_elem: + stop = nb_all_elem + stop = stop -1 + + return {"tagged_obj":l_tagged_obj, "date" : date_range, + "page":page, "nb_pages":nb_pages, "nb_first_elem":start+1, "nb_last_elem":stop+1, "nb_all_elem":nb_all_elem} # without daterange else: diff --git a/var/www/blueprints/tags_ui.py b/var/www/blueprints/tags_ui.py index 9f5e8e7b..56cd788f 100644 --- a/var/www/blueprints/tags_ui.py +++ b/var/www/blueprints/tags_ui.py @@ -94,6 +94,15 @@ def get_all_obj_tags(): return jsonify(res) return jsonify(Tag.get_all_obj_tags(object_type)) +@tags_ui.route('/tag/search/item') +@login_required +@login_read_only +def tags_search_items(): + object_type = 'item' + dict_tagged = {"object_type":object_type, "object_name":object_type.title() + "s"} + dict_tagged['date'] = Date.sanitise_date_range('', '', separator='-') + return render_template("tags/search_obj_by_tags.html", bootstrap_label=bootstrap_label, dict_tagged=dict_tagged) + @tags_ui.route('/tag/search/domain') @login_required @login_read_only @@ -119,8 +128,14 @@ def get_obj_by_tags(): object_type = request.args.get('object_type') ltags = request.args.get('ltags') page = request.args.get('page') - date_from = request.args.get('ltags') - date_to = request.args.get('ltags') + date_from = request.args.get('date_from') + date_to = request.args.get('date_to') + + # remove date separator + if date_from: + date_from = date_from.replace('-', '') + if date_to: + date_to = date_to.replace('-', '') # unpack tags list_tags = ltags.split(',') @@ -139,12 +154,13 @@ def get_obj_by_tags(): except: page = 1 - dict_obj = Tag.get_obj_by_tags(object_type, list_tag, page=page) + dict_obj = Tag.get_obj_by_tags(object_type, list_tag, date_from=date_from, date_to=date_to, page=page) if dict_obj['tagged_obj']: dict_tagged = {"object_type":object_type, "object_name":object_type.title() + "s", "tagged_obj":[], "page":dict_obj['page'] ,"nb_pages":dict_obj['nb_pages'], "nb_first_elem":dict_obj['nb_first_elem'], "nb_last_elem":dict_obj['nb_last_elem'], "nb_all_elem":dict_obj['nb_all_elem']} + for obj_id in dict_obj['tagged_obj']: obj_metadata = Correlate_object.get_object_metadata(object_type, obj_id) obj_metadata['id'] = obj_id @@ -162,4 +178,7 @@ def get_obj_by_tags(): else: dict_tagged = {"object_type":object_type, "object_name":object_type.title() + "s"} + if 'date' in dict_obj: + dict_tagged['date'] = dict_obj['date'] + return render_template("tags/search_obj_by_tags.html", bootstrap_label=bootstrap_label, dict_tagged=dict_tagged) diff --git a/var/www/modules/PasteSubmit/templates/submit_items.html b/var/www/modules/PasteSubmit/templates/submit_items.html index 454b8e7a..ad22c660 100644 --- a/var/www/modules/PasteSubmit/templates/submit_items.html +++ b/var/www/modules/PasteSubmit/templates/submit_items.html @@ -62,7 +62,7 @@