Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023 Updates #80

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

basedir = path.abspath(path.dirname(__file__))

engine: Engine = create_engine('sqlite:///' +
path.join(basedir, '..', 'database.db'),
echo=True,
encoding='utf8')
engine: Engine = create_engine(
'sqlite:///' + path.join(basedir, '..', 'database.db'),
echo=True,
)

BaseModel.metadata.create_all(bind=engine)

Expand Down
34 changes: 19 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
astroid==2.15.6
bcrypt==4.0.1
Bootstrap-Flask==2.2.0
click==8.1.3
dill==0.3.6
Flask==3.0.0
Flask-CKEditor==0.4.6
astroid==3.0.1
bcrypt==4.1.1
blinker==1.7.0
Bootstrap-Flask==2.3.3
click==8.1.7
dill==0.3.7
Flask==2.3.3
Flask-CKEditor==0.5.1
Flask-Login==0.6.3
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.1.1
Flask-WTF==1.2.1
greenlet==3.0.1
importlib-metadata==6.8.0
isort==5.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
lazy-object-proxy==1.9.0
MarkupSafe==2.1.2
MarkupSafe==2.1.3
mccabe==0.7.0
platformdirs==3.10.0
platformdirs==4.0.0
pylint==3.0.2
SQLAlchemy==2.0.19
SQLAlchemy==2.0.23
tomli==2.0.1
tomlkit==0.12.3
uWSGI==2.0.22
Werkzeug==2.3.8
wrapt==1.15.0
WTForms==3.0.1
typing_extensions==4.8.0
uWSGI==2.0.23
Werkzeug==3.0.1
wrapt==1.16.0
WTForms==3.1.1
yapf==0.40.2
zipp==3.17.0
20 changes: 19 additions & 1 deletion routes/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bcrypt import gensalt, hashpw
from flask_login import login_required, current_user
from flask import redirect, flash, render_template, request, Response, g, make_response
from sqlalchemy import text

from app import app
from models import Session, Note
Expand All @@ -20,6 +21,23 @@ def account():
return render_template('account.html', uuid=str(uuid4()))


@app.route('/search')
@login_required
def search():
search_param = request.args.get('search', '')
with Session() as session:
session.query(Note)

personal_notes = session.query(Note).filter(
Note.user_id == current_user.id,
text(f"text like '%{search_param}%'")).all()
return render_template(
'search.html',
search=search_param,
personal_notes=personal_notes,
)


@app.route('/accounts/<int:user_id>/notes')
@login_required
def get_personal_notes(user_id: int):
Expand Down Expand Up @@ -84,7 +102,7 @@ def toggle_darkmode():
preferences = g.preferences
preferences['mode'] = 'light' if preferences['mode'] == 'dark' else 'dark'

response.set_cookie('preferences', b64encode(dumps(preferences)))
response.set_cookie('preferences', b64encode(dumps(preferences)).decode())
return response


Expand Down
2 changes: 1 addition & 1 deletion templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ <h1>Page not Found</h1>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
72 changes: 15 additions & 57 deletions templates/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,43 @@ <h1>Account</h1>
</div>
<div class="row mb-2">
<div class="col col-12 col-md-6">
<form
method="post"
action="/account">
<form method="post" action="/account">
<div class="mb-3">
<label
for="email"
class="form-label">
<label for="email" class="form-label">
Email address
</label>
<input
type="email"
class="form-control"
name="email"
id="email"
value="{{current_user.email}}" />
<input type="email" class="form-control" name="email" id="email" value="{{current_user.email}}" />
</div>
<div class="mb-3">
<label
for="password"
class="form-label">
<label for="password" class="form-label">
Password
</label>
<input
type="password"
class="form-control"
id="password"
name="password"
value="{{uuid}}" />
<input type="password" class="form-control" id="password" name="password" value="{{uuid}}" />
</div>
<input
type="hidden"
class="form-control"
id="password_control"
name="password_control"
value="{{uuid}}" />
<input type="hidden" class="form-control" id="password_control" name="password_control" value="{{uuid}}" />

{% if current_user.is_admin %}
<div class="mb-3">
<input
class="form-check-input"
type="checkbox"
name="is_admin"
checked="{{current_user.is_admin}}"
<input class="form-check-input" type="checkbox" name="is_admin" checked="{{current_user.is_admin}}"
id="is_admin" />
<label
class="form-check-label"
for="is_admin">
<label class="form-check-label" for="is_admin">
Admin
</label>
</div>
{% endif %}
<button
type="submit"
class="btn btn-primary d-flex align-items-center">
<button type="submit" class="btn btn-primary d-flex align-items-center">
{{ render_icon('save') }}&nbsp;Update
</button>
</form>
</div>
<div class="col col-12 col-md-6">
<div class="d-flex flex-column align-items-center">
<object
width="200"
height="200"
class="rounded-circle img-thumbnail d-flex mb-2"
<object width="200" height="200" class="rounded-circle img-thumbnail d-flex mb-2"
data="{{current_user.profile_image.decode() if current_user.profile_image else '/static/fallback.png'}}">
<img
width="200"
height="200"
class="rounded-circle img-thumbnail"
src="/static/fallback.png" />
<img width="200" height="200" class="rounded-circle img-thumbnail" src="/static/fallback.png" />
</object>
{% include "partials/change_image_modal.html" %}
<button
class="btn btn-primary mb-2 d-flex align-items-center"
data-bs-toggle="modal"
<button class="btn btn-primary mb-2 d-flex align-items-center" data-bs-toggle="modal"
data-bs-target="#change_image_modal">
{{ render_icon('image') }}&nbsp;Change Image
</button>
Expand All @@ -97,12 +59,8 @@ <h2>Preferences</h2>
</div>
<div class="row mb-2">
<div class="col">
<form
action="/darkmode"
method="post">
<button
type="submit"
class="btn btn-primary d-flex align-items-center">
<form action="/darkmode" method="post">
<button type="submit" class="btn btn-primary d-flex align-items-center">
{% if g.preferences['mode'] == 'light' %}
{{render_icon('moon')}}&nbsp;Enable Darkmode {% else %}
{{render_icon('sun')}}&nbsp;Disable Darkmode {% endif %}
Expand All @@ -111,4 +69,4 @@ <h2>Preferences</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{% if current_user.is_authenticated %}
<div class="d-flex flex-column flex-lg-row">
{{ render_nav_item('home', 'Home') }}
{{ render_nav_item('search', 'Search') }}
{{ render_nav_item('get_personal_notes', 'Personal Notes', user_id=current_user.id) }}
{% if current_user.is_admin %}
{{ render_nav_item('registration_codes', 'Registration Codes') }}
Expand Down
28 changes: 7 additions & 21 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<div class="col">
<div class="d-flex justify-content-between align-items-center">
<h1>Home</h1>
<button
class="btn btn-primary mb-2 d-flex align-items-center"
data-bs-toggle="modal"
<button class="btn btn-primary mb-2 d-flex align-items-center" data-bs-toggle="modal"
data-bs-target="#create_note_modal">
{{ render_icon('file-earmark-plus') }}&nbsp;Create note
</button>
Expand All @@ -32,29 +30,17 @@ <h6 class="card-subtitle mb-2 text-muted">
</h6>
<p class="card-text">{{ note.text | safe }}</p>
</div>
<div
class="card-footer text-muted d-flex justify-content-between align-items-center">
<div class="card-footer text-muted d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<object
width="40"
height="40"
class="rounded img-thumbnail d-flex"
<object width="40" height="40" class="rounded img-thumbnail d-flex"
data="{{note.user.profile_image.decode() if note.user.profile_image else '/static/fallback.png'}}">
<img
width="40"
height="40"
class="rounded img-thumbnail"
src="/static/fallback.png" />
<img width="40" height="40" class="rounded img-thumbnail" src="/static/fallback.png" />
</object>
<span class="ms-1">By {{ note.user.email }}</span>
</div>
{% if note.user_id == current_user.id or current_user.is_admin %}
<form
method="post"
action="/notes/{{note.id}}/delete">
<button
type="submit"
class="btn btn-primary d-flex align-items-center">
<form method="post" action="/notes/{{note.id}}/delete">
<button type="submit" class="btn btn-primary d-flex align-items-center">
{{render_icon('trash')}}&nbsp;Delete
</button>
</form>
Expand All @@ -68,4 +54,4 @@ <h6 class="card-subtitle mb-2 text-muted">
{% endif %}
</div>
</div>
{% endblock %} {% block scripts %} {{ ckeditor.load() }} {% endblock %}
{% endblock %} {% block scripts %} {{ ckeditor.load() }} {% endblock %}
30 changes: 7 additions & 23 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,25 @@ <h1>Login</h1>
</div>
<div class="row">
<div class="col">
<form
method="post"
action="/login">
<form method="post" action="/login">
<div class="mb-3">
<label
for="email"
class="form-label">
<label for="email" class="form-label">
Email address
</label>
<input
type="email"
class="form-control"
name="email"
id="email" />
<input type="email" class="form-control" name="email" id="email" />
</div>
<div class="mb-3">
<label
for="password"
class="form-label">
<label for="password" class="form-label">
Password
</label>
<input
type="password"
class="form-control"
id="password"
name="password" />
<input type="password" class="form-control" id="password" name="password" />
</div>
<button
type="submit"
class="btn btn-primary">
<button type="submit" class="btn btn-primary">
Login
</button>
</form>
</div>
</div>
</div>

{% endblock %}
{% endblock %}
34 changes: 7 additions & 27 deletions templates/partials/change_image_modal.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
{% from 'bootstrap5/utils.html' import render_icon %}
<div
class="modal fade"
id="change_image_modal"
tabindex="-1"
aria-labelledby="Change Image Modal"
aria-hidden="true">
<div class="modal fade" id="change_image_modal" tabindex="-1" aria-labelledby="Change Image Modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Change Image</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"></button>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form
method="post"
action="/account/image">
<form method="post" action="/account/image">
<div class="mb-3">
<label
for="url"
class="form-label">
<label for="url" class="form-label">
Image URL
</label>
<input
type="text"
class="form-control"
name="url"
id="url"
required />
<input type="text" class="form-control" name="url" id="url" required />
</div>
<button
type="submit"
class="btn btn-primary d-flex align-items-center">
<button type="submit" class="btn btn-primary d-flex align-items-center">
{{render_icon('upload')}}&nbsp;Upload
</button>
</form>
</div>
</div>
</div>
</div>
</div>
Loading