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

pass last_login_at to user crud UI from backend API correctly #133

Merged
merged 5 commits into from May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions flexmeasures/data/schemas/users.py
Expand Up @@ -24,3 +24,4 @@ def validate_timezone(self, timezone):
active = ma.auto_field()
timezone = ma.auto_field()
flexmeasures_roles = ma.auto_field()
last_login_at = ma.auto_field()
nhoening marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions flexmeasures/ui/crud/users.py
@@ -1,4 +1,5 @@
from typing import Optional, Union
from datetime import datetime

from flask import request, url_for
from flask_classful import FlaskView
Expand Down Expand Up @@ -55,6 +56,10 @@ def process_internal_api_response(
role_ids = tuple(user_data.get("flexmeasures_roles", []))
user_data["flexmeasures_roles"] = Role.query.filter(Role.id.in_(role_ids)).all()
user_data.pop("status", None) # might have come from requests.response
if "last_login_at" in user_data and user_data["last_login_at"] is not None:
user_data["last_login_at"] = datetime.fromisoformat(
user_data["last_login_at"]
)
if user_id:
user_data["id"] = user_id
if make_obj:
Expand Down
1 change: 1 addition & 0 deletions flexmeasures/ui/tests/utils.py
Expand Up @@ -64,6 +64,7 @@ def mock_user_response(
active=active,
password="secret",
flexmeasures_roles=[1],
last_login_at="2021-05-14T20:00:00",
nhoening marked this conversation as resolved.
Show resolved Hide resolved
)
if as_list:
user_list = [user]
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/time_utils.py
Expand Up @@ -85,7 +85,7 @@ def naturalized_datetime_str(dt: Optional[datetime]) -> str:
local_dt = (
dt.replace(tzinfo=pytz.utc).astimezone(local_timezone).replace(tzinfo=None)
)
if dt >= datetime.utcnow() - timedelta(hours=24):
if naive_utc_from(dt) >= datetime.utcnow() - timedelta(hours=24):
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
return naturaltime(local_dt)
else:
return naturaldate(local_dt)
Expand Down