user out_key

feature/fix_generate_pass
Andrey 8 years ago
parent fc56aa9dd3
commit b57a455b3e
  1. 3
      access/migrations/0001_initial.py
  2. 20
      access/migrations/0003_auto_20180115_1953.py
  3. 20
      access/migrations/0004_auto_20180117_1558.py
  4. 1
      access/models/user.py
  5. 6
      access/serializers.py
  6. 4
      achievements/migrations/0001_initial.py
  7. 2
      courses/migrations/0001_initial.py
  8. 4
      csv/load_comments.py
  9. 2
      finance/migrations/0001_initial.py
  10. 2
      library/migrations/0001_initial.py
  11. 6
      storage/api.py
  12. 4
      storage/migrations/0001_initial.py
  13. 2
      storage/models.py
  14. 22
      storage/tests.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
import access.models.user import access.models.user
@ -28,6 +28,7 @@ class Migration(migrations.Migration):
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('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')), ('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='Токен')), ('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')), ('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')), ('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')), ('last_name', models.CharField(blank=True, max_length=63, verbose_name='last name')),

@ -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='Дата зачтения задания'),
),
]

@ -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='Дата зачтения задания'),
),
]

@ -94,6 +94,7 @@ class CustomUserManager(BaseUserManager):
class User(AbstractBaseUser, PermissionsMixin): class User(AbstractBaseUser, PermissionsMixin):
out_key = models.UUIDField(verbose_name="Токен", default=uuid.uuid4, editable=False) 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) email = models.EmailField(_('email address'), unique=True)
first_name = models.CharField(_('first name'), max_length=63, blank=True, default='Гость') first_name = models.CharField(_('first name'), max_length=63, blank=True, default='Гость')
last_name = models.CharField(_('last name'), max_length=63, blank=True) last_name = models.CharField(_('last name'), max_length=63, blank=True)

@ -52,7 +52,7 @@ class UserSelfSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = get_user_model() 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') 'account', 'groups', 'is_staff', 'is_superuser', 'diplomas', 'is_active')
@staticmethod @staticmethod
@ -83,7 +83,7 @@ class UserProfileSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = get_user_model() model = get_user_model()
fields = ( fields = (
'id', 'email', 'first_name', 'last_name', 'out_key', 'email', 'first_name', 'last_name',
'account', 'groups', 'is_staff', 'is_superuser', 'account', 'groups', 'is_staff', 'is_superuser',
) )
@ -102,7 +102,7 @@ class UserSearchSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = get_user_model() model = get_user_model()
fields = ('id', 'email', 'first_name', 'last_name', 'phone', 'pay') fields = ('out_key', 'email', 'first_name', 'last_name', 'phone', 'pay')
@staticmethod @staticmethod
def get_phone(self): def get_phone(self):

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
from django.conf import settings from django.conf import settings
@ -12,8 +12,8 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('courses', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('courses', '0001_initial'),
] ]
operations = [ operations = [

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
import django.contrib.postgres.fields import django.contrib.postgres.fields

@ -55,8 +55,8 @@ if __name__ == '__main__':
if not file == ''] if not file == '']
comment = Comment.objects.create( comment = Comment.objects.create(
text=row['text'], text=row['text'] or row['bb_text'],
email=row['owner__email'], out_key=get_user_model().objects.get(email=row['owner__email']).out_key,
) )
if row['status'] == 'Одобренно': if row['status'] == 'Одобренно':

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
from django.conf import settings from django.conf import settings

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
import datetime import datetime

@ -13,10 +13,10 @@ def upload_file(original=None, name=None, base64=None) -> File:
return new_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 text: sting
:param email: string :param out_key: string
:param files: {name?: string, original?: File, base64?: string}[] одно из двух последних свойств должно быть указано :param files: {name?: string, original?: File, base64?: string}[] одно из двух последних свойств должно быть указано
:return: Comment :return: Comment
""" """
@ -25,7 +25,7 @@ def add_comment(text: str, email: str, files=None) -> Comment:
comment = Comment.objects.create( comment = Comment.objects.create(
text=text, text=text,
email=email, user_key=out_key,
) )
for file in files: for file in files:

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
@ -18,7 +18,7 @@ class Migration(migrations.Migration):
name='Comment', name='Comment',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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='Текст комментария')), ('text', models.TextField(default='', verbose_name='Текст комментария')),
('token', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='Ключ')), ('token', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='Ключ')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Дата коментария')), ('date', models.DateTimeField(auto_now_add=True, verbose_name='Дата коментария')),

@ -36,7 +36,7 @@ class File(models.Model):
class Comment(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="Текст комментария") text = models.TextField(default="", verbose_name="Текст комментария")
files = models.ManyToManyField(to=File, blank=True, verbose_name='Файлы') files = models.ManyToManyField(to=File, blank=True, verbose_name='Файлы')
token = models.UUIDField(verbose_name="Ключ", default=uuid.uuid4, editable=False) token = models.UUIDField(verbose_name="Ключ", default=uuid.uuid4, editable=False)

@ -1,4 +1,4 @@
import tempfile import uuid
from django.test import TestCase from django.test import TestCase
from storage.api import add_comment, delete_comment, update_comment, get_comment from storage.api import add_comment, delete_comment, update_comment, get_comment
@ -10,8 +10,10 @@ from storage.models import Comment
class CommentTestCase(TestCase): class CommentTestCase(TestCase):
def setUp(self): def setUp(self):
self.first_comment = add_comment("first comment", "vasia@rambler.ru") self.f_k = uuid.uuid4()
self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") 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): def tearDown(self):
Comment.objects.all().delete() Comment.objects.all().delete()
@ -25,9 +27,9 @@ class CommentTestCase(TestCase):
self.assertEqual(get_comment(self.first_comment.token).text, new_text) self.assertEqual(get_comment(self.first_comment.token).text, new_text)
# def test_comment_create(self): # def test_comment_create(self):
# token = 'fskjfskj' # text = 'fskjfskj'
# comment1 = add_comment(text=token, email="artem4000@gmail.com") # comment1 = add_comment(text=text, out_key=uuid.uuid4())
# self.assertEqual(comment1.text, token) # self.assertEqual(comment1.text, text)
# with tempfile.gettempdir() as dir_path: # with tempfile.gettempdir() as dir_path:
# file_for_upload = SimpleUploadedFile(dir_path + '/1.txt', 'Я файл!'.encode('utf-8')) # file_for_upload = SimpleUploadedFile(dir_path + '/1.txt', 'Я файл!'.encode('utf-8'))
# file_name = 'Клёвый файл' # file_name = 'Клёвый файл'
@ -48,8 +50,8 @@ class CommentTestCase(TestCase):
class FileTestCase(TestCase): class FileTestCase(TestCase):
def setUp(self): def setUp(self):
self.first_comment = add_comment("first comment", "vasia@rambler.ru") self.first_comment = add_comment("first comment", uuid.uuid4())
self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") self.second_comment = add_comment(text="Привет, отличная работа", out_key=uuid.uuid4())
def test_comment_get(self): def test_comment_get(self):
self.assertEqual(self.first_comment, get_comment(self.first_comment.token)) self.assertEqual(self.first_comment, get_comment(self.first_comment.token))
@ -61,12 +63,12 @@ class FileTestCase(TestCase):
def test_comment_create(self): def test_comment_create(self):
token = 'fskjfskj' 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) self.assertEqual(comment1.text, token)
file_for_upload = SimpleUploadedFile('1.txt', 'Я файл!'.encode('utf-8')) file_for_upload = SimpleUploadedFile('1.txt', 'Я файл!'.encode('utf-8'))
file_name = 'Клёвый файл' file_name = 'Клёвый файл'
object_for_upload = {'original': file_for_upload, 'name': 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.count(), 1)
self.assertEqual(comment2.files.all()[0].name, file_name) self.assertEqual(comment2.files.all()[0].name, file_name)

Loading…
Cancel
Save