Skip to content

Commit

Permalink
feat(timestamps): display times based on browser timezone (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
drahamim authored Mar 3, 2024
1 parent ee0e880 commit 7d761ef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/invenflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,33 @@
from importlib.metadata import version, PackageNotFoundError
from sqlalchemy.exc import IntegrityError
from werkzeug.utils import secure_filename
from flask_moment import Moment

from .models import Asset, Staff, Checkout, History, db


app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv(
'DATABASE_URI', 'sqlite:////tmp/test.db')
bootstrap = Bootstrap5(app)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SECRET_KEY'] = os.urandom(24)
app.config['upload_folder'] = 'uploads'
moment = Moment(app)

# Init DB
db.init_app(app)
migrate = Migrate(app, db)

# @app.context
# def inject_settings():
# if not db.session.query(GlobalSet).filter(GlobalSet.settingid == "timezone"):
# db.session.add(GlobalSet(settingid="timezone", setting="UTC"))
# db.session.commit()
# else:
# print("timezone already set")
# return dict(settings=db.session.query(GlobalSet).all())


@app.context_processor
def get_version():
Expand Down
5 changes: 5 additions & 0 deletions src/invenflask/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<a class="nav-link" href="{{ url_for('history') }}">History
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('settings') }}">Settings
</a>
</li>
</ul>
<!-- <form class="d-flex">
<input class="form-control me-sm-2" type="search" placeholder="Search">
Expand All @@ -61,6 +65,7 @@
</head>

<body {{ load_checkout|safe if load_checkout is not none else 'NONE' }} >
{{moment.include_moment()}}
<hr>
<div class="content">
{% with messages = get_flashed_messages(with_categories=true) %}
Expand Down
8 changes: 4 additions & 4 deletions src/invenflask/templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<th>staff ID</th>
<th>Department</th>
<th>Division</th>
<th>CheckoutTime</th>
<th>ReturnTime</th>
<th><div>Checkout Time</div><div>Browser Local</div></th>
<th><div>Return Time</div><div>Browser Local</div></th>
</tr>
</thead>
<tbody>
Expand All @@ -19,8 +19,8 @@
<td>{{ asset.staffid }}</td>
<td>{{ asset.department }}</td>
<td>{{ asset.division }}</td>
<td>{{ asset.checkouttime }}</td>
<td>{{ asset.returntime }}</td>
<td>{{ moment(asset.checkouttime, local=True).format('LLL') }}</td>
<td>{{ moment(asset.returntime, local=True).format('LLL') }}</td>
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion src/invenflask/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h4>Checked Out Assets</h4>
<td>{{ item.assetid }}</td>
<td>{{ item.staffid }}</td>
<td>{{ item.department }}</td>
<td>{{ item.timestamp }}</td>
<td>{{ moment(item.timestamp, local=True).format('LLL') }}</td>
</td>
</tr>
{% endfor %}
Expand Down
12 changes: 6 additions & 6 deletions src/invenflask/templates/single_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h4>Current Assets</h4>
{% for item in current %}
<tr>
<td>{{ item.assetid }}</td>
<td>{{ item.timestamp }}</td>
<td>{{ moment(item.timestamp, local=True).format('LLL') }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -58,8 +58,8 @@ <h4>History</h4>
{% for item in history %}
<tr>
<td>{{ item.assetid }}</td>
<td>{{ item.checkouttime }}</td>
<td>{{ item.returntime }}</td>
<td>{{ moment(item.checkouttime, local=True).format('LLL') }}</td>
<td>{{ moment(item.returntime, local=True).format('LLL') }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -100,7 +100,7 @@ <h1> Asset History </h1>
<tr>
<td>{{ item.staffid }}</td>
<td>{{ item.department }}</td>
<td>{{ item.timestamp }}</td>
<td>{{ moment(item.timestamp, local=True).format('LLL') }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -123,8 +123,8 @@ <h1> Asset History </h1>
<td>{{ item.staffid }}</td>
<td>{{ item.department }}</td>
<td>{{ item.division }}</td>
<td>{{ item.checkouttime }}</td>
<td>{{ item.returntime }}</td>
<td>{{ moment(item.checkouttime, local=True).format('LLL') }}</td>
<td>{{ moment(item.returntime, local=True).format('LLL') }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 7d761ef

Please sign in to comment.