[importers] Fix setting timezones before all imports
This commit is contained in:
@ -115,6 +115,28 @@ class UserProfile(TimeStampedModel):
|
||||
|
||||
return timestamp.replace(tzinfo=timezone)
|
||||
|
||||
def adjust_timezone_of_scrobbles(self, commit=False):
|
||||
current_dt = None
|
||||
scrobbles_to_change_qs_list = []
|
||||
for boundry_dt in self.historic_timezone_changes:
|
||||
if current_dt and boundry_dt:
|
||||
logger.info(
|
||||
f"Checking for scrobbles between {current_dt} and {boundry_dt} to update to {current_dt.tzinfo.name}"
|
||||
)
|
||||
scrobbles = self.user.scrobble_set.filter(
|
||||
timestamp__gte=current_dt,
|
||||
timestamp__lt=boundry_dt,
|
||||
).exclude(timezone=current_dt.tzinfo.name)
|
||||
scrobbles_to_change_qs_list.append(scrobbles)
|
||||
logger.info(
|
||||
f"Updating {scrobbles.count()} scrobble timezones to {current_dt.tzinfo.name}"
|
||||
)
|
||||
if commit:
|
||||
scrobbles.update(timezone=current_dt.tzinfo.name)
|
||||
|
||||
current_dt = boundry_dt
|
||||
return scrobbles_to_change_qs_list
|
||||
|
||||
@cached_property
|
||||
def task_context_tags(self) -> list[str]:
|
||||
tag_list = [
|
||||
|
||||
Reference in New Issue
Block a user