def prev_step_get(self, index): # type: (str) -> Update prev_steps = TtbPrevStep.objects.filter(index=index) if prev_steps.exists() and isinstance(prev_steps[0], TtbPrevStep): update = self.deserialize_update(prev_steps[0].update) TtbUser.update_or_create_by_update(UpdateCmn(update, self)) return update
def set_user_language_by_update(self, update, language): # type: (Update, str) -> None language = language or self.get_default_language() update = UpdateCmn(update) if update: ttb_user, created = TtbUser.update_or_create_by_update(update) if isinstance(ttb_user, TtbUser): ttb_user.language = language ttb_user.save()
def get_user_language_by_update(self, update): # type: (Update) -> str language = self.get_default_language() update = UpdateCmn(update) if update: ttb_user, created = TtbUser.update_or_create_by_update(update) if isinstance(ttb_user, TtbUser): language = ttb_user.language or self.get_default_language() return language
def get_user_language_by_update(self, update): # type: (Update) -> str update = UpdateCmn(update, self) language = update.user_locale or self.get_default_language() if language[:2] not in self.languages_dict.keys(): language = self.get_default_language() if update: ttb_user, created = TtbUser.update_or_create_by_update(update) if isinstance(ttb_user, TtbUser): language = ttb_user.language or language return language
def prev_step_write(self, index, update): # type: (str, Update) -> None if not self.prev_step_exists(index): b_obj = self.serialize_update(update) ttb_user, created = TtbUser.update_or_create_by_update( UpdateCmn(update, self)) if isinstance(ttb_user, TtbUser): TtbPrevStep.objects.update_or_create(index=index, defaults={ 'user': ttb_user, 'update': b_obj, 'updated': now() })
def set_user_language_by_update(self, update, language, soft_setting=False): # type: (Update, str, bool) -> None update = UpdateCmn(update, self) language = language or self.get_default_language() if language[:2] not in self.languages_dict.keys(): language = self.get_default_language() if update: ttb_user, created = TtbUser.update_or_create_by_update(update) if isinstance(ttb_user, TtbUser): if ttb_user.language: if not soft_setting: ttb_user.language = language else: ttb_user.language = language ttb_user.save()