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