Commit 22d2d95d authored by Aedin Hunter A. Clay's avatar Aedin Hunter A. Clay

can now view the edit questboard page, and add quests to questboard

parent 0de6c440
......@@ -9,8 +9,9 @@ class QuestboardForm(forms.ModelForm):
class QuestForm(forms.ModelForm):
class Meta:
model = Quest
fields = ['name', 'description', 'stars', 'for_everyone', 'board_pk' ,'student1','student2', 'student3']
fields = ['board_pk', 'name', 'description', 'stars', 'for_everyone','student1','student2', 'student3']
widgets = {'board_pk' : forms.HiddenInput(),
'student1' : forms.HiddenInput(),
'student2' : forms.HiddenInput(),
'student3' : forms.HiddenInput()}
\ No newline at end of file
'student3' : forms.HiddenInput(),
}
\ No newline at end of file
......@@ -11,9 +11,9 @@ class Quest(models.Model):
description = models.CharField(max_length = 300, default = '')
stars = models.IntegerField(default = 0)
for_everyone = models.BooleanField(default = False)
student1 = models.CharField(max_length = 60, default = '')
student2 = models.CharField(max_length = 60, default = '')
student3 = models.CharField(max_length = 60, default = '')
student1 = models.CharField(max_length = 60, default = '', blank = True)
student2 = models.CharField(max_length = 60, default = '', blank = True)
student3 = models.CharField(max_length = 60, default = '', blank = True)
def is_for_everyone(self):
if self.students is not None:
......
......@@ -3,4 +3,6 @@ from django.urls import path
from . import views
urlpatterns = [
]
path('edit/<int:pk>', views.edit_board_view),
path('edit/add_quest/', views.add_quest),
]
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import redirect, render
from .models import Quest, Questboard
from .forms import QuestForm, QuestboardForm
def edit_board_view(request, pk):
return render(
request,
'board/edit_board.html',
{
'questboard' : Questboard.objects.get(pk=pk),
'quests' : Quest.objects.filter(board_pk=pk),
'add_quest_form' : QuestForm(initial={'board_pk' : pk}),
}
)
def add_quest(request):
if request.method == "POST":
filled_form = QuestForm(request.POST)
if filled_form.is_valid():
filled_form.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
\ No newline at end of file
......@@ -3,10 +3,7 @@ from board.models import Questboard
from board.forms import QuestboardForm
def redirect_to_home(request):
return redirect('home/')
def return_previous_page(request):
return redirect(request.META.get('HTTP_REFERER', '/'))
return redirect('/home/')
def homepage_view(request):
return render(request,
......@@ -21,4 +18,4 @@ def add_questboard(request):
filled_form = QuestboardForm(request.POST)
if filled_form.is_valid():
filled_form.save()
return return_previous_page(request)
\ No newline at end of file
return redirect(request.META.get('HTTP_REFERER', '/'))
\ No newline at end of file
......@@ -5,4 +5,4 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('', include('homepage.urls')),
path('questboard/', include('board.urls')),
]
]
\ No newline at end of file
......@@ -9,22 +9,12 @@
{% block header %}{{questboard.name}}{% endblock %}
{% block content %}
<button onclick="showAddQuest()">Add Quest</button>
<dialog id="add_quest"><!-- PLEASE PREVENT NEGATIVE NUMBERS!!!-->
<form action = "add_quest" method = "post">
{% csrf_token %}
{{ add_quest_form }}
<button type="submit">Add</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
Required Stars: {{questboard.required_stars}}<br/>
{{questboard.description}}<br/>
{% if quests %}
Quests in the Questboard:
<ul>
{% for quest in quests %}
......@@ -33,6 +23,18 @@
<ul>
{% endif %}
<button onclick="showAddQuest()">Add Quest</button>
<dialog id="add_quest">
<form action = "/questboard/edit/add_quest/" method = "post">
{% csrf_token %}
{{ add_quest_form }}
<button type="submit">Add</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
{% endblock %}
{% block scripts %}
......
......@@ -12,17 +12,29 @@
{% block content %}
{% for board in boards %}
{{ board.name }}<br/>
{{ board.description }}<br/>
{{ board.required_stars }}<br/>
<br/>
{% endfor %}
<!-- LIST OF QUESTBOARDS -->
<table class = "board_table">
<tr>
<th>Questboard Name</th>
<th>Actions</th>
</tr>
{% for board in boards %}
<tr>
<td>{{ board.name }}</td>
<td>
<a href = "/questboard/edit/{{ board.pk }}">
<button class = "button">Edit Questboard </button>
</a>
</td>
</tr>
{% endfor %}
</table>
<button class = "button" onclick = "showAddBoard()">Add a Questboard</button>
<dialog id="add_board">
<dialog id="add_board"><!-- PLEASE PREVENT NEGATIVE NUMBERS!!!-->
<form action = "add_board/" method = "post">
{% csrf_token %}
{{ add_board_form }}
......
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