Started functionality around editing a verse. Added the ability to add a new child as well as a force popup if you load the page and there are no people in the db. Need to add another field for when you add a person to add their club too.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
import theme
|
import theme
|
||||||
from nicegui import ui
|
from nicegui import ui
|
||||||
from main import checked_data
|
|
||||||
import data
|
import data
|
||||||
from utils import Utils
|
from utils import Utils
|
||||||
|
|
||||||
|
|||||||
238
main.py
238
main.py
@ -10,43 +10,80 @@ from utils import Utils
|
|||||||
db = data.CON
|
db = data.CON
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
APIKEY = "Token f562cf2d890151d682065696dacdc0f86938a18e"
|
APIKEY = "Token f562cf2d890151d682065696dacdc0f86938a18e"
|
||||||
HEADERS = { 'Authorization': APIKEY}
|
HEADERS = {"Authorization": APIKEY}
|
||||||
|
|
||||||
@ui.page('/')
|
|
||||||
|
@ui.page("/")
|
||||||
def index_page() -> None:
|
def index_page() -> None:
|
||||||
with theme.frame('Homepage'):
|
with theme.frame("Homepage"):
|
||||||
with ui.dialog().props('persistent') as addverse:
|
firstload = Utils.get_unique_people()
|
||||||
pass
|
if firstload is None:
|
||||||
with ui.dialog().props('persistent') as editverse:
|
with ui.dialog() as first_dialog, ui.card().classes("items-center"):
|
||||||
|
first_dialog.open()
|
||||||
|
ui.label(
|
||||||
|
"Looks like this is your first time! \n\n Please click the button below to add your first Awana club member."
|
||||||
|
).classes("text-center font-bold text-xl")
|
||||||
|
ui.button().props("push glossy icon=person_add color=secondary").on(
|
||||||
|
"click", lambda: addchild.open()
|
||||||
|
)
|
||||||
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with ui.grid(columns=1).classes('self-center justify-items-center content-center p-2 m-2 rounded-xl'):
|
with ui.dialog().props("persistent") as addverse:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with ui.dialog().props("persistent") as editverse:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with ui.dialog() as addchild, ui.card().classes("items-center"):
|
||||||
|
result = ui.input(label="Clubber's Name")
|
||||||
|
ui.button().props("push glossy icon=add_circle color=secondary").on(
|
||||||
|
"click", lambda: add_child(result)
|
||||||
|
)
|
||||||
|
|
||||||
|
with ui.grid(columns=1).classes(
|
||||||
|
"self-center justify-items-center content-center p-2 m-2 rounded-xl"
|
||||||
|
):
|
||||||
users = Utils.get_unique_people()
|
users = Utils.get_unique_people()
|
||||||
for ppl in users:
|
for ppl in users:
|
||||||
pers = str(ppl)[2:-3].title()
|
pers = str(ppl)[2:-3].title()
|
||||||
users = [pers if x==ppl else x for x in users]
|
users = [pers if x == ppl else x for x in users]
|
||||||
toggle = ui.toggle(users, clearable=True, on_change=lambda: show_person(toggle))
|
toggle = ui.toggle(users, clearable=True, on_change=lambda: show_person(toggle))
|
||||||
|
|
||||||
with ui.row().classes('fixed bottom-0 left-0 p-2 m-2'):
|
with ui.row().classes("fixed bottom-0 left-0 p-2 m-2"):
|
||||||
with ui.element('q-fab').props('icon=navigation color=accent'):
|
with ui.element("q-fab").props("icon=navigation color=accent"):
|
||||||
ui.element('q-fab-action').props('icon=add color=secondary').on('click', lambda: add_verse(toggle))
|
ui.element("q-fab-action").props("icon=add color=secondary").on(
|
||||||
ui.element('q-fab-action').props('icon=remove color=negative').on('click', lambda: remove_verse(toggle))
|
"click", lambda: add_verse(toggle)
|
||||||
|
)
|
||||||
|
ui.element("q-fab-action").props("icon=remove color=negative").on(
|
||||||
|
"click", lambda: remove_verse(toggle)
|
||||||
|
)
|
||||||
|
ui.element("q-fab-action").props("icon=person_add color=positive").on(
|
||||||
|
"click", lambda: addchild.open()
|
||||||
|
)
|
||||||
|
ui.element("q-fab-action").props("icon=person_remove color=accent").on(
|
||||||
|
"click", lambda: ui.notify("Removing person is not set up yet")
|
||||||
|
)
|
||||||
|
|
||||||
with ui.row().style('justify-content: center') as showperson:
|
with ui.row().style("justify-content: center") as showperson:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
showperson.set_visibility(False)
|
showperson.set_visibility(False)
|
||||||
# FEAT: Allow editing of the verse. Awana will sometimes only give the student part of a verse (i.e 1 John 4:14 is actually 14b).
|
# FEAT: Allow editing of the verse. Awana will sometimes only give the student part of a verse (i.e 1 John 4:14 is actually 14b).
|
||||||
# FEAT: Find how to pin/bind a verse to a second page
|
|
||||||
|
|
||||||
@ui.refreshable
|
@ui.refreshable
|
||||||
def show_person(person):
|
def show_person(person):
|
||||||
showperson.clear()
|
showperson.clear()
|
||||||
|
showperson.set_visibility(False)
|
||||||
if person.value is not None:
|
if person.value is not None:
|
||||||
dbinfo = Utils.get_specific_person(person)
|
dbinfo = Utils.get_specific_person(person)
|
||||||
if dbinfo == []:
|
if dbinfo == []:
|
||||||
showperson.clear()
|
showperson.clear()
|
||||||
ui.notify(f"{person.value} doesn't have any verses saved under her name! Start adding some by clicking the green arrow in the bottom left.")
|
ui.notify(
|
||||||
|
f"{person.value} doesn't have any verses saved under their name! Start adding some by clicking the arrow in the bottom left."
|
||||||
|
)
|
||||||
|
elif dbinfo[0][1] == None:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
showperson.set_visibility(True)
|
showperson.set_visibility(True)
|
||||||
if person.value == "Hannah":
|
if person.value == "Hannah":
|
||||||
@ -55,30 +92,63 @@ def index_page() -> None:
|
|||||||
setcolor = "rgba(255, 0, 0, .5)"
|
setcolor = "rgba(255, 0, 0, .5)"
|
||||||
else:
|
else:
|
||||||
setcolor = "rgba(0, 0, 255, .5)"
|
setcolor = "rgba(0, 0, 255, .5)"
|
||||||
with showperson.classes(f'border-8').style(f'border: {setcolor} 1px solid;'):
|
with showperson.classes(f"border-8").style(
|
||||||
with ui.grid(columns=5).classes('items-center w-full'):
|
f"border: {setcolor} 1px solid;"
|
||||||
ui.separator().classes('col-span-5 h-2')
|
):
|
||||||
|
with ui.grid(columns=5).classes(
|
||||||
|
"items-center w-full"
|
||||||
|
) as persontoggle:
|
||||||
|
ui.separator().classes("col-span-5 h-2")
|
||||||
for item in dbinfo:
|
for item in dbinfo:
|
||||||
label_verse = ui.label(text=item[0]).classes('hidden')
|
label_verse = ui.label(text=item[0]).classes("hidden")
|
||||||
label_passage = ui.label(text=item[1]).classes('hidden')
|
label_passage = ui.label(text=item[1]).classes("hidden")
|
||||||
label_status = ui.label(text=item[2]).classes('hidden')
|
label_status = ui.label(text=item[2]).classes("hidden")
|
||||||
ui.label(label_verse.text).classes('font-bold text-center')
|
ui.label(label_verse.text).classes("font-bold text-center")
|
||||||
with ui.row():
|
with ui.row():
|
||||||
ui.label(label_passage.text).classes('text-wrap')
|
ui.label(label_passage.text).classes("text-wrap")
|
||||||
ui.chip("Edit Verse", selectable=True, icon="edit", color="white", on_selection_change=lambda label_verse=label_verse: edit_verse(label_verse.text, person, label_passage.text))
|
# ui.chip("Edit Verse", selectable=True, icon="edit", color="white", on_selection_change=lambda label_verse=label_verse: edit_verse(label_verse.text, person, label_passage.text))
|
||||||
if label_status.text == '1':
|
if label_status.text == "1":
|
||||||
ui.chip('Complete',
|
ui.chip(
|
||||||
selectable=True, icon="add", color="positive",
|
"Complete",
|
||||||
on_selection_change=lambda label_verse=label_verse: Utils.toggle_completion(label_verse.text, person, status=0),
|
selectable=True,
|
||||||
on_click=lambda: show_person(person))
|
icon="add",
|
||||||
|
color="tnt",
|
||||||
|
on_selection_change=lambda label_verse=label_verse: Utils.toggle_completion(
|
||||||
|
label_verse.text, person, status=0
|
||||||
|
),
|
||||||
|
on_click=lambda: show_person(person),
|
||||||
|
).classes("text-white")
|
||||||
else:
|
else:
|
||||||
ui.chip('Incomplete',
|
ui.chip(
|
||||||
selectable=True, icon="add", color="negative",
|
"Incomplete",
|
||||||
on_selection_change=lambda label_verse=label_verse: Utils.toggle_completion(label_verse.text, person, status=1),
|
selectable=True,
|
||||||
on_click=lambda: show_person(person))
|
icon="add",
|
||||||
ui.checkbox('Pin Verse')#.bind_visibility_from(card, 'value')
|
color="sparks",
|
||||||
ui.checkbox('Mark as Completed')#.bind_value(item[2])
|
on_selection_change=lambda label_verse=label_verse: Utils.toggle_completion(
|
||||||
ui.separator().classes('col-span-5 h-2')
|
label_verse.text, person, status=1
|
||||||
|
),
|
||||||
|
on_click=lambda: show_person(person),
|
||||||
|
).classes("text-white")
|
||||||
|
ui.chip(
|
||||||
|
"Edit Verse",
|
||||||
|
selectable=True,
|
||||||
|
icon="edit",
|
||||||
|
color="cubbies",
|
||||||
|
on_selection_change=lambda label_passage=label_passage: edit_verse(
|
||||||
|
label_verse.text, person, label_passage.text
|
||||||
|
),
|
||||||
|
).classes("text-white")
|
||||||
|
ui.chip(
|
||||||
|
"Delete Verse",
|
||||||
|
selectable=True,
|
||||||
|
color="red",
|
||||||
|
icon="delete",
|
||||||
|
on_selection_change=lambda label_verse=label_verse: Utils.delete_verse(
|
||||||
|
label_verse.text, person
|
||||||
|
),
|
||||||
|
on_click=lambda: show_person(person),
|
||||||
|
).classes("text-white").style('color: white;')
|
||||||
|
ui.separator().classes("col-span-5 h-2")
|
||||||
else:
|
else:
|
||||||
showperson.clear()
|
showperson.clear()
|
||||||
addverse.close()
|
addverse.close()
|
||||||
@ -86,10 +156,14 @@ def index_page() -> None:
|
|||||||
def edit_verse(verse, person, passage):
|
def edit_verse(verse, person, passage):
|
||||||
editverse.open()
|
editverse.open()
|
||||||
with editverse:
|
with editverse:
|
||||||
with ui.card().classes('flex-wrap items-center'):
|
with ui.card().classes("flex-wrap items-center"):
|
||||||
editing = ui.textarea(label="Edit Below", placeholder=passage)
|
ui.label("Here's the verse for easier copy & paste:")
|
||||||
with ui.row().classes('justify-content-center'):
|
ui.label(passage)
|
||||||
ui.button().props('push glossy icon=add_circle color=secondary').on('click', lambda: submit_verse(result, person))
|
editing = ui.textarea(label="Edit below")
|
||||||
|
with ui.row().classes("justify-content-center"):
|
||||||
|
ui.button().props("push glossy icon=add_circle color=secondary").on(
|
||||||
|
"click", lambda: edit_submit_verse(person, editing, verse)
|
||||||
|
)
|
||||||
|
|
||||||
def add_verse(person):
|
def add_verse(person):
|
||||||
if person.value is None:
|
if person.value is None:
|
||||||
@ -97,31 +171,51 @@ def index_page() -> None:
|
|||||||
else:
|
else:
|
||||||
addverse.open()
|
addverse.open()
|
||||||
with addverse:
|
with addverse:
|
||||||
with ui.card().classes('flex-wrap items-center'):
|
with ui.card().classes("flex-wrap items-center"):
|
||||||
result = ui.input(label="Add Verse Here")
|
result = ui.input(label="Add Verse Here")
|
||||||
with ui.row().classes('justify-content-center'):
|
with ui.row().classes("justify-content-center"):
|
||||||
ui.button().props('push glossy icon=add_circle color=secondary').on('click', lambda: submit_verse(result, person))
|
ui.button().props(
|
||||||
ui.button().props('push glossy icon=cancel color=negative').on('click', lambda: addverse.close())
|
"push glossy icon=add_circle color=secondary"
|
||||||
|
).on("click", lambda: submit_verse(result, person))
|
||||||
|
ui.button().props("push glossy icon=cancel color=negative").on(
|
||||||
|
"click", lambda: addverse.close()
|
||||||
|
)
|
||||||
|
|
||||||
|
def edit_submit_verse(person, passage, verse):
|
||||||
|
print(passage)
|
||||||
|
print(passage.value)
|
||||||
|
Utils.edit_verse(person, verse, passage)
|
||||||
|
editverse.close()
|
||||||
|
show_person(person)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def submit_verse(result, person):
|
def submit_verse(result, person):
|
||||||
# Check if Verse is already in db
|
# Check if Verse is already in db
|
||||||
dbcheck = cur.execute(f"select * from tasks where person = '{person.value.lower()}' and verse = '{result.value}';")
|
dbcheck = cur.execute(
|
||||||
|
f"select * from tasks where person = '{person.value}' and verse = '{result.value}';"
|
||||||
|
)
|
||||||
check_for_verse = dbcheck.fetchone()
|
check_for_verse = dbcheck.fetchone()
|
||||||
if check_for_verse is not None:
|
if check_for_verse is not None:
|
||||||
ui.notify(f"{result.value} already exists for {person.value}! You can't have duplicates")
|
ui.notify(
|
||||||
|
f"{result.value} already exists for {person.value}! You can't have duplicates"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Verify the format of a Bible Verse
|
# Verify the format of a Bible Verse
|
||||||
if not re.match(r'((^\d\s\w{1,}\s|^\w{1,}\s)(\d{1,2}:)(\d{1,2}-\d{1,2}|\d{1,2}))', result.value):
|
if not re.match(
|
||||||
|
r"((^\d\s\w{1,}\s|^\w{1,}\s)(\d{1,2}:)(\d{1,2}-\d{1,2}|\d{1,2}))",
|
||||||
|
result.value,
|
||||||
|
):
|
||||||
ui.notify("Verse was input incorrectly.")
|
ui.notify("Verse was input incorrectly.")
|
||||||
addverse.close()
|
addverse.close()
|
||||||
else:
|
else:
|
||||||
# Split up the string for later
|
# Split up the string for later
|
||||||
colon = result.value.split(':')
|
colon = result.value.split(":")
|
||||||
precolon = colon[0].split(' ')[1].strip()
|
precolon = colon[0].split(" ")[1].strip()
|
||||||
postcolon = colon[1].strip()
|
postcolon = colon[1].strip()
|
||||||
if '-' in postcolon:
|
if "-" in postcolon:
|
||||||
start = postcolon.split('-')[0]
|
start = postcolon.split("-")[0]
|
||||||
end = postcolon.split('-')[1]
|
end = postcolon.split("-")[1]
|
||||||
else:
|
else:
|
||||||
start = postcolon
|
start = postcolon
|
||||||
|
|
||||||
@ -132,31 +226,41 @@ def index_page() -> None:
|
|||||||
vpass = response.json()
|
vpass = response.json()
|
||||||
passage = str(vpass["passages"])
|
passage = str(vpass["passages"])
|
||||||
# npassage gets rid of any carriage return characters
|
# npassage gets rid of any carriage return characters
|
||||||
npassage = passage.replace('\\n', '').strip()
|
npassage = passage.replace("\\n", "").strip()
|
||||||
# xpassage removes Footnotes section, if it exists
|
# xpassage removes Footnotes section, if it exists
|
||||||
if 'Footnotes' in npassage:
|
if "Footnotes" in npassage:
|
||||||
xpassage = re.sub(r'Footnotes.*', '', npassage)
|
xpassage = re.sub(r"Footnotes.*", "", npassage)
|
||||||
else:
|
else:
|
||||||
xpassage = npassage.replace("(ESV)']", '')
|
xpassage = npassage.replace("(ESV)']", "")
|
||||||
# vpassage grabs the actual verses, dropping the title (starting from first verse in result)
|
# vpassage grabs the actual verses, dropping the title (starting from first verse in result)
|
||||||
print(xpassage)
|
vpassage = re.search(rf"\[{start}\].*", xpassage).group(0)
|
||||||
vpassage = re.search(fr'\[{start}\].*', xpassage).group(0)
|
|
||||||
# zpassage - remove any parenthesis or brackets references
|
# zpassage - remove any parenthesis or brackets references
|
||||||
zpassage = re.sub(r'\[\d+\]|\(\d+\)|\s{2,}', '', vpassage).strip()
|
zpassage = re.sub(r"\[\d+\]|\(\d+\)|\s{2,}", "", vpassage).strip()
|
||||||
if re.match(r'^\“', zpassage):
|
if re.match(r"^\“", zpassage):
|
||||||
zpassage = f'{zpassage}”'
|
zpassage = f"{zpassage}”"
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
print(zpassage)
|
|
||||||
else:
|
else:
|
||||||
print(response.text)
|
|
||||||
ui.notify("Uh oh. Something went wrong.")
|
ui.notify("Uh oh. Something went wrong.")
|
||||||
|
|
||||||
ins = cur.execute(f"replace into tasks values('{person.value.lower()}', '{result.value}', '{zpassage}', 0, 0, 'none');")
|
ins = cur.execute(
|
||||||
|
f"replace into tasks values('{person.value.lower()}', '{result.value}', '{zpassage}', 0, 0, 'none');"
|
||||||
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
show_person(person)
|
show_person(person)
|
||||||
|
|
||||||
def checked_data() -> None:
|
def add_child(person):
|
||||||
datavals = []
|
check_person = Utils.get_specific_person(person)
|
||||||
|
print(check_person)
|
||||||
|
if check_person == []:
|
||||||
|
Utils.add_person(person)
|
||||||
|
# persontoggle.set_visibility(False)
|
||||||
|
show_person(person)
|
||||||
|
addchild.close()
|
||||||
|
else:
|
||||||
|
ui.notify(
|
||||||
|
f"The name {person.value} already exists. Please add someone else"
|
||||||
|
)
|
||||||
|
|
||||||
ui.run(storage_secret='b601785a-855c-41d1-adeb-68f0330d8186')
|
|
||||||
|
ui.run(storage_secret="b601785a-855c-41d1-adeb-68f0330d8186")
|
||||||
|
|||||||
Binary file not shown.
2
theme.py
2
theme.py
@ -9,7 +9,7 @@ sparks='rgba(255, 0, 0, 0.25)'
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def frame(navigation_title: str):
|
def frame(navigation_title: str):
|
||||||
"""Custom page frame to share the same styling and behavior across all pages"""
|
"""Custom page frame to share the same styling and behavior across all pages"""
|
||||||
ui.colors(primary='#023047', secondary='#219ebc', accent='#8ecae6', positive='#ffb703', negative='#fb8500', header="#abb8c3", tnt='rgba(30, 206, 0, 0.25)', cubbies='rgba(25, 39, 255, 0.25)', sparks='rgba(255, 0, 0, 0.25)')
|
ui.colors(primary='#023047', secondary='#219ebc', accent='#8ecae6', positive='#ffb703', negative='#fb8500', header="#abb8c3", tnt='#02ba08', cubbies='#3a3ac9', sparks='#ba0202')
|
||||||
with ui.header().style('background-color: #abb8c3'):
|
with ui.header().style('background-color: #abb8c3'):
|
||||||
ui.image('./assets/awana-clubs.png').classes('w-16')
|
ui.image('./assets/awana-clubs.png').classes('w-16')
|
||||||
ui.label('Awana Verse Practice').classes('font-bold font-16')
|
ui.label('Awana Verse Practice').classes('font-bold font-16')
|
||||||
|
|||||||
14
utils.py
14
utils.py
@ -27,6 +27,16 @@ class Utils():
|
|||||||
incret = inc.fetchall()
|
incret = inc.fetchall()
|
||||||
return incret
|
return incret
|
||||||
|
|
||||||
def edit_verse(person, verse):
|
def edit_verse(person, verse, passage):
|
||||||
vedit = cur.execute(f"update tasks set verse_passage = '{verse_text}' where person = '{person.value} and verse = '{verse}'")
|
print(f"update tasks set verse_passage = '{passage.value}' where person = '{person.value}' and verse = '{verse}'")
|
||||||
|
vedit = cur.execute(f"update tasks set verse_passage = '{passage.value}' where person = '{person.value} and verse = '{verse}';")
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
def add_person(person):
|
||||||
|
print(person)
|
||||||
|
aperson = cur.execute(f"insert into tasks(person) values ('{person.value}')")
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
def delete_verse(verse, person):
|
||||||
|
dverse = cur.execute(f"delete from tasks where person = '{person.value}' and verse = '{verse}'")
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user