initial commit

This commit is contained in:
2021-01-20 01:36:22 -08:00
commit 368f89750b
45 changed files with 2821 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from flask import Blueprint, url_for, render_template, redirect
from flask_login import current_user
from app.models import Category, Task
cats = Blueprint(
"cats", __name__, template_folder="templates"
)
@cats.route("/move-categories/<int:taskid>")
def move_categories(taskid):
task = Task.query.get(taskid)
if task is None:
return(redirect(url_for('cats.index')))
if current_user.is_anonymous or current_user.id != task.contributor_id:
return(redirect(url_for('cats.index')))
cu = 'tsks.{}tasks'.format('hidden_' if task.done else '')
cancel_nav_link = ('cancel', url_for(cu, category_id=task.catid))
nl = (cancel_nav_link, )
categories = Category.query.filter(Category.contributor_id == current_user.id, Category.id != task.catid).all()
for cat in categories:
cat.href = url_for('movecat.move_cat', taskid=taskid, catid=cat.id)
cat.open = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=False).count()
cat.done = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=True).count()
return render_template(
'categories.html',
title="Move to",
navbar_links=nl,
heading='move to?',
categories=categories
)
@cats.route("/index")
@cats.route("/")
def index():
if current_user.is_anonymous:
navbar_links = (('login', url_for('auths.login')), )
return render_template('categories.html', title="Todo", navbar_links=navbar_links)
nl = (
('prof', url_for('prof.edit_profile')),
('new', url_for('new_cat.new_category')),
('hide', url_for('hidecats.hide_categories')),
('logout', url_for('auths.logout'))
)
categories = Category.query.filter_by(contributor_id=current_user.id, hidden=False).all()
for cat in categories:
cat.href = url_for('tsks.tasks', category_id=cat.id)
cat.open = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=False).count()
cat.done = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=True).count()
return render_template(
'categories.html',
title="Categories",
navbar_links=nl,
heading='categories',
categories=categories
)

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python3
from flask import Blueprint, url_for, redirect, render_template, flash
from flask_login import current_user
from app.models import Category, Task
from .. import db
delcat = Blueprint(
"delcat", __name__, template_folder="templates"
)
@delcat.route("/delete_category/<int:catid>")
def delete_category(catid):
category = Category.query.get(catid)
if category is None:
return(redirect(url_for('cats.index')))
if current_user.is_anonymous or current_user.id != category.contributor_id:
return(redirect(url_for('cats.index')))
db.session.delete(category)
db.session.commit()
flash("category {} is deleted".format(category.name))
return(redirect(url_for('hidecats.unhide_categories')))
@delcat.route("/delete-categories")
def delete_categories():
if current_user.is_anonymous:
return(redirect(url_for('cats.index')))
nl = (
('cancel', url_for('hidecats.unhide_categories')),
('logout', url_for('auths.logout'))
)
categories = Category.query.filter_by(contributor_id=current_user.id, hidden=True).all()
for cat in categories:
cat.href = url_for('delcat.delete_category', catid=cat.id)
cat.open = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=False).count()
cat.done = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=True).count()
return render_template(
'categories.html',
title="Category To Delete",
navbar_links=nl,
heading='category to delete?',
categories=categories
)

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
from flask import Blueprint, redirect, url_for, render_template, flash
from flask_login import current_user
from app.models import Category, Task
from .. import db
hidecats = Blueprint(
"hidecats", __name__, template_folder="templates"
)
@hidecats.route("/category-toggle-hidden/<int:catid>")
def category_toggle_hidden(catid):
category = Category.query.get(catid)
if category is None:
return(redirect(url_for('cats.index')))
if current_user.is_anonymous or current_user.id != category.contributor_id:
return(redirect(url_for('cats.index')))
category.hidden = not category.hidden
db.session.commit()
if category.hidden:
flash("category {} is now hidden".format(category.name))
return(redirect(url_for('hidecats.hide_categories')))
else:
flash("category {} is now unhidden".format(category.name))
return(redirect(url_for('hidecats.unhide_categories')))
@hidecats.route("/unhide-categories")
def unhide_categories():
if current_user.is_anonymous:
return(redirect(url_for('cats.index')))
if Category.query.filter_by(contributor_id=current_user.id, hidden=True).count() == 0:
return(redirect(url_for('hidecats.hide_categories')))
nl = (
('cancel', url_for('cats.index')),
('hide', url_for('hidecats.hide_categories')),
('delete', url_for('delcat.delete_categories'))
)
categories = Category.query.filter_by(contributor_id=current_user.id, hidden=True).all()
for cat in categories:
cat.href = url_for('hidecats.category_toggle_hidden', catid=cat.id)
cat.open = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=False).count()
cat.done = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=True).count()
return render_template(
'categories.html',
title="Category To unHide",
navbar_links=nl,
heading='category to unhide?',
categories=categories
)
@hidecats.route("/hide-categories")
def hide_categories():
if current_user.is_anonymous:
return(redirect(url_for('cats.index')))
num_hidden_cats = Category.query.filter_by(contributor_id=current_user.id, hidden=True).count()
nl = [('cancel', url_for('cats.index')), ]
if num_hidden_cats > 0:
nl.append(('unhide', url_for('hidecats.unhide_categories')), )
nl.append(('logout', url_for('auths.logout')))
categories = Category.query.filter_by(contributor_id=current_user.id, hidden=False).all()
for cat in categories:
cat.href = url_for('hidecats.category_toggle_hidden', catid=cat.id)
cat.open = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=False).count()
cat.done = Task.query.filter_by(catid=cat.id, contributor_id=cat.contributor_id, done=True).count()
return render_template(
'categories.html',
title="Category To Hide",
navbar_links=nl,
heading='category to hide?',
categories=categories
)

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import psycopg2
from flask import Blueprint, redirect, url_for, flash, render_template
from flask import current_app as app
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired, Regexp
from app.models import Category
new_cat = Blueprint(
"new_cat", __name__, template_folder="templates"
)
def insert_category(category):
conn = psycopg2.connect(
dbname=app.config['DATABASE_NAME'],
user=app.config['DATABASE_USER'],
host=app.config['DATABASE_HOST'],
password=app.config['DATABASE_PASSWORD']
)
cur = conn.cursor()
cur.execute("SELECT setval('category_id_seq', (SELECT MAX(id) FROM category))")
conn.commit()
cur.execute("SELECT count(id) FROM category WHERE name=%s AND contributor_id=%s", (category.name, category.contributor_id))
if cur.fetchone()[0] == 0:
cur.execute("INSERT INTO category(name, contributor_id) VALUES(%s, %s)", (category.name, category.contributor_id))
conn.commit()
conn.close
@new_cat.route("/new-category", methods=["GET", "POST"])
def new_category():
if current_user.is_anonymous:
return(redirect(url_for('cats.index')))
form = NewCategory()
nl = (('cancel', url_for('cats.index')), )
if form.validate_on_submit():
category = Category(name=form.name.data, contributor_id=current_user.id)
insert_category(category)
flash("Thanks for the new category!")
return(redirect(url_for('cats.index')))
return render_template('new_category.html', title='New Category', form=form, navbar_links=nl)
class NewCategory(FlaskForm):
name = StringField(
'New Task Category',
validators=[
DataRequired(),
Regexp('^[a-zA-Z0-9\\s-]+$', message='dashes, digits, and spaces are ok')
],
render_kw={'autofocus': True}
)
submit = SubmitField('Save')

View File

@@ -0,0 +1,42 @@
<style>
#main {
align-items: center;
}
h1 {
margin-top: 40px;
font-size: 2.3rem;
}
.buttonLink {
width: 95%;
max-width: 700px;
text-decoration: none;
}
.buttonLink button {
width: 100%;
color: white;
background-color: black;
padding: 10px 20px 10px 20px;
margin-bottom: 10px;
border-radius: 9px;
font-size: 1.3rem;
display: flex;
font-weight: bold;
justify-content: space-between;
}
</style>
{% extends "base.html" %}
{% block content %}
<h1>{{ heading }}</h1>
{% for category in categories %}
<a href={{ category.href }} class="buttonLink">
<button>
{{ category.name }}
<div style="display: flex;">
<div>{{ category.open }},</div>
<div style="color: grey;">{{ category.done }}</div>
</div>
</button>
</a>
{% endfor %}
{% endblock %}

View File

@@ -0,0 +1,28 @@
<style>
#name {
font-size: 1.2rem;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
{% extends "base.html" %}
{% block content %}
<div class="formContainer">
<h1>{{ titile }}</h1>
<form action="" method="post">
{{ form.hidden_tag() }}
<p>
{{ form.name.label }}<br>
{{ form.name(size=24) }}<br>
{% for error in form.name.errors %}
<span class="formWarning">[{{ error }}]</span>
{% endfor %}
</p>
<p>{{ form.submit() }}</p>
</form>
</div>
{% endblock %}