Commit fbc9bda6 authored by Aedin Hunter A. Clay's avatar Aedin Hunter A. Clay

cleaned up code and added comments

parent 24351d19
......@@ -21,7 +21,8 @@ class QuestForm(forms.ModelForm):
'student2' : forms.HiddenInput(),
'student3' : forms.HiddenInput(),
}
#Form for signing up to quests
class StudentSignupForm(forms.Form):
quest_id = forms.IntegerField(widget = forms.HiddenInput())
name = forms.CharField(max_length = 60)
......
from django.core.validators import MinValueValidator
from django.db import models
#Questboard: a place where Quests can be posted.
class Questboard(models.Model):
name = models.CharField(max_length = 50)
description = models.CharField(max_length = 300)
required_stars = models.PositiveIntegerField(validators=[MinValueValidator(0)])
#Quest: Students can sign up for quests. Each one is worth a certain number of stars.
class Quest(models.Model):
board_id = models.PositiveIntegerField(default = 0, validators=[MinValueValidator(0)])
name = models.CharField(max_length = 60, default = '')
......
......@@ -3,7 +3,7 @@ from django.http import HttpRequest
from .models import Quest, Questboard
from .forms import *
#View that displays a questboard, allows it to be edited as a teacher
def edit_board_view(request, pk):
return render(
request,
......@@ -20,6 +20,8 @@ def edit_board_view(request, pk):
'delete_quest_form' : DeleteQuestForm(auto_id = 'delete_%s'),
}
)
#View that displays a questboard, allows students to sign up for quests
def view_board_view(request, pk):
return render(
request,
......@@ -31,9 +33,13 @@ def view_board_view(request, pk):
'signup_form' : StudentSignupForm(auto_id = 'signup_%s')
}
)
#get the url of the questboard so it can be shared
def get_share_url(request, pk):
return request.build_absolute_uri('/questboard/view/' + str(pk))
#FUNCTIONS FOR MANIPULATING QUESTS
def add_quest(request):
if request.method == "POST":
filled_form = QuestForm(request.POST)
......@@ -41,7 +47,8 @@ def add_quest(request):
filled_form.save()
return redirect(request.META.get('HTTP_REFERER', '/'))
def student_signup(request): # PLEASE ADD A "CHECK IF NAME IS THERE ALREADY" FUNCTION TO THE QUEST!
#signs students up to quests
def student_signup(request):
if request.method == "POST":
filled_form = StudentSignupForm(request.POST)
if filled_form.is_valid():
......@@ -76,10 +83,11 @@ def delete_quest(request):
quest_to_delete.delete()
return redirect(request.META.get('HTTP_REFERER', '/'))
#FUNCTIONS FOR MANIPULATING QUESTBOARDS
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']
......@@ -90,7 +98,6 @@ def edit_board_name(request):
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']
......
from django.shortcuts import redirect, render
from board.models import Questboard
from board.forms import QuestboardForm
from board.models import Questboard
def redirect_to_home(request):
return redirect('/home/')
......@@ -12,10 +12,12 @@ def homepage_view(request):
'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():
new_questboard = filled_form.save()
return redirect('/questboard/edit/' + str(new_questboard.id))
\ No newline at end of file
#redirect to the newly created questboard
return redirect('/questboard/edit/' + str(new_questboard.id))
return redirect_to_home(request)
\ No newline at end of file
......@@ -9,7 +9,6 @@ BASE_DIR = Path(__file__).resolve().parent.parent
load_dotenv()
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#(49vncg1=2+(7=73as12d0*_h52w6$2%-sjqmtj@580mr+(-k'
......@@ -19,7 +18,6 @@ DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
......@@ -65,8 +63,7 @@ TEMPLATES = [
WSGI_APPLICATION = 'project_questboard.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
# Postgres Database
DATABASES = {
'default': {
......@@ -81,7 +78,6 @@ DATABASES = {
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
......@@ -100,7 +96,6 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
......@@ -114,7 +109,6 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
For the postgres database:
Please create a .env with the following variables:
DB_NAME : name of the database to use
DB_USER : username of postgres account
DB_PASS : password of postgres account
<!--Template for basic web page in Questboard.-->
{% load static %}
<html>
<head>
<title>{% block title %}{% endblock %}</title>
......@@ -21,13 +18,18 @@
<body>
<a href = "/home/"><p class = "homepage_link">Back to Homepage</p></a>
<div id="contents">
<a href = "/home/"><p class = "website_header">Questboard!</p></a>
<p class = "website_author">Implemented by Aedin Clay</p>
<!-- Page title and contents go here -->
<p class = "page_header">{% block header %}{% endblock %}</p>
{% block content %}{% endblock %}
</div>
<!-- Additional Scripts -->
{% block scripts %}{% endblock %}
</body>
......
<!-- BASIC TEMPLATE FOR DISPLAYING THE CONTENTS OF A QUESTBOARD-->
<!-- Includes questboard name, description, required stars, and url. -->
<!-- Also includes details of all quests in the questboard -->
{% extends 'base.html' %}
{% load static %}
<!-- BASIC PAGE INFORMATION -->
{% block title%}{{questboard.name}}{% endblock %}
{% block styles %}
<link rel = "stylesheet" href = "{% static 'board/board.css' %}">
{% endblock %}
{% block header %}{{questboard.name}}{% endblock %}
<!-- PAGE CONTENTS -->
{% block content %}
<!-- Questboard name and description -->
<div class = "infobox">
<p><b>Description:</b> {{questboard.description}}</p>
<p><b>Required stars:</b> {{questboard.required_stars}}</p>
</div>
<!-- Copy questboard link -->
<!-- Button to copy questboard url -->
<button onclick = "copyQuestboardLink()" class = "button">Copy Questboard Link</button>
<script>
function copyQuestboardLink(){
var link_area = document.createElement("textarea")
......@@ -30,18 +34,26 @@ function copyQuestboardLink(){
}
</script>
{% block extra_content %}{% endblock %}
<br/>
<!-- Extra menu options for viewing and editing questboard -->
{% block extra_content %}{% endblock %}<br/>
<!-- Display area for Quests-->
<p class = "sub_header">Quests:</p>
{% if quests %}
<div id = "quest_display">
{% for quest in quests %}
<!-- Display box for Single Quest -->
<div class = "questbox_wrapper">
<div class = "questbox">
<!-- Quest information -->
<p class = "questbox_name">{{ quest.name }}</p>
<p class = "questbox_description">{{ quest.description }}</p>
<p class = "questbox_stars">Stars : {{quest.stars}}</p>
<!-- List of Students to sign up to the quest -->
<div class = "questbox_students">
{% if quest.for_everyone is True %}
This Quest is for everyone.
......@@ -53,21 +65,23 @@ function copyQuestboardLink(){
</ol>
{% endif %}
</div>
<!-- Actions for the Quest (edit, delete, sign up)-->
<span class = "questbox_actions">
{% block questbox_actions %}{% endblock %}
</span>
</div>
</div>
{% endfor %}
</div>
<!-- If there are no quests in the questboard, display this message-->
{% else %}
<i>No Quests so Far</i>
{% endif %}
<!-- Additional Scripts-->
{% block extra_scripts %}{% endblock %}
{% endblock %}
{% endblock %}
\ No newline at end of file
<!-- PAGE FOR EDITING QUESTBOARD AND QUESTS AS A TEACHER-->
{% extends 'board/board.html' %}
{% load static %}
{% block extra_content %}
<!-- Dropdown box for Editing Questboard-->
<div class = "dropdown">
<button class = "button">Edit Options</button>
<div class = "dropdown-content">
......@@ -12,6 +15,7 @@
</div>
<button class = "button" onclick="showAddQuest()">Add Quest</button>
<!-- Dialog box for Editing Questboard Name-->
<br/>
<dialog id="edit_board_name">
<form action = "/questboard/edit/edit_board_name/" method = "post">
......@@ -22,6 +26,7 @@
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<!-- Dialog box for Editing Questboard Description-->
<dialog id="edit_board_desc">
<form action = "/questboard/edit/edit_board_desc/" method = "post">
{% csrf_token %}
......@@ -31,6 +36,7 @@
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<!-- Dialog box for Editing Questboard Required Stars-->
<dialog id="edit_board_stars">
<form action = "/questboard/edit/edit_board_stars/" method = "post">
{% csrf_token %}
......@@ -40,6 +46,7 @@
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<!-- Dialog box for Adding Quests-->
<dialog id="add_quest">
<form action = "/questboard/edit/add_quest/" method = "post">
{% csrf_token %}
......@@ -49,6 +56,7 @@
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<!-- Dialog box for Editing Quests-->
<dialog id="edit_quest">
<form action = "/questboard/edit/edit_quest/" method = "post">
{% csrf_token %}
......@@ -58,6 +66,7 @@
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
<!-- Dialog box for Deleting Quests-->
<dialog id="delete_quest">
Are you sure you want to delete this quest?
<form action = "/questboard/edit/delete_quest/" method = "post">
......@@ -69,19 +78,22 @@
</dialog>
{% endblock %}
<!-- Buttons and options for manipulating individual Quests -->
{% block questbox_actions %}
<!-- If no student has signed up yet or the quest is for everyone, then the quest can be edited / deleted -->
{% if quest.student1 == '' and quest.student2 == '' and quest.student3 == '' %}
<button onclick="showEditQuest({{quest.pk}})" class = "button">Edit Quest</button>
<button onclick="showDeleteQuest({{quest.pk}})" class = "button">Delete Quest</button>
{% else %}
<p>Cannot Edit Quest: students have already signed up.</p>
{% endif %}
<!-- If no student has signed up yet or the quest is for everyone, then the quest can be edited / deleted -->
{% if quest.student1 == '' and quest.student2 == '' and quest.student3 == '' %}
<button onclick="showEditQuest({{quest.pk}})" class = "button">Edit Quest</button>
<button onclick="showDeleteQuest({{quest.pk}})" class = "button">Delete Quest</button>
{% else %}
<p>Cannot Edit Quest: students have already signed up.</p>
{% endif %}
{% endblock %}
<!-- Additional Scripts -->
{% block extra_scripts %}
<script>
// Store Dialog Boxes as Variables
AddQuest = document.getElementById('add_quest');
EditQuest = document.getElementById('edit_quest');
DeleteQuest = document.getElementById('delete_quest');
......@@ -98,6 +110,7 @@ function closeAllDialogBoxes(){
EditBoardStars.close();
}
// Store value of quest being edited or deleted to Form being sent
function selectQuestToEdit(pk){
document.getElementById('edit_quest_id').setAttribute("value", pk)
}
......@@ -106,6 +119,7 @@ function selectQuestToDelete(pk){
document.getElementById('delete_quest_id').setAttribute("value", pk)
}
//Functions for displaying Dialog Boxes
function showAddQuest(){
closeAllDialogBoxes();
AddQuest.show();
......@@ -137,6 +151,5 @@ function showDeleteQuest(pk){
DeleteQuest.show();
selectQuestToDelete(pk);
}
</script>
{% endblock %}
\ No newline at end of file
<!-- Page to View Questboard as Student-->
{% extends 'board/board.html' %}
{% load static %}
<!-- Button for Signing up to Quest -->
{% block questbox_actions %}
{% if quest.for_everyone is False %}
<!-- If the quest does not yet have three students -->
<!-- If the quest is not for everyone and if the quest does not yet have three students, show Signup button -->
{% if quest.for_everyone is False %}
{% if quest.student1 == '' or quest.student2 == '' or quest.student3 == '' %}
<button id="show_quest_signup" onclick = "showQuestSignup({{ quest.pk }})">Sign Up for Quest</button>
{% endif %}
{% endif %}
{% endif %}
{% endblock %}
{% block extra_content %}
<!-- Dialog box for signing up to quests-->
<dialog id = "quest_signup">
Please enter your name to sign up for this quest.
<form action = "/questboard/view/student_signup/" method = "post">
......@@ -24,6 +26,7 @@
</dialog>
{% endblock %}
<!-- Additional Scripts-->
{% block extra_scripts %}
<script>
......@@ -33,15 +36,18 @@ function closeAllDialogBoxes(){
QuestSignup.close();
}
// Store value of quest to sign up for into Form being sent
function selectQuestToSignupFor(pk){
document.getElementById('signup_quest_id').setAttribute("value", pk)
}
function showQuestSignup(pk){
closeAllDialogBoxes();
QuestSignup.show();
selectQuestToSignupFor(pk);
}
function selectQuestToSignupFor(pk){
document.getElementById('signup_quest_id').setAttribute("value", pk)
}
......
<!-- HOMEPAGE.HTML -->
{% extends 'base.html' %}
{% load static %}
<!-- BASIC PAGE INFORMATION-->
{% block title%}Homepage{% endblock %}
{% block styles %}
<link rel = "stylesheet" href = "{% static 'homepage/homepage.css' %}">
{% endblock %}
{% block header %}Homepage{% endblock %}
<!-- PAGE CONTENTS -->
{% block content %}
<!-- LIST OF QUESTBOARDS -->
<!-- TABLE OF QUESTBOARDS -->
<table class = "board_table">
<tr>
<th>Questboard Name</th>
<th>Actions</th>
</tr>
<!-- Displays one questboard per table row -->
{% for board in boards %}
<tr>
<td>{{ board.name }}</td>
......@@ -31,13 +30,12 @@
</td>
</tr>
{% endfor %}
</table>
<button class = "button" onclick = "showAddBoard()">Add a Questboard</button>
<dialog id="add_board"><!-- PLEASE PREVENT NEGATIVE NUMBERS!!!-->
<!-- DIALOG BOX FOR ADDING A QUESTBOARD-->
<dialog id="add_board">
<form action = "add_board/" method = "post">
{% csrf_token %}
{{ add_board_form }}
......@@ -45,9 +43,10 @@
</form>
<button onclick = "closeAllDialogBoxes()">Cancel</button>
</dialog>
{% endblock %}
<!-- PAGE SCRIPTS -->
{% block scripts %}
<script>
AddBoard = document.getElementById("add_board");
......@@ -60,6 +59,5 @@ function showAddBoard(){
closeAllDialogBoxes();
AddBoard.show();
}
</script>
{% 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