Skip to content

Commit d281c8d

Browse files
committed
fix pack search
1 parent c443bbd commit d281c8d

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

api/management/commands/scan_packs.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def convert_seconds(seconds):
5555
return " ".join(parts)
5656

5757
def print_warning(string):
58-
RED = '\033[30m'
59-
WARNING = '\033[93m'
60-
RESET = '\033[0m'
61-
print(f"{WARNING}{string}{RESET}")
58+
"""Add some color to terminal printing"""
59+
warning = '\033[93m'
60+
reset = '\033[0m'
61+
print(f"{warning}{string}{reset}")
6262

6363
def extract_file(zip_ref, member, path):
6464
"""Extract s single file from the zip"""
@@ -512,7 +512,6 @@ def save_notedata(chart):
512512
if line.strip().startswith("#NOTES:"):
513513
# RhythmCodex converts put these on single line :facepalm:
514514
if len(line.split(":")) > 6:
515-
rcodex = True
516515
parts = line.split(":")
517516
file_charttype = parts[1]
518517
file_description = parts[2]
@@ -538,7 +537,6 @@ def save_notedata(chart):
538537
diff_name = "Challenge"
539538

540539
# if all these match, it means this is the correct notedata, let save it
541-
#print(f"{type(file_charttype)} {type(charttype)} {type(file_meter)} {type(meter)} {type(diff_name)} {type(difficulty)}")
542540
if (file_charttype.lower(), file_meter, diff_name.lower()) == \
543541
(charttype.lower(), meter, difficulty.lower()):
544542
notedata = ""
@@ -553,9 +551,9 @@ def save_notedata(chart):
553551
while True:
554552
line = next(lines, None)
555553
# Simfile corrupt, lame.
556-
if(line is None):
554+
if line is None:
557555
print("chart ended early")
558-
break;
556+
break
559557
notedata += line
560558
notedata += '\n'
561559
if ';' in line:

web/templates/components/search-bar.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<option {% if "pack" in request.path %}selected{% endif %} value="pack">Pack Name</option>
99
<option {% if "credit" in request.path %}selected{% endif %} value="credit">Chart Author</option>
1010
</select>
11-
<input type="text" id="search" name="search" class="form-control" placeholder="">
11+
<input type="text" id="search" name="search" class="form-control" {% if search_query %} value="{{ search_query }}" {% endif %} placeholder="">
1212
<button type="submit" name="submit" class="btn btn-primary">Search</button>
1313
</div>
1414
</form>
@@ -26,6 +26,12 @@
2626
<div><label><input type="checkbox" class="filter-checkbox" value="smx"> SMX</label></div>
2727
<div><label><input type="checkbox" class="filter-checkbox" value="techno"> Techno</label></div>
2828
</div>
29+
<div>
30+
<label>Filter by Style:</label>
31+
<div><label><input type="checkbox" class="filter-checkbox" value="single"> Singles</label></div>
32+
<div><label><input type="checkbox" class="filter-checkbox" value="double"> Doubles</label></div>
33+
<div><label><input type="checkbox" class="filter-checkbox" value="solo"> Solo</label></div>
34+
</div>
2935
</div>
3036
</div>
3137
</div>

web/templates/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<tbody>
2626
{% for pack in packs %}
2727
<tr>
28-
<td><img loading="lazy" class="img-fluid rounded" style="max-width:200px;" src="/media/images/packs/{% if pack.banner %}{{ pack.banner }}{% else %}nobanner.png{% endif %}"></td>
28+
<td><img loading="lazy" class="img-fluid rounded" style="max-height:50px;" src="/media/images/packs/{% if pack.banner %}{{ pack.banner }}{% else %}nobanner.png{% endif %}"></td>
2929
<td class="small"><a href="/pack/{{ pack.id }}">{{ pack.name|slice:":64" }}{% if pack.name|length > 64 %}...{% endif %}</a></td>
3030
<td data-sort="{{ pack.size }}" class="small">{{ pack.size|filesizeformat }}</td>
3131
<td class="small">{{ pack.song_count }}</td>

web/templates/search.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888

8989
var table = $('#songTable').DataTable();
9090

91+
92+
const match = window.location.hash.match(/page=(\d+)/);
93+
if (match) {
94+
const pageNum = parseInt(match[1], 10) - 1;
95+
table.page(pageNum).draw('page');
96+
}
97+
98+
table.on('page.dt', function () {
99+
const info = table.page.info();
100+
window.location.hash = `page=${info.page + 1}`;
101+
});
102+
91103
// Track active filters
92104
let activeFilters = [];
93105

web/views.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,14 @@ def search(request, search_type=None, search_query=None):
6666
)
6767
.filter(credit__icontains=search_query))
6868
elif "pack" in search_type:
69-
songs = (
70-
Song.objects.prefetch_related(
71-
Prefetch("charts", queryset=charts_qs)
72-
)
73-
.select_related("pack")
74-
.annotate(
75-
min_meter=Min("charts__meter"),
76-
max_meter=Max("charts__meter")
77-
)
78-
.filter(pack__name__icontains=search_query))
69+
packs = list(Pack.objects.filter(name__icontains=search_query)
70+
.annotate(song_count=Count('songs')).order_by("name"))
71+
packs.sort(key=lambda pack: natural_sort_key(pack.name))
72+
return render(request, "main.html", {"packs": packs, "search_query": search_query})
7973
else:
8074
redirect("/")
8175

82-
return render(request, "search.html", {"songs": songs})
83-
84-
def pack_list(request):
85-
"""list all the packs"""
86-
packs = list(Pack.objects.all().order_by("name"))
87-
packs.sort(key=lambda pack: natural_sort_key(pack.name))
88-
return render(request, "packs.html", {"packs": packs})
76+
return render(request, "search.html", {"songs": songs, "search_query": search_query})
8977

9078
def pack_view(request, packid):
9179
"""list all the songs in a pack"""
@@ -271,6 +259,9 @@ def main(request):
271259

272260
return render(request, "main.html", context)
273261

262+
def faq_view(request):
263+
"""faq view"""
264+
return render(request, "faq.html", {})
274265
#@cache_page(timeout=None) # Cache the view for 1 day
275266
def list_all_songs(request):
276267
"""list all songs will query all songs and charts"""

0 commit comments

Comments
 (0)