Skip to content

Commit

Permalink
move a common function to common class
Browse files Browse the repository at this point in the history
  • Loading branch information
maggi373 committed Sep 5, 2024
1 parent 26ac2ec commit e1326e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
20 changes: 10 additions & 10 deletions asite.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,19 @@ def modpack(id):
Build.new(id, request.form["version"], request.form["mcversion"], publish, private, min_java, request.form["memory"], clonebuild)
return redirect(url_for("asite.modpack", id=id))
if "recommended_submit" in request.form:
Build.update_checkbox(id, request.form["modid"], "recommended", "modpacks")
common.update_checkbox(id, request.form["modid"], "recommended", "modpacks")
return redirect(url_for("asite.modpack", id=id))
if "latest_submit" in request.form:
Build.update_checkbox(id, request.form["modid"], "latest", "modpacks")
common.update_checkbox(id, request.form["modid"], "latest", "modpacks")
return redirect(url_for("asite.modpack", id=id))
if "is_published_submit" in request.form:
Build.update_checkbox(request.form["modid"], request.form["check"], "is_published", "builds")
common.update_checkbox(request.form["modid"], request.form["check"], "is_published", "builds")
return redirect(url_for("asite.modpack", id=id))
if "private_submit" in request.form:
Build.update_checkbox(request.form["modid"], request.form["check"], 'private', 'builds')
common.update_checkbox(request.form["modid"], request.form["check"], 'private', 'builds')
return redirect(url_for("asite.modpack", id=id))
if "marked_submit" in request.form:
Build.update_checkbox_marked(request.form["modid"], request.form["check"])
common.update_checkbox_marked(request.form["modid"], request.form["check"])
return redirect(url_for("asite.modpack", id=id))
if "changelog_submit" in request.form:
oldversion = request.form["changelog_oldver"]
Expand Down Expand Up @@ -604,15 +604,15 @@ def modpacklibrary_post():
if User_modpack.get_user_modpackpermission(session["token"], Build.get_modpackid_by_id(request.form["modid"])) == False:
return redirect(request.referrer)
if "hidden_submit" in request.form:
Modpack.update_checkbox(request.form["modid"], request.form["check"], "hidden", "modpacks")
common.update_checkbox(request.form["modid"], request.form["check"], "hidden", "modpacks")
if "private_submit" in request.form:
Modpack.update_checkbox(request.form["modid"], request.form["check"], "private", "modpacks")
common.update_checkbox(request.form["modid"], request.form["check"], "private", "modpacks")
if "pinned_submit" in request.form:
Modpack.update_checkbox(request.form["modid"], request.form["check"], "pinned", "modpacks")
common.update_checkbox(request.form["modid"], request.form["check"], "pinned", "modpacks")
if "optional_submit" in request.form:
Modpack.update_checkbox(request.form["modid"], request.form["check"], "enable_optionals", "modpacks")
common.update_checkbox(request.form["modid"], request.form["check"], "enable_optionals", "modpacks")
if "server_submit" in request.form:
Modpack.update_checkbox(request.form["modid"], request.form["check"], "enable_server", "modpacks")
common.update_checkbox(request.form["modid"], request.form["check"], "enable_server", "modpacks")

return redirect(url_for('asite.modpacklibrary'))

Expand Down
8 changes: 0 additions & 8 deletions models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ def update(id, version, minecraft, is_published, private, min_java, min_memory):
conn.commit()
return None

@staticmethod
def update_checkbox(id, value, column, table):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("UPDATE {} SET {} = %s WHERE id = %s".format(table, column), (value, id))
conn.commit()
return None

@staticmethod
def update_checkbox_marked(id, value):
conn = Database.get_connection()
Expand Down
7 changes: 0 additions & 7 deletions models/modpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ def delete_modpack(id):
cur.execute("DELETE FROM modpacks WHERE id=%s", (id,))
conn.commit()

@staticmethod
def update_checkbox(cls, where_id, value, column, table):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("UPDATE {} SET {} = %s WHERE id = %s".format(table, column), (value, where_id))
conn.commit()

@classmethod
def get_by_id(cls, id):
conn = Database.get_connection()
Expand Down

0 comments on commit e1326e9

Please sign in to comment.