Commit be289f52 authored by Aedin Hunter A. Clay's avatar Aedin Hunter A. Clay

can now edit and delete quests

parent 0e1aaaa3
...@@ -20,6 +20,12 @@ class StudentSignupForm(forms.Form): ...@@ -20,6 +20,12 @@ class StudentSignupForm(forms.Form):
quest_id = forms.IntegerField(widget = forms.HiddenInput()) quest_id = forms.IntegerField(widget = forms.HiddenInput())
name = forms.CharField(max_length = 60) name = forms.CharField(max_length = 60)
class EditQuestForm(QuestForm):
quest_id = forms.IntegerField(widget = forms.HiddenInput())
class DeleteQuestForm(forms.Form):
quest_id = forms.IntegerField(widget = forms.HiddenInput())
class EditBoardNameForm(forms.Form): class EditBoardNameForm(forms.Form):
board_id = forms.IntegerField(widget = forms.HiddenInput()) board_id = forms.IntegerField(widget = forms.HiddenInput())
name = forms.CharField(max_length = 50) name = forms.CharField(max_length = 50)
...@@ -30,4 +36,6 @@ class EditBoardDescForm(forms.Form): ...@@ -30,4 +36,6 @@ class EditBoardDescForm(forms.Form):
class EditBoardStarsForm(forms.Form): class EditBoardStarsForm(forms.Form):
board_id = forms.IntegerField(widget = forms.HiddenInput()) board_id = forms.IntegerField(widget = forms.HiddenInput())
required_stars = forms.IntegerField() required_stars = forms.IntegerField()
\ No newline at end of file
...@@ -8,6 +8,8 @@ urlpatterns = [ ...@@ -8,6 +8,8 @@ urlpatterns = [
path('edit/edit_board_desc/', views.edit_board_desc), path('edit/edit_board_desc/', views.edit_board_desc),
path('edit/edit_board_stars/', views.edit_board_stars), path('edit/edit_board_stars/', views.edit_board_stars),
path('edit/add_quest/', views.add_quest), path('edit/add_quest/', views.add_quest),
path('edit/edit_quest/', views.edit_quest),
path('edit/delete_quest/', views.delete_quest),
path('view/<int:pk>', views.view_board_view), path('view/<int:pk>', views.view_board_view),
path('view/student_signup/', views.student_signup), path('view/student_signup/', views.student_signup),
] ]
\ No newline at end of file
...@@ -14,6 +14,8 @@ def edit_board_view(request, pk): ...@@ -14,6 +14,8 @@ def edit_board_view(request, pk):
'edit_board_desc_form' : EditBoardDescForm(initial={'board_id' : pk}), 'edit_board_desc_form' : EditBoardDescForm(initial={'board_id' : pk}),
'edit_board_stars_form' : EditBoardStarsForm(initial={'board_id' : pk}), 'edit_board_stars_form' : EditBoardStarsForm(initial={'board_id' : pk}),
'add_quest_form' : QuestForm(initial={'board_id' : pk}), 'add_quest_form' : QuestForm(initial={'board_id' : pk}),
'edit_quest_form' : EditQuestForm(auto_id = 'edit_%s'),
'delete_quest_form' : DeleteQuestForm(auto_id = 'delete_%s'),
} }
) )
def view_board_view(request, pk): def view_board_view(request, pk):
...@@ -22,7 +24,7 @@ def view_board_view(request, pk): ...@@ -22,7 +24,7 @@ def view_board_view(request, pk):
'board/view_board.html', 'board/view_board.html',
{ {
'questboard' : Questboard.objects.get(pk=pk), 'questboard' : Questboard.objects.get(pk=pk),
'quests' : Quest.objects.filter(board_pk=pk), 'quests' : Quest.objects.filter(board_id=pk),
'signup_form' : StudentSignupForm(auto_id = 'signup_%s') 'signup_form' : StudentSignupForm(auto_id = 'signup_%s')
} }
) )
...@@ -34,7 +36,7 @@ def add_quest(request): ...@@ -34,7 +36,7 @@ def add_quest(request):
filled_form.save() filled_form.save()
return redirect(request.META.get('HTTP_REFERER', '/')) return redirect(request.META.get('HTTP_REFERER', '/'))
def student_signup(request): def student_signup(request): # PLEASE ADD A "CHECK IF NAME IS THERE ALREADY" FUNCTION TO THE QUEST!
if request.method == "POST": if request.method == "POST":
filled_form = StudentSignupForm(request.POST) filled_form = StudentSignupForm(request.POST)
if filled_form.is_valid(): if filled_form.is_valid():
...@@ -49,6 +51,26 @@ def student_signup(request): ...@@ -49,6 +51,26 @@ def student_signup(request):
quest_to_edit.save() quest_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/')) #PLEASE CHANGE THESE TO FUNCTION FOR CLARITY!!! return redirect(request.META.get('HTTP_REFERER', '/')) #PLEASE CHANGE THESE TO FUNCTION FOR CLARITY!!!
def edit_quest(request):
if request.method == "POST":
filled_form = EditQuestForm(request.POST)
if filled_form.is_valid():
quest_to_edit = Quest.objects.get(pk=filled_form.cleaned_data['quest_id'])
quest_to_edit.name = filled_form.cleaned_data['name']
quest_to_edit.description = filled_form.cleaned_data['description']
quest_to_edit.stars = filled_form.cleaned_data['stars']
quest_to_edit.for_everyone = filled_form.cleaned_data['for_everyone']
quest_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
def delete_quest(request):
if request.method == "POST":
filled_form = DeleteQuestForm(request.POST)
if filled_form.is_valid():
quest_to_delete = Quest.objects.get(pk=filled_form.cleaned_data['quest_id'])
quest_to_delete.delete()
return redirect(request.META.get('HTTP_REFERER', '/'))
def edit_board_name(request): def edit_board_name(request):
if request.method == "POST": if request.method == "POST":
filled_form = EditBoardNameForm(request.POST) filled_form = EditBoardNameForm(request.POST)
...@@ -58,7 +80,7 @@ def edit_board_name(request): ...@@ -58,7 +80,7 @@ def edit_board_name(request):
board_name = filled_form.cleaned_data['name'] board_name = filled_form.cleaned_data['name']
board_to_edit.name = board_name board_to_edit.name = board_name
board_to_edit.save() board_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/')) return redirect(request.META.get('HTTP_REFERER', '/'))
def edit_board_desc(request): def edit_board_desc(request):
if request.method == "POST": if request.method == "POST":
......
...@@ -42,24 +42,64 @@ ...@@ -42,24 +42,64 @@
</form> </form>
<button onclick = "closeAllDialogBoxes()">Cancel</button> <button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog> </dialog>
<dialog id="edit_quest">
<form action = "/questboard/edit/edit_quest/" method = "post">
{% csrf_token %}
{{ edit_quest_form }}
<button type="submit">Edit</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<dialog id="delete_quest">
Are you sure you want to delete this quest?
<form action = "/questboard/edit/delete_quest/" method = "post">
{% csrf_token %}
{{ delete_quest_form }}
<button type="submit">Yes</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
{% endblock %} {% endblock %}
{% block questbox_actions %}
<!-- If no student has signed up yet or the quest is for everyone, then the quest can be edited / deleted -->
{% if quest.student1 == '' and quest.student2 == '' and quest.student3 == '' %}
<button onclick="showEditQuest({{quest.pk}})">Edit Quest</button>
<button onclick="showDeleteQuest({{quest.pk}})">Delete Quest</button>
{% else %}
<p>Cannot Edit Quest: students signed up alsready</p>
{% endif %}
{% endblock %}
{% block extra_scripts %} {% block extra_scripts %}
<script> <script>
AddQuest = document.getElementById('add_quest'); AddQuest = document.getElementById('add_quest');
EditQuest = document.getElementById('edit_quest');
DeleteQuest = document.getElementById('delete_quest');
EditBoardName = document.getElementById('edit_board_name'); EditBoardName = document.getElementById('edit_board_name');
EditBoardDesc = document.getElementById('edit_board_desc'); EditBoardDesc = document.getElementById('edit_board_desc');
EditBoardStars = document.getElementById('edit_board_stars'); EditBoardStars = document.getElementById('edit_board_stars');
function closeAllDialogBoxes(){ function closeAllDialogBoxes(){
AddQuest.close(); AddQuest.close();
EditQuest.close();
DeleteQuest.close();
EditBoardName.close(); EditBoardName.close();
EditBoardDesc.close(); EditBoardDesc.close();
EditBoardStars.close(); EditBoardStars.close();
} }
function selectQuestToEdit(pk){
document.getElementById('edit_quest_id').setAttribute("value", pk)
}
function selectQuestToDelete(pk){
document.getElementById('delete_quest_id').setAttribute("value", pk)
}
function showAddQuest(){ function showAddQuest(){
closeAllDialogBoxes(); closeAllDialogBoxes();
AddQuest.show(); AddQuest.show();
...@@ -78,7 +118,18 @@ function showEditBoardDesc(){ ...@@ -78,7 +118,18 @@ function showEditBoardDesc(){
function showEditBoardStars(){ function showEditBoardStars(){
closeAllDialogBoxes(); closeAllDialogBoxes();
EditBoardStars.show(); EditBoardStars.show();
}
function showEditQuest(pk){
closeAllDialogBoxes();
EditQuest.show();
selectQuestToEdit(pk);
}
function showDeleteQuest(pk){
closeAllDialogBoxes();
DeleteQuest.show();
selectQuestToDelete(pk);
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment