Skip to content

Commit e80967d

Browse files
authored
Merge pull request #201 from statisticsnorway/modify-init.py
Modify init.py
2 parents 294da99 + 90e9f80 commit e80967d

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ssb-dash-framework"
3-
version = "0.1.4a1"
3+
version = "0.1.4a2"
44
description = "SSB Dash Framework"
55
authors = [{ name = "Magnus Theodor Engh", email = "dor@ssb.no" }]
66
license = "GPL-3.0"

src/ssb_dash_framework/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from .utils import enable_app_logging
6060
from .utils import module_validator
6161
from .utils import sidebar_button
62+
from .utils import apply_edits
6263

6364
# from .modals import HBMethod
6465
# from .utils import _get_kostra_r

src/ssb_dash_framework/modules/building_blocks/tables.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(
109109
self.module_layout = self._create_layout()
110110
self.module_callbacks()
111111
self._is_valid()
112-
self.timestamp = int(time.time() * 1000)
112+
self.tz = zoneinfo.ZoneInfo("Europe/Oslo")
113113
module_validator(self)
114114

115115
def _is_valid(self) -> None:
@@ -414,8 +414,6 @@ def confirm_edit(
414414
edit_with_reason["user"] = self.user
415415
edit_with_reason["change_event"] = "manual"
416416

417-
# Create timestamp that can be compared with datetime.now() running from users IDE
418-
tz = zoneinfo.ZoneInfo("Europe/Oslo")
419417
aware_timestamp = datetime.now(tz) # timezone-aware
420418
naive_timestamp = aware_timestamp.replace(tzinfo=None) # drop tzinfo
421419
edit_with_reason["timestamp"] = naive_timestamp
@@ -506,7 +504,10 @@ def immediate_edit(
506504
if not edited:
507505
raise PreventUpdate
508506
edit = edited[0]
509-
edit["timestamp"] = int(time.time() * 1000)
507+
508+
aware_timestamp = datetime.now(self.tz) # timezone-aware
509+
naive_timestamp = aware_timestamp.replace(tzinfo=None) # drop tzinfo
510+
edit["timestamp"] = naive_timestamp
510511
if self.log_filepath:
511512
with open(self.log_filepath, "a", encoding="utf-8") as f:
512513
f.write(

src/ssb_dash_framework/utils/prosesslogg.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
2-
32
import pandas as pd
3+
import warnings
44

55

66
def apply_edits(
@@ -39,6 +39,7 @@ def apply_edits(
3939
- Rows in `df` without matching uuids remain unchanged.
4040
- This function does not modify `df` in place; it returns an edited copy.
4141
"""
42+
4243
df_edited = df.copy()
4344
log = pd.read_json(filepath_log, lines=True)
4445
log = log.loc[log["timestamp"] > app_timestamp].copy()
@@ -63,9 +64,10 @@ def apply_edits(
6364
]
6465

6566
mapping = mapping[~mapping.index.duplicated(keep="last")]
66-
67-
df_edited.loc[df_edited["uuid"].isin(mapping.index), col] = (
68-
df_edited["uuid"].map(mapping).fillna(df_edited[col])
69-
)
67+
with warnings.catch_warnings():
68+
warnings.simplefilter("ignore", category=FutureWarning)
69+
df_edited.loc[df_edited["uuid"].isin(mapping.index), col] = (
70+
df_edited["uuid"].map(mapping).fillna(df_edited[col])
71+
)
7072

7173
return df_edited

0 commit comments

Comments
 (0)