Codes Insert & Generate

Brightcells преди 7 години
родител
ревизия
03823bcc2e
променени са 8 файла, в които са добавени 86 реда и са изтрити 10 реда
  1. 2 2
      codes/admin.py
  2. BIN
      codes/codes.xlsx
  3. 20 0
      codes/migrations/0002_coursecodeinfo_code_type.py
  4. 20 0
      codes/migrations/0003_auto_20171110_1323.py
  5. 11 1
      codes/models.py
  6. 29 2
      codes/views.py
  7. 0 1
      course/settings.py
  8. 4 4
      requirements.txt

+ 2 - 2
codes/admin.py

@@ -7,8 +7,8 @@ from codes.models import CourseCodeInfo
7 7
 
8 8
 
9 9
 class CourseCodeInfoAdmin(ExportExcelModelAdmin, admin.ModelAdmin):
10
-    list_display = ('code', 'exchanged', 'user_id', 'status', 'created_at', 'updated_at')
11
-    list_filter = ('exchanged', 'status')
10
+    list_display = ('code', 'code_type', 'exchanged', 'user_id', 'status', 'created_at', 'updated_at')
11
+    list_filter = ('code_type', 'exchanged', 'status')
12 12
 
13 13
 
14 14
 admin.site.register(CourseCodeInfo, CourseCodeInfoAdmin)

BIN
codes/codes.xlsx


+ 20 - 0
codes/migrations/0002_coursecodeinfo_code_type.py

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.3 on 2017-11-10 05:05
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('codes', '0001_initial'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='coursecodeinfo',
17
+            name='code_type',
18
+            field=models.IntegerField(choices=[(0, 'SN'), (10, '\u7cfb\u7edf')], db_index=True, default=10, help_text='\u5151\u6362\u7801\u7c7b\u522b', verbose_name='code_type'),
19
+        ),
20
+    ]

+ 20 - 0
codes/migrations/0003_auto_20171110_1323.py

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.3 on 2017-11-10 05:23
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('codes', '0002_coursecodeinfo_code_type'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterField(
16
+            model_name='coursecodeinfo',
17
+            name='code',
18
+            field=models.CharField(blank=True, db_index=True, help_text='\u5151\u6362\u7801', max_length=255, null=True, unique=True, verbose_name='code'),
19
+        ),
20
+    ]

+ 11 - 1
codes/models.py

@@ -7,7 +7,17 @@ from course.basemodels import CreateUpdateMixin
7 7
 
8 8
 
9 9
 class CourseCodeInfo(CreateUpdateMixin):
10
-    code = models.CharField(_(u'code'), max_length=255, blank=True, null=True, help_text=u'兑换码', db_index=True)
10
+    SN = 0
11
+    SYS = 10
12
+
13
+    CODE_TYPE = (
14
+        (SN, u'SN'),
15
+        (SYS, u'系统'),
16
+    )
17
+
18
+    code = models.CharField(_(u'code'), max_length=255, blank=True, null=True, help_text=u'兑换码', db_index=True, unique=True)
19
+    code_type = models.IntegerField(_(u'code_type'), choices=CODE_TYPE, default=SYS, help_text=_(u'兑换码类别'), db_index=True)
20
+
11 21
     exchanged = models.BooleanField(_(u'exchanged'), default=False, help_text=_(u'兑换状态'), db_index=True)
12 22
 
13 23
     user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识', db_index=True, unique=True)

+ 29 - 2
codes/views.py

@@ -1,7 +1,34 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from __future__ import unicode_literals
3 3
 
4
-from django.shortcuts import render
4
+import vcode
5
+import xlrd
6
+from django.db import IntegrityError
5 7
 
8
+from codes.models import CourseCodeInfo
6 9
 
7
-# Create your views here.
10
+
11
+def codes_insert(cfile='./codes/codes.xlsx'):
12
+    data = xlrd.open_workbook(cfile)
13
+    # sheets = data.sheets()
14
+    sheet = data.sheet_by_index(2)
15
+
16
+    nrows = sheet.nrows
17
+    for idx in range(1, nrows):
18
+        rvals = sheet.row_values(idx)
19
+        for val in rvals[1:]:
20
+            if not val:
21
+                continue
22
+            val = int(val)
23
+            try:
24
+                CourseCodeInfo.objects.create(code=val, code_type=CourseCodeInfo.SN)
25
+            except IntegrityError:
26
+                continue
27
+
28
+
29
+def codes_generate(num=10):
30
+    for _ in xrange(num):
31
+        try:
32
+            CourseCodeInfo.objects.create(code=vcode.digits(5, int))
33
+        except IntegrityError:
34
+            continue

+ 0 - 1
course/settings.py

@@ -167,7 +167,6 @@ MEDIA_URL = '/media/'
167 167
 
168 168
 # File 设置
169 169
 FILE_UPLOAD_MAX_MEMORY_SIZE = 104857600  # InMemoryUploadedFile 文件最大值,设置为 100 MB
170
-
171 170
 FILE_UPLOAD_PERMISSIONS = 0o644  # TemporaryUploadedFile 文件权限设置
172 171
 
173 172
 # DOMAIN

+ 4 - 4
requirements.txt

@@ -20,8 +20,8 @@ django-rlog==1.0.7
20 20
 django-shortuuidfield==0.1.3
21 21
 django-six==1.0.4
22 22
 django-uniapi==1.0.0
23
-django-we==1.0.14
24
-djangorestframework==3.7.0
23
+django-we==1.0.16
24
+djangorestframework==3.7.3
25 25
 furl==1.0.1
26 26
 hiredis==0.2.0
27 27
 isoweek==1.3.3
@@ -31,9 +31,9 @@ pysnippets==1.0.4
31 31
 pywe-miniapp==1.0.0
32 32
 pywe-oauth==1.0.5
33 33
 pywe-response==1.0.1
34
-qiniu==7.1.7
34
+qiniu==7.1.9
35 35
 redis==2.10.6
36
-redis-extensions==1.1.1
36
+redis-extensions==1.1.3
37 37
 requests==2.18.4
38 38
 rlog==0.3
39 39
 shortuuid==0.5.0