Add the timezone property to app
It will make it easier to get a default time zone.
This commit is contained in:
		| @@ -111,19 +111,18 @@ class User(db.Model, UserMixin): | ||||
|     @property | ||||
|     def timezone(self): | ||||
|         from flask import current_app | ||||
|         from pytz import timezone, UTC | ||||
|         from pytz import timezone | ||||
|         from pytz.exceptions import UnknownTimeZoneError | ||||
|  | ||||
|         timezone_str = self.settings['timezone'] | ||||
|  | ||||
|         if not timezone_str: | ||||
|             timezone_str = current_app.settings.get('DEFAULT_TIMEZONE', 'UTC') | ||||
|         if timezone_str: | ||||
|             try: | ||||
|                 return timezone(timezone_str) | ||||
|             except UnknownTimeZoneError: | ||||
|                 warn(f'Timezone of {self} (or the default timezone) "{timezone_str}" is invalid') | ||||
|  | ||||
|         try: | ||||
|             return timezone(timezone_str) | ||||
|         except pytz.exceptions.UnknownTimeZoneError: | ||||
|             warn(f'Timezone of {user} (or the default timezone) "{timezone_str}" is invalid') | ||||
|             return UTC | ||||
|         return current_app.timezone | ||||
|  | ||||
|     def __repr__(self): | ||||
|         return f'<User {self.id}({self.username})>' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user