fix: Fix some project pages using the wrong api request

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-06-10 11:52:38 -04:00
parent 446132c6fb
commit a47d40dcc2
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 25 additions and 11 deletions

36
main.py
View File

@ -84,7 +84,7 @@ def member_header(header):
return [avatar, title, location, signup, instructables, views, comments, followers, bio]
def search(path, args, query='*', teachers=False):
def search(path, head, args, query='*', teachers=False):
sort_by = "publishDate"
if args.get("sort"):
if args.get("sort").lower() == "views":
@ -117,12 +117,12 @@ def search(path, args, query='*', teachers=False):
if not type_ == '':
category = "+%26%26+" + category
channel = f"{'channel' if not teachers else 'teachers'}%3A%20" + split_path[2] \
if len(split_path) > 2 and \
split_path[2] != '' and \
split_path[2] != 'projects' and \
not split_path[2].startswith("?x") \
else ''
channel = f"{'channel' if not teachers else 'teachers'}%3A%20" + quote(head) #\
# if len(split_path) > 2 and \
# split_path[2] != '' and \
# split_path[2] != 'projects' and \
# not split_path[2].startswith("?x") \
# else ''
if not type_ == '' or not category == '':
channel = "+%26%26+" + channel
@ -207,10 +207,10 @@ def project_list(path, head, args=None, realpath=None, teachers=False):
if data.status_code != 200:
return Response(render_template(str(data.status_code) + ".html"), status=data.status_code)
head = f"{head + ' ' if head != '' else ''}Projects"
header = f"{head + ' ' if head != '' else ''}Projects"
soup = BeautifulSoup(data.text, "html.parser")
searched = search(path, args, teachers=teachers)
searched = search(path, head, args, teachers=teachers)
if type(searched) == Response:
return searched
@ -219,7 +219,7 @@ def project_list(path, head, args=None, realpath=None, teachers=False):
page = searched[1]
pages = searched[2]
return render_template("projects.html", data=[head, ibles, realpath, page, pages], sub=re.sub)
return render_template("projects.html", data=[header, ibles, realpath, page, pages], sub=re.sub)
@ -364,9 +364,23 @@ def route_contests():
return render_template("contests.html", data=[contest_count, contests, closed])
def get_channel_name(channel):
if channel == "usb" or channel == "cnc":
return channel.upper()
elif channel == "leds":
return "LEDs"
elif channel == "bbq-and-grilling":
return "BBQ & Grilling"
elif channel == "lego-and-knex":
return "LEGO & K&quot;NEX"
elif channel == "pranks-tricks-and-humor":
return "Pranks, Tricks, & Humor"
else:
return channel.replace("-", " ").replace("and", "&amp;").title()
@app.route('/<category>/<channel>/projects/')
def route_channel_projects(category, channel):
return project_list(f"/{category}/{channel}/projects/?x", channel.title(), request.args, request.full_path)
return project_list(f"/{category}/{channel}/projects/?x", get_channel_name(channel), request.args, request.full_path)
@app.route('/<category>/projects/')
def route_category_projects(category):