From 1715657ff56616321c9db68c74588f1e7106beb1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 6 Nov 2017 19:40:19 +0300 Subject: [PATCH] finance update --- access/init_group.py | 1 + access/migrations/0007_auto_20171106_1808.py | 19 +++ access/models.py | 4 +- access/views.py | 4 +- csv/load_bills.py | 24 +++- csv/load_student_teachers_threads.py | 14 +++ finance/migrations/0003_auto_20171106_1723.py | 25 ++++ finance/migrations/0004_auto_20171106_1723.py | 25 ++++ finance/models.py | 4 +- journals/default_threads.py | 112 +++++++++--------- .../0008_remove_journal_children.py | 19 +++ journals/models.py | 6 +- journals/serilizers.py | 2 +- 13 files changed, 190 insertions(+), 69 deletions(-) create mode 100644 access/migrations/0007_auto_20171106_1808.py create mode 100644 csv/load_student_teachers_threads.py create mode 100644 finance/migrations/0003_auto_20171106_1723.py create mode 100644 finance/migrations/0004_auto_20171106_1723.py create mode 100644 journals/migrations/0008_remove_journal_children.py diff --git a/access/init_group.py b/access/init_group.py index 8f9703b..79cf9bd 100644 --- a/access/init_group.py +++ b/access/init_group.py @@ -8,6 +8,7 @@ django.setup() from django.contrib.auth.models import Group if __name__ == '__main__': + Group.objects.get_or_create(name='admin') Group.objects.get_or_create(name='students') Group.objects.get_or_create(name='teachers') Group.objects.get_or_create(name='managers') diff --git a/access/migrations/0007_auto_20171106_1808.py b/access/migrations/0007_auto_20171106_1808.py new file mode 100644 index 0000000..73c0d87 --- /dev/null +++ b/access/migrations/0007_auto_20171106_1808.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-11-06 18:08 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('access', '0006_auto_20171019_1243'), + ] + + operations = [ + migrations.AlterModelOptions( + name='user', + options={'verbose_name': 'Пользователь', 'verbose_name_plural': 'Пользователи'}, + ), + ] diff --git a/access/models.py b/access/models.py index a7135b1..0c1e67d 100755 --- a/access/models.py +++ b/access/models.py @@ -160,8 +160,8 @@ class User(AbstractBaseUser, PermissionsMixin): return self.first_name class Meta: - verbose_name = _('user') - verbose_name_plural = _('users') + verbose_name = _('Пользователь') + verbose_name_plural = _('Пользователи') class Progress(models.Model): diff --git a/access/views.py b/access/views.py index dbcc75b..e90549d 100644 --- a/access/views.py +++ b/access/views.py @@ -62,8 +62,8 @@ class FindUserView(APIView): res = res[:(count if len(res) > count else len(res))] - return Response([ - UserSearchSerializer(i).data for i in res], + return Response( + [UserSearchSerializer(i).data for i in res], status=self.status_code ) diff --git a/csv/load_bills.py b/csv/load_bills.py index e9efa4b..d1da97c 100644 --- a/csv/load_bills.py +++ b/csv/load_bills.py @@ -21,8 +21,28 @@ if __name__ == '__main__': opener_id = row.pop('opener__id', None) bill_kwarg['opener'] = get_user_model().objects.get(id=opener_id) if opener_id \ else get_user_model().objects.get(email="kate.gazukina@skillbox.ru") - bill_kwarg['user'] = get_user_model().objects.get(email=row.pop('user__email', None)) + + email = row.pop('user__email', None) + try: + email = email[:email.index("\n")] + except ValueError: + pass + + try: + bill_kwarg['user'] = get_user_model().objects.get(email=email.lower()) + except get_user_model().DoesNotExist: + print([email, bill_kwarg['id']]) + bill_kwarg['comment'] = row.pop('comment', None) bill_kwarg['description'] = row.pop('description', None) bill = Bill.objects.create(**bill_kwarg) - Invoice.objects.create(bill=bill, **row) \ No newline at end of file + try: + price = int(row.pop('price', None)) + except ValueError: + price = None + + try: + real_price = int(row.pop('real_price', None)) + except ValueError: + real_price = None + Invoice.objects.create(bill=bill, price=price, real_price=real_price, **row) \ No newline at end of file diff --git a/csv/load_student_teachers_threads.py b/csv/load_student_teachers_threads.py new file mode 100644 index 0000000..e86e184 --- /dev/null +++ b/csv/load_student_teachers_threads.py @@ -0,0 +1,14 @@ +import os, sys, django, csv + +sys.path.append("../") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") +django.setup() + +from library.models import Tags, ArticleSection, Article + +if __name__ == '__main__': + with open('./management/comment.csv') as comment_csv: + comment_reader = csv.DictReader(comment_csv) + for row in comment_reader: + if row['type'] == 'task': + print(row) \ No newline at end of file diff --git a/finance/migrations/0003_auto_20171106_1723.py b/finance/migrations/0003_auto_20171106_1723.py new file mode 100644 index 0000000..23e0268 --- /dev/null +++ b/finance/migrations/0003_auto_20171106_1723.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-11-06 17:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('finance', '0002_auto_20171023_1037'), + ] + + operations = [ + migrations.AlterField( + model_name='invoice', + name='price', + field=models.IntegerField(blank=True, max_length=255, null=True, verbose_name='Сумма'), + ), + migrations.AlterField( + model_name='invoice', + name='real_price', + field=models.IntegerField(blank=True, help_text='Сумма, минус комиссия', max_length=255, null=True, verbose_name='Полученная сумма'), + ), + ] diff --git a/finance/migrations/0004_auto_20171106_1723.py b/finance/migrations/0004_auto_20171106_1723.py new file mode 100644 index 0000000..378a4fb --- /dev/null +++ b/finance/migrations/0004_auto_20171106_1723.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-11-06 17:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('finance', '0003_auto_20171106_1723'), + ] + + operations = [ + migrations.AlterField( + model_name='invoice', + name='price', + field=models.IntegerField(blank=True, null=True, verbose_name='Сумма'), + ), + migrations.AlterField( + model_name='invoice', + name='real_price', + field=models.IntegerField(blank=True, help_text='Сумма, минус комиссия', null=True, verbose_name='Полученная сумма'), + ), + ] diff --git a/finance/models.py b/finance/models.py index 65df63e..4a328ae 100755 --- a/finance/models.py +++ b/finance/models.py @@ -39,8 +39,8 @@ class Invoice(models.Model): ('H', 'Сгорел') ) status = models.CharField(verbose_name='Статус', max_length=1, default='W', choices=BILL_STATUSES) - price = models.CharField(verbose_name='Сумма', max_length=255, null=True, blank=True) - real_price = models.CharField(verbose_name='Полученная сумма', max_length=255, null=True, blank=True, + price = models.IntegerField(verbose_name='Сумма', null=True, blank=True) + real_price = models.IntegerField(verbose_name='Полученная сумма', null=True, blank=True, help_text='Сумма, минус комиссия') bill_method = models.CharField(verbose_name='Способ оплаты', max_length=2, default='Y', choices=BILL_METHOD) key = models.CharField(verbose_name='Ключ платежа', blank=True, max_length=255, default='', editable=False) diff --git a/journals/default_threads.py b/journals/default_threads.py index 9918231..94998c9 100644 --- a/journals/default_threads.py +++ b/journals/default_threads.py @@ -6,74 +6,72 @@ django.setup() from journals.models import Thread -from django.contrib.auth import get_user_model +from django.contrib.auth.models import Group from lms.global_decorators import transaction_decorator @transaction_decorator def main_threads(): + Thread.objects.all().delete() - admin_thread, _is_create = Thread.objects.get_or_create( + admin_thread = Thread.objects.create( key='Admin', text='Тред для админов, сюда падают все журналируемые сообщения в системе', is_staff=True, + is_recurse=True, ) - for i in get_user_model().objects.filter(is_superuser=True): - admin_thread.subscribers.add(i) - - # management_thread, _is_create = Thread.objects.get_or_create( - # key='Project_management', - # text='Тред для проджект-менеджеров, сюда падает статистика разного рода', - # is_staff=True, - # ) - # - # management_thread.parent.add(admin_thread) - # - # support_thread, _is_create = Thread.objects.get_or_create( - # key='Support', - # text='Тред сапортов, занимаются поддержкой клиента', - # is_staff=True, - # ) - # - # for i in get_user_model().objects.filter(email__in=support_list): - # support_thread.subscribers.add(i) - # - # support_thread.parent.add(admin_thread) - # - # res['library_thread'], _is_create = Thread.objects.get_or_create( - # key='Library', - # text='Тред <<Библиотека>> сюда прилетает вся инфа по статьям', - # is_staff=True, - # ) - # - # res['library_thread'].parent.add(management_thread) - # - # course_thread, _is_create = Thread.objects.get_or_create( - # key='Course_thread', - # text='Тред курсов', - # is_staff=True, - # ) - # - # course_thread.parent.add(management_thread) - # - # start_and_end_thread, _is_create = Thread.objects.get_or_create( - # key='Start_and_end', - # text='Тред начала и завершения прохождения какого-либо этапа обучения', - # is_staff=True, - # ) - # - # start_and_end_thread.parent.add(course_thread) - # - # res['task_thread'], _is_create = Thread.objects.get_or_create( - # key='Tasks', - # text='Сюда пободают все переписки студентов и преподов', - # is_staff=True, - # ) - # - # res['task_thread'].parent.add(support_thread) - # - # return res + admin_thread.groups.add(Group.objects.get(name='admin')) + + management_thread = Thread.objects.create( + key='Project_management', + text='Тред для проджект-менеджеров, сюда падает статистика разного рода', + is_staff=True, + is_recurse=True, + ) + + management_thread.groups.add(Group.objects.get(name='project_managers')) + management_thread.parent.add(admin_thread) + + support_thread = Thread.objects.create( + key='Support', + text='Тред сапортов, занимаются поддержкой клиента', + is_staff=True, + is_recurse=True, + ) + + support_thread.groups.add(Group.objects.get(name='supports')) + support_thread.parent.add(admin_thread) + + lead_managers = Thread.objects.create( + key='Sale_lead', + text='Тред лидов, сейлзов', + is_staff=True, + is_recurse=True, + ) + + lead_managers.groups.add(Group.objects.get(name='lead_managers')) + lead_managers.parent.add(admin_thread) + + managers = Thread.objects.create( + key='Sale', + text='Тред сейлзов', + is_staff=True, + is_recurse=True, + ) + + managers.groups.add(Group.objects.get(name='managers')) + managers.parent.add(lead_managers) + + st_tch = Thread.objects.create( + key='Student_teacher', + text='Тред студентов и учителей', + is_staff=True, + is_recurse=True, + ) + + st_tch.parent.add(support_thread) + st_tch.parent.add(management_thread) if __name__ == '__main__': diff --git a/journals/migrations/0008_remove_journal_children.py b/journals/migrations/0008_remove_journal_children.py new file mode 100644 index 0000000..223b826 --- /dev/null +++ b/journals/migrations/0008_remove_journal_children.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-11-06 18:13 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0007_journal_files'), + ] + + operations = [ + migrations.RemoveField( + model_name='journal', + name='children', + ), + ] diff --git a/journals/models.py b/journals/models.py index b6f0ec8..ce07451 100755 --- a/journals/models.py +++ b/journals/models.py @@ -9,6 +9,7 @@ from django.db import models from courses.models import Achievements, Course, CourseMap, Diploma from finance.models import Bill +from storage.models import Storage ACTION_CHOICES = ( (0, 'try'), @@ -27,7 +28,6 @@ ACTION_CHOICES = ( ) -# Новое API class Journal(models.Model): thread = models.ForeignKey(to='Thread', verbose_name='Тред') user = models.ForeignKey( @@ -39,7 +39,7 @@ class Journal(models.Model): content_object = GenericForeignKey('content_type', 'object_id') action_type = models.SmallIntegerField(choices=ACTION_CHOICES) date = models.DateTimeField(auto_now=True) - children = models.ManyToManyField(to='self', blank=True, symmetrical=False) + files = models.ManyToManyField(to=Storage, blank=True) def __str__(self): return '%d Пользователь %s %s %s' % (self.id, self.user.email, self.get_action_type_display(), self.thread.key) @@ -47,7 +47,7 @@ class Journal(models.Model): class Thread(models.Model): key = models.CharField(max_length=200) - text = models.TextField(default='', verbose_name=u'Описание треда') + text = models.TextField(default='', verbose_name='Описание треда') is_staff = models.BooleanField(default=False, verbose_name='Админская ли табличка') is_recurse = models.BooleanField(default=False, verbose_name='Поле аптимизации поиска') subscribers = models.ManyToManyField(to=settings.AUTH_USER_MODEL, verbose_name='Подписчики', blank=True) diff --git a/journals/serilizers.py b/journals/serilizers.py index 439a278..65a18fa 100644 --- a/journals/serilizers.py +++ b/journals/serilizers.py @@ -14,7 +14,7 @@ class ThreadSerializer(serializers.ModelSerializer): class Meta: model = Thread - exclude = ('is_staff', 'recurse_step') + exclude = ('is_staff', ) class ThreadAdminSerializer(ThreadSerializer):