# django-toolbox **Repository Path**: waketzheng/django-toolbox ## Basic Information - **Project Name**: django-toolbox - **Description**: toolbox for Django3.1+ and Python3.8+ - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Toolbox (backend project) def and class for multiply projects ## Install ```bash pipenv install -e git+https://gitee.com/waketzheng/django-toolbox.git#egg=toolbox # Or use pip: # pip install -e git+https://gitee.com/waketzheng/django-toolbox.git#egg=toolbox --upgrade ``` ## Features - gen_nonce - to_decimal - EncryptMixin - TimeMixin - timeout - response_error - get_client_ip - is_wechat - is_qq - is_alipay - AttrDict - AttrDictMixin - StrChoice - ChoiceField - WeakForeignKey - CascadeForeignKey - send_vcode - send_sms ## Usage ~ goto pay ```py from toolbox import timeout, TimeMixin, is_wechat class Klass(TimeMixin): @timeout def get(self, request): if is_wechat(request): return HttpResponse('view by wechat') ``` - pretty AttrDict ``` >>> from toolbox import AttrDict >>> d = {'a': 1, 'b': 'xx'} >>> d = AttrDict(d) >>> d.a == d['a'] and d.b == d['b'] True ``` - ChoiceField is the subclass of models.CharField ``` >>> from toolbox import StrChoice, ChoiceField >>> from django.db import models >>> class A(models.Model): ... class GenderChoice(StrChoice): ... none = '0', '未知' ... man = '1', '男' ... lady = '2', '女' ... gender = ChoiceField('性别', GenderChoice, default=GenderChoice.none) ``` - Send vcode ``` >>> from toolbox import send_vcode >>> phone = 123_4567_8901 # int or str >>> vcode = send_vcode(phone) # send a random code[000000, 999999] to phone ``` ## For dev, run coverage: ``` coverage run -m pytest -s # 加-s可读取终端输入,用于input函数 coverage report -m # Or run in one line: coverage run -m pytest -s && coverage report -m ``` ## Typing check: ``` mypy toolbox # To install mypy, run: # pip install mypy --user ``` ## Security check: ``` bandit toolbox ``` ## Release install package: ``` ./setup.py publish ```