From 59e098321f2131ca2b9c5c46b174c6875efb2f2c Mon Sep 17 00:00:00 2001 From: kingiw Date: Wed, 17 Oct 2018 19:56:12 +0800 Subject: [PATCH 1/4] bug fix --- designSite/design/tools/pre_load_data.py | 36 +++++++++++++----------- designSite/opt_sim_module/optimize.py | 2 +- designSite/search/views/search_views.py | 8 +++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/designSite/design/tools/pre_load_data.py b/designSite/design/tools/pre_load_data.py index 414ca8e..9b48349 100644 --- a/designSite/design/tools/pre_load_data.py +++ b/designSite/design/tools/pre_load_data.py @@ -1129,13 +1129,15 @@ def load_chassis(path): def final(): + print("Finalizing...") for i in Works.objects.filter(Year__lte = 2008): i.delete() - for work in Works.objects.filter(Circuit = None, Year__lte = 2016): - parts = work.Use_parts.split(';') - if len(parts) == 0: + + for work in Works.objects.filter(Circuit = None): + if len(work.Use_parts) == 0: # No parts info continue + parts = work.Use_parts.split(';') circuit = Circuit.objects.create( Name = work.Teamname + str(work.TeamID), Description = '') @@ -1240,18 +1242,18 @@ def load_2017_works(works_floder_path): def pre_load_data(currentpath, Imgpath): - load_parts(os.path.join(currentpath, 'parts')) - load_chassis(os.path.join(currentpath, 'chassis')) - # load_partsInteration(os.path.join(currentpath, 'partsinteract')) - load_partsParameter(os.path.join(currentpath, 'partsParameter')) - load_works(os.path.join(currentpath, 'works')) - load_2017_works(os.path.join(currentpath, 'works')) - load_Trelation(os.path.join(currentpath, 'TeamRelation')) - load_Teamkeyword(os.path.join(currentpath, 'TeamKeyword')) - load_papers(os.path.join(currentpath, 'papers')) - load_circuits(os.path.join(currentpath, 'works/circuits'), delete=True) - load_2017_circuits(os.path.join(currentpath, 'works/circuits/2017.xlsx')) - load_circuits(os.path.join(currentpath, 'papers/circuits'), is_work = False) - # #load_circuits(os.path.join(currentpath, 'works/circuits2')) - load_additional(os.path.join(currentpath, 'additional')) + # load_parts(os.path.join(currentpath, 'parts')) + # load_chassis(os.path.join(currentpath, 'chassis')) + # # load_partsInteration(os.path.join(currentpath, 'partsinteract')) + # load_partsParameter(os.path.join(currentpath, 'partsParameter')) + # load_works(os.path.join(currentpath, 'works')) + # load_2017_works(os.path.join(currentpath, 'works')) + # load_Trelation(os.path.join(currentpath, 'TeamRelation')) + # load_Teamkeyword(os.path.join(currentpath, 'TeamKeyword')) + # load_papers(os.path.join(currentpath, 'papers')) + # load_circuits(os.path.join(currentpath, 'works/circuits'), delete=True) + # load_2017_circuits(os.path.join(currentpath, 'works/circuits/2017.xlsx')) + # load_circuits(os.path.join(currentpath, 'papers/circuits'), is_work = False) + # # #load_circuits(os.path.join(currentpath, 'works/circuits2')) + # load_additional(os.path.join(currentpath, 'additional')) final() \ No newline at end of file diff --git a/designSite/opt_sim_module/optimize.py b/designSite/opt_sim_module/optimize.py index 0e67f61..5d59c42 100644 --- a/designSite/opt_sim_module/optimize.py +++ b/designSite/opt_sim_module/optimize.py @@ -4,7 +4,7 @@ import math from opt_sim_module.solve import * -def optimization(data, target, k, evol_t,ith_protein): +def optimization(data, target, k, evol_t, ith_protein): class Chrom: chrom = [] fitness = 0.0 diff --git a/designSite/search/views/search_views.py b/designSite/search/views/search_views.py index c92525a..1a5733e 100644 --- a/designSite/search/views/search_views.py +++ b/designSite/search/views/search_views.py @@ -57,10 +57,10 @@ def update(w_dict, key, w): logging.info(keys) w_dict = {} if search_type == 'project': - # try: - nn_search_result = recommend_team(keys[0]) - # except: - # logging.info("Unable to load nn search module.") + try: + nn_search_result = recommend_team(keys[0]) + except: + logging.info("Unable to load nn search module.") for key in keys: if key.isdigit(): # May be year q_on_Year = Works.objects.filter(Year__exact=int(key)) From df2ca49f7b43e3cea6a98f41b63f6f3613abddda Mon Sep 17 00:00:00 2001 From: kingiw Date: Wed, 17 Oct 2018 20:03:24 +0800 Subject: [PATCH 2/4] sth --- designSite/search/views/search_views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/designSite/search/views/search_views.py b/designSite/search/views/search_views.py index 1a5733e..1fbcb6f 100644 --- a/designSite/search/views/search_views.py +++ b/designSite/search/views/search_views.py @@ -57,10 +57,15 @@ def update(w_dict, key, w): logging.info(keys) w_dict = {} if search_type == 'project': + if search.nn_search_flag >= 0: try: + nn_search_result = recommend_team(keys[0]) + search.nn_search_flag = 1 # nn_search module is initialized successfully + logging.info("Search module activated!") except: logging.info("Unable to load nn search module.") + search.nn_search_flag = -1 ## nn_search module failed for key in keys: if key.isdigit(): # May be year q_on_Year = Works.objects.filter(Year__exact=int(key)) @@ -188,6 +193,7 @@ def update(w_dict, key, w): }) # logging.info(context) return render(request, 'search_result.html', context) +search.nn_search_flag = 0 @login_required From 1d9178192446e0df8fb6b936175fdebbbf7d6833 Mon Sep 17 00:00:00 2001 From: yanbin Date: Wed, 17 Oct 2018 22:32:10 +0800 Subject: [PATCH 3/4] fix the bug that shared circuit save, get 403 --- .../migrations/0030_auto_20181017_1335.py | 23 +++++++++++++++++++ designSite/design/views/design_views.py | 15 ++++++++++++ designSite/search/views/search_views.py | 16 ++++++------- designSite/static/js/design.js | 8 +++++-- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 designSite/design/migrations/0030_auto_20181017_1335.py diff --git a/designSite/design/migrations/0030_auto_20181017_1335.py b/designSite/design/migrations/0030_auto_20181017_1335.py new file mode 100644 index 0000000..74ba576 --- /dev/null +++ b/designSite/design/migrations/0030_auto_20181017_1335.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.1 on 2018-10-17 13:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('design', '0029_auto_20181017_0130'), + ] + + operations = [ + migrations.AlterField( + model_name='works', + name='DefaultImg', + field=models.URLField(default='static/img/Team_img/none.jpg'), + ), + migrations.AlterField( + model_name='works', + name='logo', + field=models.URLField(default='static/img/Team_img/none.jpg'), + ), + ] diff --git a/designSite/design/views/design_views.py b/designSite/design/views/design_views.py index d661fd7..1a8fbfb 100644 --- a/designSite/design/views/design_views.py +++ b/designSite/design/views/design_views.py @@ -826,14 +826,29 @@ def circuit(request): for i in data['combines'][x]: cd.Sons.add(cids[i]) cd.save() + # now update authority if necessary. for example, `A` save a circuit shared by `B`. + logger.debug('should I update authority?') + if not new and request.user != old_circuit.Author: + logger.debug('save new version and circuit not own by "me"') + auth_query = Authorities.objects.filter(Circuit__Name=name) + logger.debug('revalent auth query %s', auth_query) + if auth_query: + Authorities.objects.create( + User=request.user, + Circuit=circuit, + Authority='write' + ) + logger.debug('insert new write authority') return JsonResponse({ 'status': 1, 'circuit_id': circuit.id}) + except: traceback.print_exc() return JsonResponse({ 'status': 0 }) + else: return JsonResponse({ 'status': 0}) diff --git a/designSite/search/views/search_views.py b/designSite/search/views/search_views.py index 1fbcb6f..49bddc4 100644 --- a/designSite/search/views/search_views.py +++ b/designSite/search/views/search_views.py @@ -58,14 +58,14 @@ def update(w_dict, key, w): w_dict = {} if search_type == 'project': if search.nn_search_flag >= 0: - try: - - nn_search_result = recommend_team(keys[0]) - search.nn_search_flag = 1 # nn_search module is initialized successfully - logging.info("Search module activated!") - except: - logging.info("Unable to load nn search module.") - search.nn_search_flag = -1 ## nn_search module failed + #TODO: I change here. + try: + nn_search_result = recommend_team(keys[0]) + search.nn_search_flag = 1 # nn_search module is initialized successfully + logging.info("Search module activated!") + except: + logging.info("Unable to load nn search module.") + search.nn_search_flag = -1 ## nn_search module failed for key in keys: if key.isdigit(): # May be year q_on_Year = Works.objects.filter(Year__exact=int(key)) diff --git a/designSite/static/js/design.js b/designSite/static/js/design.js index 296f0ed..27133aa 100644 --- a/designSite/static/js/design.js +++ b/designSite/static/js/design.js @@ -816,8 +816,12 @@ $('#save-circuit, #save-as-new-circuit').on('click', () => { }, 3000); // Redirect to the new design - if (v.status === 1) - window.location.replace(`/design/${v.circuit_id}`); + if (v.status === 1) { + let url = window.location.href.split('/'); + url[url.length-1] = `${v.circuit_id}`; + console.log(`${v.circuit_id}`) + window.location.replace(url.join('/')); + } }); }); From 3dc64829b4b313176c07826999358dcdf2ad0279 Mon Sep 17 00:00:00 2001 From: yanbin Date: Wed, 17 Oct 2018 23:32:11 +0800 Subject: [PATCH 4/4] IMPORTANT FIX! url deal success --- designSite/static/js/design.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/designSite/static/js/design.js b/designSite/static/js/design.js index 27133aa..592d7fc 100644 --- a/designSite/static/js/design.js +++ b/designSite/static/js/design.js @@ -818,9 +818,11 @@ $('#save-circuit, #save-as-new-circuit').on('click', () => { // Redirect to the new design if (v.status === 1) { let url = window.location.href.split('/'); - url[url.length-1] = `${v.circuit_id}`; - console.log(`${v.circuit_id}`) - window.location.replace(url.join('/')); + if (url.indexOf('share') !== -1) { + window.location.replace(`/design/share/${v.circuit_id}`); + } else { + window.location.replace(`/design/${v.circuit_id}`); + } } }); });