From b4ca90188b222e82f7df4cfcea923e9daa0b68a5 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sat, 20 Nov 2021 11:38:45 +0300 Subject: [PATCH] favourite language id --- Main/context_processors.py | 3 ++- Main/models/userinfo.py | 1 + Main/views/AccountView.py | 6 ++++++ Main/views/TaskView.py | 1 - templates/account.html | 27 +++++++++++++++++++++++++++ templates/task.html | 2 +- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Main/context_processors.py b/Main/context_processors.py index 399c05f..b08cd29 100644 --- a/Main/context_processors.py +++ b/Main/context_processors.py @@ -1,5 +1,6 @@ from Sprint.settings import CONSTS +from SprintLib.language import languages def attributes(request): - return CONSTS + return {**CONSTS, "languages": sorted(languages, key=lambda x: x.name)} diff --git a/Main/models/userinfo.py b/Main/models/userinfo.py index 0f07cd3..5323784 100644 --- a/Main/models/userinfo.py +++ b/Main/models/userinfo.py @@ -15,6 +15,7 @@ class UserInfo(models.Model): middle_name = models.TextField() last_request = models.DateTimeField(default=timezone.now) profile_picture_fs_id = models.IntegerField(null=True) + favourite_language_id = models.IntegerField(null=True) rating = models.IntegerField(default=0) user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) telegram_chat_id = models.TextField(default="") diff --git a/Main/views/AccountView.py b/Main/views/AccountView.py index deb8c2e..66dae2a 100644 --- a/Main/views/AccountView.py +++ b/Main/views/AccountView.py @@ -27,6 +27,12 @@ class AccountView(BaseView): self.request.user.userinfo.save() return "/account" + def post_set_language(self): + lang_id = self.request.POST["language"] + self.request.user.userinfo.favourite_language_id = lang_id if lang_id != -1 else None + self.request.user.userinfo.save() + return "/account" + def post_change_password(self): password = self.request.POST["password"].strip() new_password = self.request.POST["new_password"].strip() diff --git a/Main/views/TaskView.py b/Main/views/TaskView.py index aeae5e3..dd70dff 100644 --- a/Main/views/TaskView.py +++ b/Main/views/TaskView.py @@ -13,7 +13,6 @@ class TaskView(BaseView): view_file = "task.html" def get(self): - self.context["languages"] = sorted(languages, key=lambda x: x.name) progress, _ = Progress.objects.get_or_create( user=self.request.user, task=self.entities.task ) diff --git a/templates/account.html b/templates/account.html index 3e7585e..eaaa599 100644 --- a/templates/account.html +++ b/templates/account.html @@ -74,6 +74,33 @@

{{ account.date_joined.date }}

+ + +

+ +
+ + {% if owner %} +
+ {% csrf_token %} + + +
+ {% else %} + {% if account.favourite_language_id %} + yes + {% else %} + no + {% endif %} + {% endif %} + + + diff --git a/templates/task.html b/templates/task.html index fab20c3..158bd99 100644 --- a/templates/task.html +++ b/templates/task.html @@ -121,7 +121,7 @@