Commit 2c1b0b52 authored by Aedin Hunter A. Clay's avatar Aedin Hunter A. Clay

can now view questboard as student and sign up to a quest.

parent 58e77fd6
...@@ -16,5 +16,6 @@ class QuestForm(forms.ModelForm): ...@@ -16,5 +16,6 @@ class QuestForm(forms.ModelForm):
'student3' : forms.HiddenInput(), 'student3' : forms.HiddenInput(),
} }
class AddStudentName(forms.Form): class StudentSignupForm(forms.Form):
name = forms.CharField(max_length = 60) quest_id = forms.IntegerField(widget = forms.HiddenInput())
\ No newline at end of file name = forms.CharField(max_length = 60)
...@@ -5,4 +5,6 @@ from . import views ...@@ -5,4 +5,6 @@ from . import views
urlpatterns = [ urlpatterns = [
path('edit/<int:pk>', views.edit_board_view), path('edit/<int:pk>', views.edit_board_view),
path('edit/add_quest/', views.add_quest), path('edit/add_quest/', views.add_quest),
path('view/<int:pk>', views.view_board_view),
path('view/student_signup/', views.student_signup),
] ]
\ No newline at end of file
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from .models import Quest, Questboard from .models import Quest, Questboard
from .forms import QuestForm, QuestboardForm from .forms import QuestForm, QuestboardForm, StudentSignupForm
def edit_board_view(request, pk): def edit_board_view(request, pk):
return render( return render(
...@@ -12,10 +13,36 @@ def edit_board_view(request, pk): ...@@ -12,10 +13,36 @@ def edit_board_view(request, pk):
'add_quest_form' : QuestForm(initial={'board_pk' : pk}), 'add_quest_form' : QuestForm(initial={'board_pk' : pk}),
} }
) )
def view_board_view(request, pk):
return render(
request,
'board/view_board.html',
{
'questboard' : Questboard.objects.get(pk=pk),
'quests' : Quest.objects.filter(board_pk=pk),
'signup_form' : StudentSignupForm(auto_id = 'signup_%s')
}
)
def add_quest(request): def add_quest(request):
if request.method == "POST": if request.method == "POST":
filled_form = QuestForm(request.POST) filled_form = QuestForm(request.POST)
if filled_form.is_valid(): if filled_form.is_valid():
filled_form.save() filled_form.save()
return redirect(request.META.get('HTTP_REFERER', '/')) return redirect(request.META.get('HTTP_REFERER', '/'))
\ No newline at end of file
def student_signup(request):
if request.method == "POST":
filled_form = StudentSignupForm(request.POST)
if filled_form.is_valid():
quest_to_edit = Quest.objects.get(pk=filled_form.cleaned_data['quest_id'])
student_name = filled_form.cleaned_data['name']
if quest_to_edit.student1 == '':
quest_to_edit.student1 = student_name
elif quest_to_edit.student2 == '':
quest_to_edit.student2 = student_name
elif quest_to_edit.student3 == '':
quest_to_edit.student3 = student_name
quest_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/')) #PLEASE CHANGE THESE TO FUNCTION FOR CLARITY!!!
...@@ -18,4 +18,4 @@ def add_questboard(request): ...@@ -18,4 +18,4 @@ def add_questboard(request):
filled_form = QuestboardForm(request.POST) filled_form = QuestboardForm(request.POST)
if filled_form.is_valid(): if filled_form.is_valid():
filled_form.save() filled_form.save()
return redirect(request.META.get('HTTP_REFERER', '/')) return redirect(request.META.get('HTTP_REFERER', '/'))
\ No newline at end of file \ No newline at end of file
...@@ -25,8 +25,6 @@ Required Stars: {{questboard.required_stars}}<br/> ...@@ -25,8 +25,6 @@ Required Stars: {{questboard.required_stars}}<br/>
<p class = "questbox_stars">Stars : {{quest.stars}}</p> <p class = "questbox_stars">Stars : {{quest.stars}}</p>
<div class = "questbox_students"> <div class = "questbox_students">
<!-- If the quest has three students -->
{% if quest.for_everyone is True %} {% if quest.for_everyone is True %}
<b> for everyone </b> <b> for everyone </b>
{% else %} {% else %}
...@@ -50,3 +48,5 @@ Required Stars: {{questboard.required_stars}}<br/> ...@@ -50,3 +48,5 @@ Required Stars: {{questboard.required_stars}}<br/>
{% endblock %} {% endblock %}
{% extends 'board/board.html' %}
{% load static %}
{% block questbox_actions %}
{% if quest.for_everyone is False %}
<!-- If the quest does not yet have three students -->
{% if quest.student1 == '' or quest.student2 == '' or quest.student3 == '' %}
<button id="show_quest_signup" onclick = "showQuestSignup({{ quest.pk }})">Sign Up for Quest</button>
{% endif %}
{% endif %}
{% endblock %}
{% block extra_content %}
<dialog id = "quest_signup">
Please enter your name to sign up for this quest.
<form action = "/questboard/view/student_signup/" method = "post">
{% csrf_token %}
{{ signup_form }}
<button type="submit">Submit</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
{% endblock %}
{% block extra_scripts %}
<script>
QuestSignup = document.getElementById('quest_signup');
function closeAllDialogBoxes(){
QuestSignup.close();
}
function showQuestSignup(pk){
closeAllDialogBoxes();
QuestSignup.show();
selectQuestToSignupFor(pk);
}
function selectQuestToSignupFor(pk){
document.getElementById('signup_quest_id').setAttribute("value", pk)
}
</script>
{% endblock %}
\ No newline at end of file
...@@ -23,7 +23,10 @@ ...@@ -23,7 +23,10 @@
<td>{{ board.name }}</td> <td>{{ board.name }}</td>
<td> <td>
<a href = "/questboard/edit/{{ board.pk }}"> <a href = "/questboard/edit/{{ board.pk }}">
<button class = "button">Edit Questboard </button> <button class = "button">Edit Questboard as Teacher</button>
</a>
<a href = "/questboard/view/{{ board.pk }}">
<button class = "button">View Questboard as Student</button>
</a> </a>
</td> </td>
</tr> </tr>
......
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