Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple results at once #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion search/templates/cosmos/data.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ <h5>
<button type="button" name="button" class="btn btn-light tool" onclick="getValue()"><i class="fa fa-clipboard"></i><span class="tooltiptext">Copied</span></button>
</div>
</div>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="soln"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Solutions [{{ result|length }}]
</button>
<div class="dropdown-menu" aria-labelledby="soln">
{% for i in result %}
<form method="GET" action="{% url 'display' %}" target="_blank">
<button type="submit" name="path" class="dropdown-item" value="{{ apath }}/{{ i }}">{{ i }}</button>
</form>
{% endfor %}
</div>

<div style="display: none;" id="select">{{code}}</div>
<pre class="language">
<code>
Expand All @@ -97,4 +111,4 @@ <h5>
createtag.remove();
}
</script>
{% endblock %}
{% endblock %}
40 changes: 39 additions & 1 deletion search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

# Create your views here

a = []
b = []
count = 0


# To prefill the searchbar
def get_random_tag():
Expand Down Expand Up @@ -114,6 +118,7 @@ def is_file_extension_ignored(file_):

def query(request):
global ans, rec
global a, b, count
title = ''
algo_name = ''
amount = 0
Expand Down Expand Up @@ -167,6 +172,11 @@ def query(request):
path = folder
folder_list = folder.split('/')
ans.append({'path': path, 'dirs': folder_list, 'files': filtered_v})

a.append(folder_list)
b.append(filtered_v)
count = count + 1

amount += len(filtered_v)
if len(folder_list) == 2:
d = folder_list[-2] + '/'
Expand Down Expand Up @@ -290,11 +300,39 @@ def subsq(a, b, m, n):

def display(request):
path = request.GET['path']
ans = []
q = get_array1()
p = get_array2()
n = cnt()
new = path.split("/")
no = len(new) - 2
for i in range(0, n):
num = len(q[i])
for j in range(0, num):
if (new[no] == q[i][j]):
ans = p[i]
display = "https://raw.githubusercontent.com/OpenGenus/cosmos/master/code/" + path
r = requests.get(display)
k = path.split('/')
nk = len(k)
a = k[0]
for i in range(1, nk - 1):
a = a + '/' + k[i]
path = path.replace('_', ' ')
path = path.replace('.', ' in ')
l = path.split('/')
if 'src' in l:
l.remove('src')
return render(request, 'cosmos/data.html', {'code': r.text, 'path': l})
return render(request, 'cosmos/data.html', {'code': r.text, 'path': l, "result": ans, "apath": a})


def get_array1():
return (a)


def get_array2():
return(b)


def cnt():
return(count)