num lines-num-new"> 16
+
+application = get_wsgi_application()
@@ -0,0 +1,23 @@ |
||
| 1 |
+#!/usr/bin/env python |
|
| 2 |
+import os |
|
| 3 |
+import sys |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+if __name__ == "__main__": |
|
| 7 |
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kodo.settings")
|
|
| 8 |
+ try: |
|
| 9 |
+ from django.core.management import execute_from_command_line |
|
| 10 |
+ except ImportError: |
|
| 11 |
+ # The above import may fail for some other reason. Ensure that the |
|
| 12 |
+ # issue is really that Django is missing to avoid masking other |
|
| 13 |
+ # exceptions on Python 2. |
|
| 14 |
+ try: |
|
| 15 |
+ import django |
|
| 16 |
+ except ImportError: |
|
| 17 |
+ raise ImportError( |
|
| 18 |
+ "Couldn't import Django. Are you sure it's installed and " |
|
| 19 |
+ "available on your PYTHONPATH environment variable? Did you " |
|
| 20 |
+ "forget to activate a virtual environment?" |
|
| 21 |
+ ) |
|
| 22 |
+ raise |
|
| 23 |
+ execute_from_command_line(sys.argv) |
@@ -0,0 +1,22 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.contrib import admin |
|
| 4 |
+ |
|
| 5 |
+from mch.models import BrandInfo, DistributorInfo, ModelInfo |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class BrandInfoAdmin(admin.ModelAdmin): |
|
| 9 |
+ list_display = ('brand_id', 'brand_name', 'brand_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+class ModelInfoAdmin(admin.ModelAdmin): |
|
| 13 |
+ list_display = ('model_id', 'model_name', 'model_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+class DistributorInfoAdmin(admin.ModelAdmin): |
|
| 17 |
+ list_display = ('distributor_id', 'distributor_name', 'distributor_descr', 'position', 'status', 'created_at', 'updated_at')
|
|
| 18 |
+ |
|
| 19 |
+ |
|
| 20 |
+admin.site.register(BrandInfo, BrandInfoAdmin) |
|
| 21 |
+admin.site.register(ModelInfo, ModelInfoAdmin) |
|
| 22 |
+admin.site.register(DistributorInfo, DistributorInfoAdmin) |
@@ -0,0 +1,8 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.apps import AppConfig |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+class MchConfig(AppConfig): |
|
| 8 |
+ name = 'mch' |
@@ -0,0 +1,68 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.3 on 2017-12-30 13:37 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+import shortuuidfield.fields |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class Migration(migrations.Migration): |
|
| 10 |
+ |
|
| 11 |
+ initial = True |
|
| 12 |
+ |
|
| 13 |
+ dependencies = [ |
|
| 14 |
+ ] |
|
| 15 |
+ |
|
| 16 |
+ operations = [ |
|
| 17 |
+ migrations.CreateModel( |
|
| 18 |
+ name='BrandInfo', |
|
| 19 |
+ fields=[ |
|
| 20 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 21 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 22 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 23 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 24 |
+ ('brand_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 25 |
+ ('brand_name', models.CharField(blank=True, help_text='\u54c1\u724c\u540d\u79f0', max_length=255, null=True, verbose_name='brand_name')),
|
|
| 26 |
+ ('brand_descr', models.TextField(blank=True, help_text='\u54c1\u724c\u63cf\u8ff0', max_length=255, null=True, verbose_name='brand_descr')),
|
|
| 27 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 28 |
+ ], |
|
| 29 |
+ options={
|
|
| 30 |
+ 'verbose_name': '\u54c1\u724c\u4fe1\u606f', |
|
| 31 |
+ 'verbose_name_plural': '\u54c1\u724c\u4fe1\u606f', |
|
| 32 |
+ }, |
|
| 33 |
+ ), |
|
| 34 |
+ migrations.CreateModel( |
|
| 35 |
+ name='DistributorInfo', |
|
| 36 |
+ fields=[ |
|
| 37 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 38 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 39 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 40 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 41 |
+ ('distributor_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u7ecf\u9500\u5546\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 42 |
+ ('distributor_name', models.CharField(blank=True, help_text='\u7ecf\u9500\u5546\u540d\u79f0', max_length=255, null=True, verbose_name='distributor_name')),
|
|
| 43 |
+ ('distributor_descr', models.TextField(blank=True, help_text='\u7ecf\u9500\u5546\u63cf\u8ff0', max_length=255, null=True, verbose_name='distributor_descr')),
|
|
| 44 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 45 |
+ ], |
|
| 46 |
+ options={
|
|
| 47 |
+ 'verbose_name': '\u7ecf\u9500\u5546\u4fe1\u606f', |
|
| 48 |
+ 'verbose_name_plural': '\u7ecf\u9500\u5546\u4fe1\u606f', |
|
| 49 |
+ }, |
|
| 50 |
+ ), |
|
| 51 |
+ migrations.CreateModel( |
|
| 52 |
+ name='ModelInfo', |
|
| 53 |
+ fields=[ |
|
| 54 |
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
| 55 |
+ ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
|
|
| 56 |
+ ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
|
|
| 57 |
+ ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
|
|
| 58 |
+ ('model_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
|
|
| 59 |
+ ('model_name', models.CharField(blank=True, help_text='\u578b\u53f7\u540d\u79f0', max_length=255, null=True, verbose_name='model_name')),
|
|
| 60 |
+ ('model_descr', models.TextField(blank=True, help_text='\u578b\u53f7\u63cf\u8ff0', max_length=255, null=True, verbose_name='model_descr')),
|
|
| 61 |
+ ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
|
|
| 62 |
+ ], |
|
| 63 |
+ options={
|
|
| 64 |
+ 'verbose_name': '\u578b\u53f7\u4fe1\u606f', |
|
| 65 |
+ 'verbose_name_plural': '\u578b\u53f7\u4fe1\u606f', |
|
| 66 |
+ }, |
|
| 67 |
+ ), |
|
| 68 |
+ ] |
@@ -0,0 +1,75 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.db import models |
|
| 4 |
+from django.utils.translation import ugettext_lazy as _ |
|
| 5 |
+from models_ext import BaseModelMixin |
|
| 6 |
+from shortuuidfield import ShortUUIDField |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class BrandInfo(BaseModelMixin): |
|
| 10 |
+ brand_id = ShortUUIDField(_(u'brand_id'), max_length=32, help_text=u'品牌唯一标识', db_index=True, unique=True) |
|
| 11 |
+ brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') |
|
| 12 |
+ brand_descr = models.TextField(_(u'brand_descr'), max_length=255, blank=True, null=True, help_text=u'品牌描述') |
|
| 13 |
+ |
|
| 14 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 15 |
+ |
|
| 16 |
+ class Meta: |
|
| 17 |
+ verbose_name = _(u'品牌信息') |
|
| 18 |
+ verbose_name_plural = _(u'品牌信息') |
|
| 19 |
+ |
|
| 20 |
+ def __unicode__(self): |
|
| 21 |
+ return unicode(self.pk) |
|
| 22 |
+ |
|
| 23 |
+ @property |
|
| 24 |
+ def data(self): |
|
| 25 |
+ return {
|
|
| 26 |
+ 'brand_id': self.brand_id, |
|
| 27 |
+ 'brand_name': self.brand_name, |
|
| 28 |
+ 'brand_descr': self.brand_descr, |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ |
|
| 32 |
+class ModelInfo(BaseModelMixin): |
|
| 33 |
+ model_id = ShortUUIDField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True, unique=True) |
|
| 34 |
+ model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称') |
|
| 35 |
+ model_descr = models.TextField(_(u'model_descr'), max_length=255, blank=True, null=True, help_text=u'型号描述') |
|
| 36 |
+ |
|
| 37 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 38 |
+ |
|
| 39 |
+ class Meta: |
|
| 40 |
+ verbose_name = _(u'型号信息') |
|
| 41 |
+ verbose_name_plural = _(u'型号信息') |
|
| 42 |
+ |
|
| 43 |
+ def __unicode__(self): |
|
| 44 |
+ return unicode(self.pk) |
|
| 45 |
+ |
|
| 46 |
+ @property |
|
| 47 |
+ def data(self): |
|
| 48 |
+ return {
|
|
| 49 |
+ 'model_id': self.model_id, |
|
| 50 |
+ 'model_name': self.model_name, |
|
| 51 |
+ 'model_descr': self.model_descr, |
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+ |
|
| 55 |
+class DistributorInfo(BaseModelMixin): |
|
| 56 |
+ distributor_id = ShortUUIDField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True, unique=True) |
|
| 57 |
+ distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称') |
|
| 58 |
+ distributor_descr = models.TextField(_(u'distributor_descr'), max_length=255, blank=True, null=True, help_text=u'经销商描述') |
|
| 59 |
+ |
|
| 60 |
+ position = models.IntegerField(_(u'position'), default=1, help_text=u'排序') |
|
| 61 |
+ |
|
| 62 |
+ class Meta: |
|
| 63 |
+ verbose_name = _(u'经销商信息') |
|
| 64 |
+ verbose_name_plural = _(u'经销商信息') |
|
| 65 |
+ |
|
| 66 |
+ def __unicode__(self): |
|
| 67 |
+ return unicode(self.pk) |
|
| 68 |
+ |
|
| 69 |
+ @property |
|
| 70 |
+ def data(self): |
|
| 71 |
+ return {
|
|
| 72 |
+ 'distributor_id': self.distributor_id, |
|
| 73 |
+ 'distributor_name': self.distributor_name, |
|
| 74 |
+ 'distributor_descr': self.distributor_descr, |
|
| 75 |
+ } |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.test import TestCase |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Create your tests here. |
@@ -0,0 +1,7 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+from __future__ import unicode_literals |
|
| 3 |
+ |
|
| 4 |
+from django.shortcuts import render |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+# Create your views here. |
@@ -0,0 +1,9 @@ |
||
| 1 |
+#!/bin/bash |
|
| 2 |
+ |
|
| 3 |
+# Ignoring autogenerated files |
|
| 4 |
+# -- Migration directories |
|
| 5 |
+# Ignoring error codes |
|
| 6 |
+# -- E128 continuation line under-indented for visual indent |
|
| 7 |
+# -- E501 line too long |
|
| 8 |
+ |
|
| 9 |
+pycodestyle --exclude=build,migrations,.tox --ignore=E128,E501 . |
@@ -0,0 +1,18 @@ |
||
| 1 |
+Django==1.11.3 |
|
| 2 |
+StatusCode==1.0.0 |
|
| 3 |
+django-admin==1.1.0 |
|
| 4 |
+django-detect==1.0.5 |
|
| 5 |
+django-json-render==1.0.0 |
|
| 6 |
+django-json-response==1.1.5 |
|
| 7 |
+django-models-ext==1.0.5 |
|
| 8 |
+django-short-url==1.0.2 |
|
| 9 |
+django-uniapi==1.0.0 |
|
| 10 |
+django-we==1.1.2 |
|
| 11 |
+furl==1.0.1 |
|
| 12 |
+hiredis==0.2.0 |
|
| 13 |
+mysqlclient==1.3.12 |
|
| 14 |
+pywe-oauth==1.0.5 |
|
| 15 |
+pywe-pay==1.0.11 |
|
| 16 |
+redis==2.10.6 |
|
| 17 |
+redis-extensions==1.1.6 |
|
| 18 |
+rsa==3.4.2 |
@@ -0,0 +1,13 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+import base64 |
|
| 4 |
+ |
|
| 5 |
+from CodeConvert import CodeConvert as cc |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+def b64_encrypt(plaintext): |
|
| 9 |
+ return base64.urlsafe_b64encode(cc.Convert2Utf8(plaintext)) |
|
| 10 |
+ |
|
| 11 |
+ |
|
| 12 |
+def b64_decrypt(ciphertext): |
|
| 13 |
+ return cc.Convert2Unicode(base64.urlsafe_b64decode(ciphertext)) |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+import base64 |
|
| 4 |
+ |
|
| 5 |
+import rsa |
|
| 6 |
+from CodeConvert import CodeConvert as cc |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+pubkey = rsa.PublicKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537) |
|
| 10 |
+privkey = rsa.PrivateKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537, 316971401565576878144472516350155768882090601834219605321449556369521730928872332388800749109622843453327077688969025635980606763507018292148749534091473, 4517492317789178911663214752269837474466539823144998211438927363654134055916886851, 1711997816918835594017245862832442114582648667392542139046338517030653261) |
|
| 11 |
+ |
|
| 12 |
+ |
|
| 13 |
+def rsa_encrypt(plaintext): |
|
| 14 |
+ return base64.urlsafe_b64encode(rsa.encrypt(cc.Convert2Utf8(plaintext), pubkey)) |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+def rsa_decrypt(ciphertext): |
|
| 18 |
+ return rsa.decrypt(base64.urlsafe_b64decode(cc.Convert2Utf8(ciphertext)), privkey) |
@@ -0,0 +1,72 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from StatusCode import BaseStatusCode, StatusCodeField |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+class ProfileStatusCode(BaseStatusCode): |
|
| 7 |
+ """ 4001xx 用户相关错误码 """ |
|
| 8 |
+ PROFILE_NOT_FOUND = StatusCodeField(400101, 'Profile Not Found', description=u'用户不存在') |
|
| 9 |
+ |
|
| 10 |
+ |
|
| 11 |
+class PhoneStatusCode(BaseStatusCode): |
|
| 12 |
+ """ 4002xx 手机相关错误码 """ |
|
| 13 |
+ INVALID_PHONE = StatusCodeField(400200, 'Invalid Phone', description=u'非法手机号') |
|
| 14 |
+ PHONE_NOT_FOUND = StatusCodeField(400201, 'Phone Not Found', description=u'手机号不存在') |
|
| 15 |
+ PHONE_ALREADY_EXISTS = StatusCodeField(400202, 'Phone Already Exists', description=u'手机号已存在') |
|
| 16 |
+ |
|
| 17 |
+ |
|
| 18 |
+class OrderStatusCode(BaseStatusCode): |
|
| 19 |
+ """ 4040xx 订单/支付相关错误码 """ |
|
| 20 |
+ UNIFIED_ORDER_FAIL = StatusCodeField(404000, 'Unified Order Fail', description=u'统一下单失败') |
|
| 21 |
+ ORDER_NOT_FOUND = StatusCodeField(404001, 'Order Not Found', description=u'订单不存在') |
|
| 22 |
+ # 订单支付状态 |
|
| 23 |
+ ORDER_NOT_PAY = StatusCodeField(404011, 'Order Not Pay', description=u'订单未支付') |
|
| 24 |
+ ORDER_PAYING = StatusCodeField(404012, 'Order Paying', description=u'订单支付中') |
|
| 25 |
+ ORDER_PAY_FAIL = StatusCodeField(404013, 'Order Pay Fail', description=u'微信支付失败') |
|
| 26 |
+ # 通知校验状态 |
|
| 27 |
+ SIGN_CHECK_FAIL = StatusCodeField(404090, 'Sign Check Fail', description=u'签名校验失败') |
|
| 28 |
+ FEE_CHECK_FAIL = StatusCodeField(404091, 'FEE Check Fail', description=u'金额校验失败') |
|
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+class PayStatusCode(BaseStatusCode): |
|
| 32 |
+ """ 4041xx 支付相关错误码 """ |
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+class WithdrawStatusCode(BaseStatusCode): |
|
| 36 |
+ """ 4042xx 提现相关错误码 """ |
|
| 37 |
+ BALANCE_INSUFFICIENT = StatusCodeField(404200, 'Balance Insufficient', description=u'提现金额不足') |
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+class TokenStatusCode(BaseStatusCode): |
|
| 41 |
+ """ 4090xx 票据相关错误码 """ |
|
| 42 |
+ TOKEN_NOT_FOUND = StatusCodeField(409001, 'Token Not Found', description=u'票据不存在') |
|
| 43 |
+ |
|
| 44 |
+ |
|
| 45 |
+class SignatureStatusCode(BaseStatusCode): |
|
| 46 |
+ """ 4091xx 签名校验错误 """ |
|
| 47 |
+ SIGNATURE_ERROR = StatusCodeField(409101, 'Signature Error', description=u'签名错误') |
|
| 48 |
+ |
|
| 49 |
+ |
|
| 50 |
+class GVCodeStatusCode(BaseStatusCode): |
|
| 51 |
+ """ 4095xx 图形验证码相关错误码 """ |
|
| 52 |
+ GRAPHIC_VCODE_ERROR = StatusCodeField(409101, 'Graphic VCode Error', description=u'图形验证码错误') |
|
| 53 |
+ |
|
| 54 |
+ |
|
| 55 |
+class SVCodeStatusCode(BaseStatusCode): |
|
| 56 |
+ """ 4092xx 短信验证码相关错误码 """ |
|
| 57 |
+ SMS_QUOTA_LIMIT = StatusCodeField(409200, 'SMS Quota Limit', description=u'短信次数超限') |
|
| 58 |
+ SMS_VCODE_ERROR = StatusCodeField(409201, 'SMS VCode Error', description=u'验证码错误,请稍后重试') |
|
| 59 |
+ SMS_VCODE_HAS_SEND = StatusCodeField(409202, 'SMS VCode Has Send', description=u'验证码已发送,请勿重复获取') |
|
| 60 |
+ |
|
| 61 |
+ |
|
| 62 |
+class InsufficientStatusCode(BaseStatusCode): |
|
| 63 |
+ """ 4095xx 不足相关错误码 """ |
|
| 64 |
+ BALANCE_INSUFFICIENT = StatusCodeField(409501, 'Balance Insufficient', description=u'余额不足') |
|
| 65 |
+ INTEGRAL_INSUFFICIENT = StatusCodeField(409502, 'Integral Insufficient', description=u'积分不足') |
|
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+class PermissionStatusCode(BaseStatusCode): |
|
| 69 |
+ """ 4099xx 权限相关错误码 """ |
|
| 70 |
+ PERMISSION_DENIED = StatusCodeField(409900, 'Permission Denied', description=u'权限不足') |
|
| 71 |
+ UPLOAD_PERMISSION_DENIED = StatusCodeField(409910, 'Upload Permission Denied', description=u'上传权限不足') |
|
| 72 |
+ UPDATE_PERMISSION_DENIED = StatusCodeField(409930, 'Update Permission Denied', description=u'更新权限不足') |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.http import JsonResponse |
|
| 4 |
+from StatusCode import StatusCodeField |
|
| 5 |
+ |
|
| 6 |
+ |
|
| 7 |
+def response_data(status_code=200, message=None, description=None, data={}, **kwargs):
|
|
| 8 |
+ return dict({
|
|
| 9 |
+ 'status': status_code, |
|
| 10 |
+ 'message': message, |
|
| 11 |
+ 'description': description, |
|
| 12 |
+ 'data': data, |
|
| 13 |
+ }, **kwargs) |
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+def response(status_code=200, message=None, description=None, data={}, **kwargs):
|
|
| 17 |
+ message, description = (message or status_code.message, description or status_code.description) if isinstance(status_code, StatusCodeField) else (message, description) |
|
| 18 |
+ return JsonResponse(response_data(status_code, message, description, data, **kwargs), safe=False) |
@@ -0,0 +1,6 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from django.conf import settings |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+r = settings.REDIS_CACHE |
@@ -0,0 +1 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
@@ -0,0 +1,18 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+ |
|
| 4 |
+def userinfo_save(userinfo): |
|
| 5 |
+ """ Save profile or something else """ |
|
| 6 |
+ # from account.models import UserInfo |
|
| 7 |
+ # from django.conf import settings |
|
| 8 |
+ # |
|
| 9 |
+ # unique_identifier = userinfo.get(settings.WECHAT_UNIQUE_IDENTIFICATION, '') |
|
| 10 |
+ # |
|
| 11 |
+ # user, created = UserInfo.objects.select_for_update().get_or_create(**{settings.WECHAT_UNIQUE_IDENTIFICATION: unique_identifier})
|
|
| 12 |
+ # user.unionid = userinfo.get('unionid', '')
|
|
| 13 |
+ # user.openid = userinfo.get('openid', '')
|
|
| 14 |
+ # user.nickname = userinfo.get('nickname', '')
|
|
| 15 |
+ # user.avatar = userinfo.get('headimgurl', '')
|
|
| 16 |
+ # user.save() |
|
| 17 |
+ # |
|
| 18 |
+ # return user |