Skip to content

Commit

Permalink
feat: Add remove field button to credits management
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Jun 30, 2024
1 parent 7caf539 commit 1e20d0b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions templates/credits_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{ form.role_and_name_list }}

<button type="button" class="button is-info" id="addNewField">Add Field</button>
<button type="button" class="button is-danger" id="removeField">Remove Field</button>
</p>
<br>
<p>{{ form.submit(class_="button is-success") }}</p>
Expand Down Expand Up @@ -55,5 +56,14 @@

document.addEventListener("DOMContentLoaded", createStaffPair);
document.getElementById("addNewField").addEventListener("click", createStaffPair);
document.getElementById("removeField").addEventListener("click", function(){
// Remove last field pair
for (var i = 0; i < 7; i++) {
document.getElementById("role_and_name_list").removeChild(document.getElementById("role_and_name_list").lastChild);
}

// Finally decrement the fieldNum
fieldNum--;
})
</script>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/credits_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{{ form.hidden_tag() }}
{{ form.role_and_name_list }}
<button type="button" class="button is-info" id="addNewField">Add Field</button>
<button type="button" class="button is-danger" id="removeField">Remove Field</button>
</p>
<br>
<p>{{ form.submit(class_="button is-success") }}</p>
Expand Down Expand Up @@ -91,5 +92,14 @@
{% endfor %}
});
document.getElementById("addNewField").addEventListener("click", createStaffPair);
document.getElementById("removeField").addEventListener("click", function(){
// Remove last field pair
for (var i = 0; i < 7; i++) {
document.getElementById("role_and_name_list").removeChild(document.getElementById("role_and_name_list").lastChild);
}

// Finally decrement the fieldNum
fieldNum--;
})
</script>
{% endblock %}
11 changes: 10 additions & 1 deletion theunderground/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ def edit_credits(movie_id):

queried_credits = []
if form.validate_on_submit():
received_length = len(form.role_and_name_list.data) / 2
original_length = MovieCredits.query.filter_by(movie_id=movie_id).count()
if received_length < original_length:
# If the edited credits is less than what is in the database, we must delete the removed.
MovieCredits.query.filter_by(movie_id=movie_id).where(
MovieCredits.order > received_length
).delete()

# We can handle any edits now.
order = 1
for i in range(0, len(form.role_and_name_list.data), 2):
for i in range(0, int(received_length) * 2, 2):
# Query the row
data = (
MovieCredits.query.filter_by(movie_id=movie_id)
Expand Down

0 comments on commit 1e20d0b

Please sign in to comment.