mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-25 16:53:59 +01:00
use current month for last_updated value
This commit is contained in:
parent
f1384b72f2
commit
621db6ad2c
2 changed files with 8 additions and 7 deletions
12
main.py
12
main.py
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
import time
|
||||
from calendar import timegm
|
||||
from datetime import date
|
||||
|
||||
from fastapi import Depends, FastAPI, Response
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
@ -46,7 +47,7 @@ async def list_items(db: Session = Depends(get_db)):
|
|||
@app.put("/api/items/{id}")
|
||||
async def put_item(id: str, item: Item, db: Session = Depends(get_db)):
|
||||
if item.last_updated is None:
|
||||
item.last_updated = rough_timestamp()
|
||||
item.last_updated = month_timestamp()
|
||||
if crud.put_item(db, id, item) == crud.PutItemResult.UPDATED:
|
||||
return Response(b"", status_code=204)
|
||||
return Response(b"", status_code=201)
|
||||
|
@ -57,10 +58,9 @@ async def delete_item(id: str, db: Session = Depends(get_db)):
|
|||
crud.delete_item(db, id)
|
||||
|
||||
|
||||
def rough_timestamp() -> int:
|
||||
"""Provides an current timestamp with reduced resolution, to improve anonymity."""
|
||||
granularity = 2**20 # about 12 days
|
||||
return int(time.time()) // granularity * granularity
|
||||
def month_timestamp() -> int:
|
||||
"""Provides the timestamp of the current month's beginning (for improved privacy)"""
|
||||
return timegm(date.today().replace(day=1).timetuple())
|
||||
|
||||
|
||||
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
||||
|
|
|
@ -176,5 +176,6 @@ function formCoordsToMap() {
|
|||
|
||||
function formatTimestamp(ts) {
|
||||
const date = new Date(ts * 1000);
|
||||
return date.toLocaleDateString();
|
||||
// using Swedish format as a hack to get an iso formatted date
|
||||
return date.toLocaleDateString("sv", {timeZone: "UTC"}).replace(/\-\d+$/,'')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue