From b57a455b3e794fba112f93343c44e647378535c7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jan 2018 10:05:14 +0300 Subject: [PATCH] user out_key --- access/migrations/0001_initial.py | 3 ++- access/migrations/0003_auto_20180115_1953.py | 20 ------------------ access/migrations/0004_auto_20180117_1558.py | 20 ------------------ access/models/user.py | 1 + access/serializers.py | 6 +++--- achievements/migrations/0001_initial.py | 4 ++-- courses/migrations/0001_initial.py | 2 +- csv/load_comments.py | 4 ++-- finance/migrations/0001_initial.py | 2 +- library/migrations/0001_initial.py | 2 +- storage/api.py | 6 +++--- storage/migrations/0001_initial.py | 4 ++-- storage/models.py | 2 +- storage/tests.py | 22 +++++++++++--------- 14 files changed, 31 insertions(+), 67 deletions(-) delete mode 100644 access/migrations/0003_auto_20180115_1953.py delete mode 100644 access/migrations/0004_auto_20180117_1558.py diff --git a/access/migrations/0001_initial.py b/access/migrations/0001_initial.py index ebe5f42..6342099 100644 --- a/access/migrations/0001_initial.py +++ b/access/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals import access.models.user @@ -28,6 +28,7 @@ class Migration(migrations.Migration): ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), ('out_key', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='Токен')), + ('in_key', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='Токен')), ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')), ('first_name', models.CharField(blank=True, default='Гость', max_length=63, verbose_name='first name')), ('last_name', models.CharField(blank=True, max_length=63, verbose_name='last name')), diff --git a/access/migrations/0003_auto_20180115_1953.py b/access/migrations/0003_auto_20180115_1953.py deleted file mode 100644 index 1b40b47..0000000 --- a/access/migrations/0003_auto_20180115_1953.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 19:53 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('access', '0002_init_group'), - ] - - operations = [ - migrations.AlterField( - model_name='progresslesson', - name='date', - field=models.DateTimeField(auto_now_add=True, verbose_name='Дата зачтения задания'), - ), - ] diff --git a/access/migrations/0004_auto_20180117_1558.py b/access/migrations/0004_auto_20180117_1558.py deleted file mode 100644 index 1491d22..0000000 --- a/access/migrations/0004_auto_20180117_1558.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-17 15:58 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('access', '0003_auto_20180115_1953'), - ] - - operations = [ - migrations.AlterField( - model_name='progresslesson', - name='date', - field=models.DateTimeField(blank=True, null=True, verbose_name='Дата зачтения задания'), - ), - ] diff --git a/access/models/user.py b/access/models/user.py index 207e2af..7fdb720 100644 --- a/access/models/user.py +++ b/access/models/user.py @@ -94,6 +94,7 @@ class CustomUserManager(BaseUserManager): class User(AbstractBaseUser, PermissionsMixin): out_key = models.UUIDField(verbose_name="Токен", default=uuid.uuid4, editable=False) + in_key = models.UUIDField(verbose_name="Токен", default=uuid.uuid4, editable=False) email = models.EmailField(_('email address'), unique=True) first_name = models.CharField(_('first name'), max_length=63, blank=True, default='Гость') last_name = models.CharField(_('last name'), max_length=63, blank=True) diff --git a/access/serializers.py b/access/serializers.py index 94232b0..e051e24 100644 --- a/access/serializers.py +++ b/access/serializers.py @@ -52,7 +52,7 @@ class UserSelfSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() - fields = ('id', 'email', 'first_name', 'last_name', 'progress', 'achievements', + fields = ('out_key', 'email', 'first_name', 'last_name', 'progress', 'achievements', 'account', 'groups', 'is_staff', 'is_superuser', 'diplomas', 'is_active') @staticmethod @@ -83,7 +83,7 @@ class UserProfileSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() fields = ( - 'id', 'email', 'first_name', 'last_name', + 'out_key', 'email', 'first_name', 'last_name', 'account', 'groups', 'is_staff', 'is_superuser', ) @@ -102,7 +102,7 @@ class UserSearchSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() - fields = ('id', 'email', 'first_name', 'last_name', 'phone', 'pay') + fields = ('out_key', 'email', 'first_name', 'last_name', 'phone', 'pay') @staticmethod def get_phone(self): diff --git a/achievements/migrations/0001_initial.py b/achievements/migrations/0001_initial.py index 7c0edd4..b482f53 100644 --- a/achievements/migrations/0001_initial.py +++ b/achievements/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals from django.conf import settings @@ -12,8 +12,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('courses', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('courses', '0001_initial'), ] operations = [ diff --git a/courses/migrations/0001_initial.py b/courses/migrations/0001_initial.py index bcf0023..290ab1e 100644 --- a/courses/migrations/0001_initial.py +++ b/courses/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals import django.contrib.postgres.fields diff --git a/csv/load_comments.py b/csv/load_comments.py index 0538e54..609e5bb 100644 --- a/csv/load_comments.py +++ b/csv/load_comments.py @@ -55,8 +55,8 @@ if __name__ == '__main__': if not file == ''] comment = Comment.objects.create( - text=row['text'], - email=row['owner__email'], + text=row['text'] or row['bb_text'], + out_key=get_user_model().objects.get(email=row['owner__email']).out_key, ) if row['status'] == 'Одобренно': diff --git a/finance/migrations/0001_initial.py b/finance/migrations/0001_initial.py index 062533b..f644838 100644 --- a/finance/migrations/0001_initial.py +++ b/finance/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals from django.conf import settings diff --git a/library/migrations/0001_initial.py b/library/migrations/0001_initial.py index 2158001..7d71d43 100644 --- a/library/migrations/0001_initial.py +++ b/library/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals import datetime diff --git a/storage/api.py b/storage/api.py index 0624c47..8b8e586 100644 --- a/storage/api.py +++ b/storage/api.py @@ -13,10 +13,10 @@ def upload_file(original=None, name=None, base64=None) -> File: return new_file -def add_comment(text: str, email: str, files=None) -> Comment: +def add_comment(text: str, out_key: str, files=None) -> Comment: """ :param text: sting - :param email: string + :param out_key: string :param files: {name?: string, original?: File, base64?: string}[] одно из двух последних свойств должно быть указано :return: Comment """ @@ -25,7 +25,7 @@ def add_comment(text: str, email: str, files=None) -> Comment: comment = Comment.objects.create( text=text, - email=email, + user_key=out_key, ) for file in files: diff --git a/storage/migrations/0001_initial.py b/storage/migrations/0001_initial.py index 70e15bd..1689788 100644 --- a/storage/migrations/0001_initial.py +++ b/storage/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2018-01-15 17:54 +# Generated by Django 1.11.6 on 2018-01-22 09:27 from __future__ import unicode_literals from django.db import migrations, models @@ -18,7 +18,7 @@ class Migration(migrations.Migration): name='Comment', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('email', models.CharField(max_length=63, verbose_name='email автора')), + ('user_key', models.UUIDField(editable=False, verbose_name='Ссылка на юзера')), ('text', models.TextField(default='', verbose_name='Текст комментария')), ('token', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='Ключ')), ('date', models.DateTimeField(auto_now_add=True, verbose_name='Дата коментария')), diff --git a/storage/models.py b/storage/models.py index b76bb72..f2b12b3 100755 --- a/storage/models.py +++ b/storage/models.py @@ -36,7 +36,7 @@ class File(models.Model): class Comment(models.Model): - email = models.CharField(verbose_name="email автора", max_length=63) + user_key = models.UUIDField(verbose_name="Ссылка на юзера", editable=False) text = models.TextField(default="", verbose_name="Текст комментария") files = models.ManyToManyField(to=File, blank=True, verbose_name='Файлы') token = models.UUIDField(verbose_name="Ключ", default=uuid.uuid4, editable=False) diff --git a/storage/tests.py b/storage/tests.py index 1e1c0a0..aa9ad8c 100644 --- a/storage/tests.py +++ b/storage/tests.py @@ -1,4 +1,4 @@ -import tempfile +import uuid from django.test import TestCase from storage.api import add_comment, delete_comment, update_comment, get_comment @@ -10,8 +10,10 @@ from storage.models import Comment class CommentTestCase(TestCase): def setUp(self): - self.first_comment = add_comment("first comment", "vasia@rambler.ru") - self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") + self.f_k = uuid.uuid4() + self.s_k = uuid.uuid4() + self.first_comment = add_comment("first comment", self.f_k) + self.second_comment = add_comment(text="Привет, отличная работа", out_key=self.s_k) def tearDown(self): Comment.objects.all().delete() @@ -25,9 +27,9 @@ class CommentTestCase(TestCase): self.assertEqual(get_comment(self.first_comment.token).text, new_text) # def test_comment_create(self): - # token = 'fskjfskj' - # comment1 = add_comment(text=token, email="artem4000@gmail.com") - # self.assertEqual(comment1.text, token) + # text = 'fskjfskj' + # comment1 = add_comment(text=text, out_key=uuid.uuid4()) + # self.assertEqual(comment1.text, text) # with tempfile.gettempdir() as dir_path: # file_for_upload = SimpleUploadedFile(dir_path + '/1.txt', 'Я файл!'.encode('utf-8')) # file_name = 'Клёвый файл' @@ -48,8 +50,8 @@ class CommentTestCase(TestCase): class FileTestCase(TestCase): def setUp(self): - self.first_comment = add_comment("first comment", "vasia@rambler.ru") - self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") + self.first_comment = add_comment("first comment", uuid.uuid4()) + self.second_comment = add_comment(text="Привет, отличная работа", out_key=uuid.uuid4()) def test_comment_get(self): self.assertEqual(self.first_comment, get_comment(self.first_comment.token)) @@ -61,12 +63,12 @@ class FileTestCase(TestCase): def test_comment_create(self): token = 'fskjfskj' - comment1 = add_comment(text=token, email="artem4000@gmail.com") + comment1 = add_comment(text=token, out_key=uuid.uuid4()) self.assertEqual(comment1.text, token) file_for_upload = SimpleUploadedFile('1.txt', 'Я файл!'.encode('utf-8')) file_name = 'Клёвый файл' object_for_upload = {'original': file_for_upload, 'name': file_name} - comment2 = add_comment(text=token, email="artem4000@gmail.com", files=[object_for_upload]) + comment2 = add_comment(text=token, out_key=uuid.uuid4(), files=[object_for_upload]) self.assertEqual(comment2.files.count(), 1) self.assertEqual(comment2.files.all()[0].name, file_name)