csharp
This commit is contained in:
parent
1e975a4659
commit
6b6caffcff
22
Main/migrations/0076_auto_20211119_2050.py
Normal file
22
Main/migrations/0076_auto_20211119_2050.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.2.4 on 2021-11-19 17:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('Main', '0075_auto_20211110_2317'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='userinfo',
|
||||
name='profile_picture',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='userinfo',
|
||||
name='profile_picture_fs_id',
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
]
|
@ -27,6 +27,7 @@ class Progress(models.Model):
|
||||
delta = timedelta(minutes=self.task.time_estimation)
|
||||
self.score = int(delta / self.time * 100)
|
||||
self.save()
|
||||
self.user.userinfo.refresh_from_db()
|
||||
self.user.userinfo.rating += self.score
|
||||
self.user.userinfo.save()
|
||||
|
||||
|
@ -2,9 +2,9 @@ from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from Main.models.subscription import Subscription
|
||||
from Main.models.group import Group
|
||||
from Main.models.settask import SetTask
|
||||
from Main.models.subscription import Subscription
|
||||
from Main.models.task import Task
|
||||
from Sprint.settings import CONSTS
|
||||
|
||||
@ -14,7 +14,7 @@ class UserInfo(models.Model):
|
||||
name = models.TextField()
|
||||
middle_name = models.TextField()
|
||||
last_request = models.DateTimeField(default=timezone.now)
|
||||
profile_picture = models.ImageField(upload_to="profile_pictures", null=True)
|
||||
profile_picture_fs_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="")
|
||||
@ -59,14 +59,14 @@ class UserInfo(models.Model):
|
||||
@property
|
||||
def has_profile_pic(self):
|
||||
try:
|
||||
return self.profile_picture.url is not None
|
||||
return self.profile_picture_fs_id is not None
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
@property
|
||||
def profile_pic_url(self):
|
||||
if self.has_profile_pic:
|
||||
return self.profile_picture.url
|
||||
return "/image?id=" + str(self.profile_picture_fs_id)
|
||||
return "https://i2.wp.com/electrolabservice.com/wp-content/uploads/2021/01/blank-profile-picture-mystery-man-avatar-973460.jpg"
|
||||
|
||||
def __str__(self):
|
||||
|
@ -2,6 +2,7 @@ from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from SprintLib.BaseView import BaseView
|
||||
from SprintLib.utils import delete_file, write_bytes
|
||||
|
||||
|
||||
class AccountView(BaseView):
|
||||
@ -19,8 +20,10 @@ class AccountView(BaseView):
|
||||
self.context["error_message"] = self.request.GET.get("error_message", "")
|
||||
|
||||
def post_upload_photo(self):
|
||||
self.request.user.userinfo.profile_picture.delete()
|
||||
self.request.user.userinfo.profile_picture = self.request.FILES["file"]
|
||||
if self.request.user.userinfo.has_profile_pic:
|
||||
delete_file(self.request.user.userinfo.profile_picture_fs_id)
|
||||
fs_id = write_bytes(self.request.FILES["file"].read())
|
||||
self.request.user.userinfo.profile_picture_fs_id = fs_id
|
||||
self.request.user.userinfo.save()
|
||||
return "/account"
|
||||
|
||||
|
9
Main/views/ImageView.py
Normal file
9
Main/views/ImageView.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.http import HttpResponse
|
||||
|
||||
from SprintLib.BaseView import BaseView
|
||||
from SprintLib.utils import get_bytes
|
||||
|
||||
|
||||
class ImageView(BaseView):
|
||||
def get(self):
|
||||
return HttpResponse(get_bytes(int(self.request.GET['id'])), content_type="image/jpg")
|
@ -11,3 +11,4 @@ from Main.views.TaskView import TaskView
|
||||
from Main.views.SolutionsTableView import SolutionsTableView
|
||||
from Main.views.TaskRuntimeView import TaskRuntimeView
|
||||
from Main.views.SolutionView import SolutionView
|
||||
from Main.views.ImageView import ImageView
|
||||
|
@ -17,6 +17,7 @@ urlpatterns = [
|
||||
path("solution", SolutionView.as_view()),
|
||||
path("solutions_table", SolutionsTableView.as_view()),
|
||||
path("task_runtime", TaskRuntimeView.as_view()),
|
||||
path("image", ImageView.as_view()),
|
||||
path("", MainView.as_view()),
|
||||
path("admin/", admin.site.urls),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from os import listdir, getcwd
|
||||
from os import listdir
|
||||
|
||||
from SprintLib.testers.BaseTester import BaseTester, TestException
|
||||
|
||||
@ -7,13 +7,11 @@ class Python3Tester(BaseTester):
|
||||
file = None
|
||||
|
||||
def before_test(self):
|
||||
print(getcwd())
|
||||
for file in listdir(self.solution.testing_directory):
|
||||
if file.endswith(".py"):
|
||||
self.file = file
|
||||
break
|
||||
if self.file is None:
|
||||
print('no file')
|
||||
raise TestException("TE")
|
||||
|
||||
@property
|
||||
|
Loading…
Reference in New Issue
Block a user