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

can now view and add questboards in the homepage

parent 834b656a
# Generated by Django 3.1.7 on 2021-04-09 04:55
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Quest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('board_pk', models.IntegerField(default=0)),
('name', models.CharField(default='', max_length=60)),
('description', models.CharField(default='', max_length=300)),
('stars', models.IntegerField(default=0)),
('for_everyone', models.BooleanField(default=False)),
('student1', models.CharField(default='', max_length=60)),
('student2', models.CharField(default='', max_length=60)),
('student3', models.CharField(default='', max_length=60)),
],
),
migrations.CreateModel(
name='Questboard',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.CharField(max_length=300)),
('required_stars', models.IntegerField()),
],
),
]
...@@ -5,4 +5,5 @@ from . import views ...@@ -5,4 +5,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.redirect_to_home), path('', views.redirect_to_home),
path('home/', views.homepage_view), path('home/', views.homepage_view),
] path('home/add_board/', views.add_questboard),
\ No newline at end of file ]
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from board.models import Questboard from board.models import Questboard
form 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, 'homepage/homepage.html') return render(request,
'homepage/homepage.html',
{
'boards' : Questboard.objects.all(),
'add_board_form' : QuestboardForm(),
})
def add_questboard(request):
if request.method == "POST":
filled_form = QuestboardForm(request.POST)
if filled_form.is_valid():
filled_form.save()
return return_previous_page(request)
\ No newline at end of file
...@@ -11,5 +11,40 @@ ...@@ -11,5 +11,40 @@
{% block content %} {% block content %}
nothing so far
{% for board in boards %}
{{ board.name }}<br/>
{{ board.description }}<br/>
{{ board.required_stars }}<br/>
<br/>
{% endfor %}
<button class = "button" onclick = "showAddBoard()">Add a Questboard</button>
<dialog id="add_board">
<form action = "add_board/" method = "post">
{% csrf_token %}
{{ add_board_form }}
<button type="submit">Add</button>
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
{% endblock %}
{% block scripts %}
<script>
AddBoard = document.getElementById("add_board");
function closeAllDialogBoxes(){
AddBoard.close();
}
function showAddBoard(){
closeAllDialogBoxes();
AddBoard.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