Compare commits

...

2 Commits

Author SHA1 Message Date
jordi fita mas 1fdbf56aa7 Translate the day name in template.dayofWeek 2025-01-29 12:10:12 +01:00
jordi fita mas 79eee41365 Fix update of weather_forecast
The real problem was that i was trying to update the forecast via
pgx.Pool, not the acquired connection, therefore it did not have the
correct role.

I moved everything to a different function where db is not visible in
scope, just to make sure i did not fuck up anywhere else.
2025-01-29 12:07:29 +01:00
2 changed files with 7 additions and 4 deletions

View File

@ -42,13 +42,16 @@ func main() {
log.Fatal(err)
}
defer conn.Release()
updateForecast(context.Background(), conn)
}
if _, err := conn.Exec(context.Background(), "set role to admin"); err != nil {
func updateForecast(ctx context.Context, conn *database.Conn) {
if _, err := conn.Exec(ctx, "set role to admin"); err != nil {
log.Fatal(err)
}
var stationURL string
if err := conn.QueryRow(context.Background(), `
if err := conn.QueryRow(ctx, `
select station_uri
from weather_forecast
`).Scan(
@ -68,7 +71,7 @@ func main() {
}
for _, forecast := range result.Forecasts {
if _, err := db.Exec(context.Background(), `
if _, err := conn.Exec(ctx, `
update weather_forecast
set weather_condition_id = $1
, day_temperature = $2

View File

@ -121,7 +121,7 @@ func mustRenderLayout(w io.Writer, user *auth.User, company *auth.Company, templ
return FormatPrice(price, user.Locale.Language, user.Locale.CurrencyPattern, company.DecimalDigits, company.CurrencySymbol)
},
"dayOfWeek": func(time time.Time) template.HTML {
return template.HTML(`<time datetime="` + time.Format(database.ISODateFormat) + `">` + LongDayNames[time.Weekday()] + "</time>")
return template.HTML(`<time datetime="` + time.Format(database.ISODateFormat) + `">` + user.Locale.GetC(LongDayNames[time.Weekday()], "day") + "</time>")
},
"formatDate": func(time time.Time) template.HTML {
return template.HTML(`<time datetime="` + time.Format(database.ISODateFormat) + `">` + time.Format("02/01/2006") + "</time>")