Show More
@@ -206,8 +206,13 b' class SessionSettingsManager(SettingsMan' | |||||
206 | class DatabaseSettingsManager(SessionSettingsManager): |
|
206 | class DatabaseSettingsManager(SessionSettingsManager): | |
207 | def __init__(self, session): |
|
207 | def __init__(self, session): | |
208 | super().__init__(session) |
|
208 | super().__init__(session) | |
|
209 | ||||
|
210 | # First time a user accesses the server, his session is not saved | |||
|
211 | # and does not have the key yet. In order to create the settings object | |||
|
212 | # we need to save it manually | |||
209 | if not session.session_key: |
|
213 | if not session.session_key: | |
210 | session.save() |
|
214 | session.save() | |
|
215 | ||||
211 | self.settings, created = UserSettings.objects.get_or_create(session_key=session.session_key) |
|
216 | self.settings, created = UserSettings.objects.get_or_create(session_key=session.session_key) | |
212 |
|
217 | |||
213 | def add_fav_tag(self, tag): |
|
218 | def add_fav_tag(self, tag): | |
@@ -239,8 +244,9 b' class DatabaseSettingsManager(SessionSet' | |||||
239 |
|
244 | |||
240 | def get_settings_manager(request) -> SettingsManager: |
|
245 | def get_settings_manager(request) -> SettingsManager: | |
241 | """ |
|
246 | """ | |
242 |
Get settings manager based on the request object. Currently |
|
247 | Get settings manager based on the request object. Currently database-based | |
243 | session-based manager is supported. In the future, cookie-based or |
|
248 | settings manager is implemented over the session-based one (settings that | |
244 | database-based managers could be implemented. |
|
249 | are not connected to the database in any way are stored in session). Pure | |
|
250 | session-based manager is also supported but not used by default. | |||
245 | """ |
|
251 | """ | |
246 | return DatabaseSettingsManager(request.session) |
|
252 | return DatabaseSettingsManager(request.session) |
General Comments 0
You need to be logged in to leave comments.
Login now