Commit 5aaf8a46 authored by Alessandro Olivar's avatar Alessandro Olivar

Create and edit forms made for both quests and questboards. Homepage buttons...

Create and edit forms made for both quests and questboards. Homepage buttons direct to appropriate questboards
parent e66964a4
Pipeline #2123 canceled with stages
No preview for this file type
from django.forms import ModelForm
from .models import *
class QBoardForm(ModelForm):
class Meta:
model = QBoard
fields = '__all__'
class QuestForm(ModelForm):
class Meta:
model = Quest
fields = '__all__'
\ No newline at end of file
......@@ -6,11 +6,11 @@
<div class="col-md-5">
<h5>QUESTBOARDS</h5>
<hr>
<a class="btn btn-primary btn-sm btn-block" href="">New Questboard</a>
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_qboard' %}">New Questboard</a>
<hr>
{% for i in qboards %}
<div class="card card-body">
<a class="btn btn-primary btn-sm btn-block" href="">Go</a>
<a class="btn btn-primary btn-sm btn-block" href="{% url 'questboard' i.id %}">Go</a>
<table class="table table-sm">
<tr>
<th class="text-center">{{i.name}}</th>
......
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Homepage</a>
<a class="nav-link" href="/">Homepage</a>
</li>
</ul>
</div>
......
{% extends 'qBoard/main.html' %}
{% block content %}
<form action = "" method = "POST">
{% csrf_token %}
{{form}}
<input type = "submit" name = "Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'qBoard/main.html' %}
{% block content %}
<form action = "" method = "POST">
{% csrf_token %}
{{form}}
<input type = "submit" name = "Submit">
</form>
{% endblock %}
\ No newline at end of file
......@@ -5,14 +5,25 @@
<div class="col-md-5">
<h1>{{qboard.name}}</h1>
<hr>
<a class="btn btn-primary btn-sm btn-block" href="">New Quest</a>
<p>
"Each group should collect {{qboard.stars}} stars to fulfill the requirements for {{qboard.name}}"
</p>
<hr>
<p>
{{qboard.desc}}
</p>
<hr>
<a class="btn btn-primary btn-sm btn-block" href="{% url 'update_qboard' qboard.id %}">Edit QuestBoard</a>
<!--<a class="btn btn-primary btn-sm btn-block" href="">Delete QuestBoard</a>-->
<hr>
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_quest' qboard.id %}">New Quest</a>
<hr>
{% for quest in quests %}
<div class="card card-body">
<table>
<tr>
<td><a class="btn btn-primary btn-sm btn-block" href="">Edit Quest</a></td>
<td><a class="btn btn-primary btn-sm btn-block" href="">Delete Quest</a></td>
<td><a class="btn btn-primary btn-sm btn-block" href="{% url 'update_quest' qboard.id %}">Edit Quest</a></td>
<!--<td><a class="btn btn-primary btn-sm btn-block" href="">Delete Quest</a></td>-->
</tr>
</table>
<table class="table table-sm">
......
......@@ -2,6 +2,11 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.home),
path('questboard/<str:pk_test>/', views.quests),
path('', views.home, name = "home"),
path('questboard/<str:pk_test>/', views.quests, name = "questboard"),
path('create_qboard/', views.createQBoard, name = "create_qboard"),
path('update_qboard/<str:pk>/', views.updateQBoard, name = "update_qboard"),
path('create_quest/<str:pk>/', views.createQuest, name = "create_quest"),
path('update_quest/<str:pk>/', views.updateQuest, name = "update_quest"),
]
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
# Create your views here.
from .models import *
from .forms import *
def home(request):
qboards = QBoard.objects.all()
......@@ -13,4 +14,48 @@ def quests(request, pk_test):
quests = qboard.quest_set.all()
context = {'qboard' : qboard, 'quests' : quests}
return render(request, 'qBoard/quests.html', context)
\ No newline at end of file
return render(request, 'qBoard/quests.html', context)
def createQBoard(request):
form = QBoardForm()
if request.method == 'POST':
form = QBoardForm(request.POST)
if form.is_valid():
form.save()
return redirect('/')
context = {'form':form}
return render(request, 'qBoard/qboard_form.html', context)
def updateQBoard(request, pk):
qboard = QBoard.objects.get(id = pk)
form = QBoardForm(instance = qboard)
if request.method == 'POST':
form = QBoardForm(request.POST, instance = qboard)
if form.is_valid():
form.save()
return redirect('/')
context = {'form':form}
return render(request, 'qBoard/qboard_form.html', context)
def createQuest(request, pk):
questboard = QBoard.objects.get(id = pk)
form = QuestForm(initial = {'qboard':questboard})
if request.method == 'POST':
form = QuestForm(request.POST)
if form.is_valid():
form.save()
return redirect('/')
context = {'form':form}
return render(request, 'qBoard/quest_form.html', context)
def updateQuest(request, pk):
questboard = QBoard.objects.get(id = pk)
quest = Quest.objects.get(id = pk)
form = QuestForm(initial = {'qboard':questboard}, instance = quest)
if request.method == 'POST':
form = QuestForm(request.POST, instance = quest)
if form.is_valid():
form.save()
return redirect('/')
context = {'form':form}
return render(request, 'qBoard/quest_form.html', context)
\ 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