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 @@ ...@@ -6,11 +6,11 @@
<div class="col-md-5"> <div class="col-md-5">
<h5>QUESTBOARDS</h5> <h5>QUESTBOARDS</h5>
<hr> <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> <hr>
{% for i in qboards %} {% for i in qboards %}
<div class="card card-body"> <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"> <table class="table table-sm">
<tr> <tr>
<th class="text-center">{{i.name}}</th> <th class="text-center">{{i.name}}</th>
......
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <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"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item active"> <li class="nav-item active">
<a class="nav-link" href="#">Homepage</a> <a class="nav-link" href="/">Homepage</a>
</li> </li>
</ul> </ul>
</div> </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 @@ ...@@ -5,14 +5,25 @@
<div class="col-md-5"> <div class="col-md-5">
<h1>{{qboard.name}}</h1> <h1>{{qboard.name}}</h1>
<hr> <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> <hr>
{% for quest in quests %} {% for quest in quests %}
<div class="card card-body"> <div class="card card-body">
<table> <table>
<tr> <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="{% url 'update_quest' qboard.id %}">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="">Delete Quest</a></td>-->
</tr> </tr>
</table> </table>
<table class="table table-sm"> <table class="table table-sm">
......
...@@ -2,6 +2,11 @@ from django.urls import path ...@@ -2,6 +2,11 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.home), path('', views.home, name = "home"),
path('questboard/<str:pk_test>/', views.quests), 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 from django.http import HttpResponse
# Create your views here. # Create your views here.
from .models import * from .models import *
from .forms import *
def home(request): def home(request):
qboards = QBoard.objects.all() qboards = QBoard.objects.all()
...@@ -13,4 +14,48 @@ def quests(request, pk_test): ...@@ -13,4 +14,48 @@ def quests(request, pk_test):
quests = qboard.quest_set.all() quests = qboard.quest_set.all()
context = {'qboard' : qboard, 'quests' : quests} context = {'qboard' : qboard, 'quests' : quests}
return render(request, 'qBoard/quests.html', context) return render(request, 'qBoard/quests.html', context)
\ No newline at end of file
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