Commit 0e1aaaa3 authored by Aedin Hunter A. Clay's avatar Aedin Hunter A. Clay

can now edit questboard name, description, and required stars

parent 2c1b0b52
...@@ -9,8 +9,8 @@ class QuestboardForm(forms.ModelForm): ...@@ -9,8 +9,8 @@ class QuestboardForm(forms.ModelForm):
class QuestForm(forms.ModelForm): class QuestForm(forms.ModelForm):
class Meta: class Meta:
model = Quest model = Quest
fields = ['board_pk', 'name', 'description', 'stars', 'for_everyone','student1','student2', 'student3'] fields = ['board_id', 'name', 'description', 'stars', 'for_everyone','student1','student2', 'student3']
widgets = {'board_pk' : forms.HiddenInput(), widgets = {'board_id' : forms.HiddenInput(),
'student1' : forms.HiddenInput(), 'student1' : forms.HiddenInput(),
'student2' : forms.HiddenInput(), 'student2' : forms.HiddenInput(),
'student3' : forms.HiddenInput(), 'student3' : forms.HiddenInput(),
...@@ -19,3 +19,15 @@ class QuestForm(forms.ModelForm): ...@@ -19,3 +19,15 @@ class QuestForm(forms.ModelForm):
class StudentSignupForm(forms.Form): 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 EditBoardNameForm(forms.Form):
board_id = forms.IntegerField(widget = forms.HiddenInput())
name = forms.CharField(max_length = 50)
class EditBoardDescForm(forms.Form):
board_id = forms.IntegerField(widget = forms.HiddenInput())
description = forms.CharField(max_length = 300)
class EditBoardStarsForm(forms.Form):
board_id = forms.IntegerField(widget = forms.HiddenInput())
required_stars = forms.IntegerField()
\ No newline at end of file
# Generated by Django 3.1.7 on 2021-04-09 10:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('board', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='quest',
old_name='board_pk',
new_name='board_id',
),
migrations.AlterField(
model_name='quest',
name='student1',
field=models.CharField(blank=True, default='', max_length=60),
),
migrations.AlterField(
model_name='quest',
name='student2',
field=models.CharField(blank=True, default='', max_length=60),
),
migrations.AlterField(
model_name='quest',
name='student3',
field=models.CharField(blank=True, default='', max_length=60),
),
]
...@@ -6,7 +6,7 @@ class Questboard(models.Model): ...@@ -6,7 +6,7 @@ class Questboard(models.Model):
required_stars = models.IntegerField() required_stars = models.IntegerField()
class Quest(models.Model): class Quest(models.Model):
board_pk = models.IntegerField(default = 0) board_id = models.IntegerField(default = 0)
name = models.CharField(max_length = 60, default = '') name = models.CharField(max_length = 60, default = '')
description = models.CharField(max_length = 300, default = '') description = models.CharField(max_length = 300, default = '')
stars = models.IntegerField(default = 0) stars = models.IntegerField(default = 0)
......
...@@ -4,6 +4,9 @@ from . import views ...@@ -4,6 +4,9 @@ from . import views
urlpatterns = [ urlpatterns = [
path('edit/<int:pk>', views.edit_board_view), path('edit/<int:pk>', views.edit_board_view),
path('edit/edit_board_name/', views.edit_board_name),
path('edit/edit_board_desc/', views.edit_board_desc),
path('edit/edit_board_stars/', views.edit_board_stars),
path('edit/add_quest/', views.add_quest), path('edit/add_quest/', views.add_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),
......
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, StudentSignupForm from .forms import *
def edit_board_view(request, pk): def edit_board_view(request, pk):
...@@ -9,8 +9,11 @@ def edit_board_view(request, pk): ...@@ -9,8 +9,11 @@ def edit_board_view(request, pk):
'board/edit_board.html', 'board/edit_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),
'add_quest_form' : QuestForm(initial={'board_pk' : pk}), 'edit_board_name_form' : EditBoardNameForm(initial={'board_id' : pk}),
'edit_board_desc_form' : EditBoardDescForm(initial={'board_id' : pk}),
'edit_board_stars_form' : EditBoardStarsForm(initial={'board_id' : pk}),
'add_quest_form' : QuestForm(initial={'board_id' : pk}),
} }
) )
def view_board_view(request, pk): def view_board_view(request, pk):
...@@ -46,3 +49,36 @@ def student_signup(request): ...@@ -46,3 +49,36 @@ 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_board_name(request):
if request.method == "POST":
filled_form = EditBoardNameForm(request.POST)
if filled_form.is_valid():
board_to_edit = Questboard.objects.get(pk=filled_form.cleaned_data['board_id'])
board_name = filled_form.cleaned_data['name']
board_to_edit.name = board_name
board_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
def edit_board_desc(request):
if request.method == "POST":
filled_form = EditBoardDescForm(request.POST)
if filled_form.is_valid():
board_to_edit = Questboard.objects.get(pk=filled_form.cleaned_data['board_id'])
board_desc = filled_form.cleaned_data['description']
board_to_edit.description = board_desc
board_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
def edit_board_stars(request):
if request.method == "POST":
filled_form = EditBoardStarsForm(request.POST)
if filled_form.is_valid():
board_to_edit = Questboard.objects.get(pk=filled_form.cleaned_data['board_id'])
board_stars = filled_form.cleaned_data['required_stars']
board_to_edit.required_stars = board_stars
board_to_edit.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
\ No newline at end of file
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</head> </head>
<body> <body>
<p class = "website_header">QUESTBOARD</p> <a href = "/home/"><p class = "website_header">QUESTBOARD</p></a>
<div id="contents"> <div id="contents">
<p class = "page_header">{% block header %}{% endblock %}</p> <p class = "page_header">{% block header %}{% endblock %}</p>
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
Required Stars: {{questboard.required_stars}}<br/> Required Stars: {{questboard.required_stars}}<br/>
{{questboard.description}}<br/> {{questboard.description}}<br/>
{% block extra_content %}{% endblock %}
{% if quests %} {% if quests %}
Quests in the Questboard: Quests in the Questboard:
<div id = "quest_display"> <div id = "quest_display">
...@@ -43,7 +45,7 @@ Required Stars: {{questboard.required_stars}}<br/> ...@@ -43,7 +45,7 @@ Required Stars: {{questboard.required_stars}}<br/>
</div> </div>
{% endif %} {% endif %}
{% block extra_content %}{% endblock %}
{% block extra_scripts %}{% endblock %} {% block extra_scripts %}{% endblock %}
{% endblock %} {% endblock %}
......
...@@ -2,7 +2,37 @@ ...@@ -2,7 +2,37 @@
{% load static %} {% load static %}
{% block extra_content %} {% block extra_content %}
<button onclick="showEditBoardName()">Edit Questboard Name</button>
<button onclick="showEditBoardDesc()">Edit Questboard Description</button>
<button onclick="showEditBoardStars()">Edit Questboard Required Stars</button>
<button onclick="showAddQuest()">Add Quest</button> <button onclick="showAddQuest()">Add Quest</button>
<br/>
<dialog id="edit_board_name">
<form action = "/questboard/edit/edit_board_name/" method = "post">
{% csrf_token %}
{{ edit_board_name_form }}
<button type="submit">Edit</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<dialog id="edit_board_desc">
<form action = "/questboard/edit/edit_board_desc/" method = "post">
{% csrf_token %}
{{ edit_board_desc_form }}
<button type="submit">Edit</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<dialog id="edit_board_stars">
<form action = "/questboard/edit/edit_board_stars/" method = "post">
{% csrf_token %}
{{ edit_board_stars_form }}
<button type="submit">Edit</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<dialog id="add_quest"> <dialog id="add_quest">
<form action = "/questboard/edit/add_quest/" method = "post"> <form action = "/questboard/edit/add_quest/" method = "post">
...@@ -16,12 +46,18 @@ ...@@ -16,12 +46,18 @@
{% block extra_scripts %} {% block extra_scripts %}
<script> <script>
AddQuest = document.getElementById('add_quest'); AddQuest = document.getElementById('add_quest');
EditBoardName = document.getElementById('edit_board_name');
EditBoardDesc = document.getElementById('edit_board_desc');
EditBoardStars = document.getElementById('edit_board_stars');
function closeAllDialogBoxes(){ function closeAllDialogBoxes(){
AddQuest.close(); AddQuest.close();
EditBoardName.close();
EditBoardDesc.close();
EditBoardStars.close();
} }
function showAddQuest(){ function showAddQuest(){
...@@ -29,6 +65,21 @@ function showAddQuest(){ ...@@ -29,6 +65,21 @@ function showAddQuest(){
AddQuest.show(); AddQuest.show();
} }
</script> function showEditBoardName(){
closeAllDialogBoxes();
EditBoardName.show();
}
function showEditBoardDesc(){
closeAllDialogBoxes();
EditBoardDesc.show();
}
function showEditBoardStars(){
closeAllDialogBoxes();
EditBoardStars.show();
}
</script>
{% endblock %} {% endblock %}
\ No newline at end of file
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