{ "info": { "author": "Yegor Ivashchenko", "author_email": "yegor.ivashchenko@protonmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Django Admin client\n\n## Installation\n\n```\npip install django-admin-client\n```\n\n## Usage\n\n3 main usages:\n1. Convenient HTTP GET and POST methods\n2. Dynamic Django Admin python client\n3. Generating specific Django Admin python client\n\n### 1. Convenient HTTP GET and POST methods\n\n`DjangoAdminBase` will do auto login, session management, and auto csrf token inclusion and auto error detection\n\n```python\nfrom django_admin_client import DjangoAdminBase\n\nbasic_client = DjangoAdminBase('http://127.0.0.1:9000/admin', 'superuser', 'why-dont-tell-mom?')\n\n# auto login:\nbasic_client.get_with_auto_login('/')\n# \n\n# response is just our favorite and well-known response from 'requests' library\ntype(basic_client.get_with_auto_login('/'))\n# requests.models.Response\n\n# auto login (if not yet logged in or session expired),\n# csrf token included in POST request automatically,\n# errors in response html form detected and provided\nbasic_client.post_with_csrf_and_auto_login(\n '/auth/user/add/',\n {'username': 'test', 'password1': '123', 'password2': '123'}\n)\n#{'response': ,\n# 'errors': [
\n#
  • This password is too short. It must contain at least 8 characters.
  • This password is too common.
  • This password is entirely numeric.
\n#
\n# \n# \n#
Enter the same password as before, for verification.
\n#
\n#
]}\n\nbasic_client.post_with_csrf_and_auto_login(\n '/auth/user/add/',\n {'username': 'test', 'password1': 'isthislongenough', 'password2': 'isthislongenough'}\n)\n# {'response': , 'errors': []}\n```\n\n### 2. Dynamic Django Admin python client\n\n`DjangoAdminBase` can also do introspection on Django Admin site and generate specification.\n\n```python\nIn [1]: spec = basic_client.generate_spec()\nIn [2]: import json\nIn [3]: json.dumps(spec, indent=2)\nOut[3]:\n{\n \"models\": {\n \"groups\": {\n \"id\": \"groups\",\n \"app\": \"auth\",\n \"name\": \"group\",\n \"fields\": {\n \"name\": {\n \"name\": \"name\",\n \"required\": true,\n \"default_value\": \"\"\n },\n \"permissions\": {\n \"name\": \"permissions\",\n \"required\": false,\n \"default_value\": \"\"\n }\n }\n },\n \"users\": {\n \"id\": \"users\",\n \"app\": \"auth\",\n \"name\": \"user\",\n \"fields\": {\n \"username\": {\n \"name\": \"username\",\n \"required\": true,\n \"default_value\": \"\"\n },\n \"password1\": {\n \"name\": \"password1\",\n \"required\": true,\n \"default_value\": \"\"\n },\n \"password2\": {\n \"name\": \"password2\",\n \"required\": true,\n \"default_value\": \"\"\n }\n }\n }\n }\n}\n```\n\nThis specification can then be fed to `DjangoAdminDynamic` class to get dynamic admin python client.\n\n```python\nfrom django_admin_client import DjangoAdminBase, DjangoAdminDynamic\nbasic_client = DjangoAdminBase('http://127.0.0.1:9000/admin', 'superuser', 'why-dont-tell-mom?')\nspec = basic_client.generate_spec()\ndynamic_client = DjangoAdminDynamic(spec=spec, client=basic_client)\ndynamic_client.users.all()\n# {'response': , 'ids': ['1', '2']}\n```\n\nAt the moment you can add objects with `.add(item: dict)`:\n```python\ndynamic_client.users.add({})\n#{'id': None,\n# 'created': False,\n# 'errors': [
\n#
  • This field is required.
\n#
\n# \n# \n#
Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
\n#
\n#
,
\n#
  • This field is required.
\n#
\n# \n# \n#
  • Your password can't be too similar to your other personal information.
  • Your password must contain at least 8 characters.
  • Your password can't be a commonly used password.
  • Your password can't be entirely numeric.
\n#
\n#
,
\n#
  • This field is required.
\n#
\n# \n# \n#
Enter the same password as before, for verification.
\n#
\n#
],\n# 'response': }\n\ndynamic_client.users.add({'username': 'fromdynamic', 'password1': 'qwertyuio!', 'password2': 'qwertyuio!'})\n# {'id': '3', 'created': True, 'errors': [], 'response': }\n```\n\nGet all object ids with `.all()`:\n```python\ndynamic_client.users.all()\n# {'ids': ['3', '1', '2'], 'response': }\n```\n\nSearch object id with `.find(query: str)`:\n```python\ndynamic_client.users.find('fromdynamic')\n# {'id': '3', 'response': }\n```\n\nGet object fields with `.get(object_id: str)`:\n```python\n>>> dynamic_client.users.get('3')\n{'response': ,\n 'details': {'username': 'fromdynamic',\n 'password': '',\n 'first_name': '',\n 'last_name': '',\n 'email': '',\n 'is_active': '',\n 'is_staff': '',\n 'is_superuser': '',\n 'groups': [],\n 'user_permissions': [],\n 'last_login_0': '',\n 'last_login_1': '',\n 'date_joined_0': '2019-03-06',\n 'date_joined_1': '13:00:00'}}\n```\n\nChange object with `.change(object_id: str, fields: dict)`:\n```python\nIn [1]: dynamic_client.users.change('3', {'is_superuser': '1'})\nOut[1]:\n{'success': False, 'errors': [
\n
  • This field is required.
\n
\n \n \n
Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
\n
\n
,
\n
  • This field is required.
\n
\n \n

\n Date: \n
\n Time: \n

\n \n
\n
], 'response': }\n\nIn [2]: dynamic_client.users.change('3',\n ...: {'username': 'fromdynamic',\n ...: 'is_active': '1',\n ...: 'is_staff': '1',\n ...: 'is_superuser': '1',\n ...: 'date_joined_0': '2019-03-06', 'date_joined_1': '13:00'})\nOut[2]: {'success': True, 'errors': [], 'response': }\n\nIn [3]: dynamic_client.users.get('3')\nOut[3]:\n{'response': ,\n 'details': {'username': 'fromdynamic',\n 'password': '',\n 'first_name': '',\n 'last_name': '',\n 'email': '',\n 'is_active': '1',\n 'is_staff': '1',\n 'is_superuser': '1',\n 'groups': [],\n 'user_permissions': [],\n 'last_login_0': '',\n 'last_login_1': '',\n 'date_joined_0': '2019-03-06',\n 'date_joined_1': '13:00:00'}}\n\n\n\n```\n\nAnd delete the object with `.delete(object_id: str)`:\n```python\ndynamic_client.users.delete('3')\n# {'response': , 'success': True}\n\ndynamic_client.users.all()\n# {'response': , 'ids': ['1', '2']}\n```\n\n### 3. Generating specific Django Admin python client\n\n`DjangoAdminDynamic` is quite useful for quick terminal sessions.\n\nAuto-completion for `DjangoAdminDynamic` clients is provided in python interpreter when hitting `` because attributes\nof a client are introspected at run time with `dir` built-in python funciton.\n\nBut writing source code with `DjangoAdminDynamic` is not that pleasant because\nthere's no way for IDE to know what attributes will object have at run time.\n\nFor this purpose `generate-package` command is provided with `django-admin-package`.\n\nExample\n```\n$ generate-package\nBase url (including /admin): http://localhost:9000/admin\nSuperuser username: superuser\nSuperuser password:\nSite name: fresh project\nPath to package (default: /tmp): .\nVersion (default: 1.0):\nGenerated package in ./freshproject-admin-client\n```\n\nGenerated project structure:\n```\n$ tree freshproject-admin-client\nfreshproject-admin-client\n\u251c\u2500\u2500 freshproject_admin_client\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 client.py\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 spec.json\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 setup.py\n\n1 directory, 5 files\n```\n\nYou can version control generated package, install it, upload to PyPI.\n\nExample usage of a generated client:\n```\n$ ipython\nPython 3.6.7 (default, Nov 9 2018, 21:20:52)\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.\n\nIn [1]: from freshproject_admin_client import FreshProjectDjangoAdminClient\n\nIn [2]: client = FreshProjectDjangoAdminClient('http://localhost:9000/admin', 'superuser', 'why-dont-tell-mom?')\n\nIn [3]: client.auth.users.all()\nOut[3]: {'response': , 'ids': ['4', '1', '2']}\n\nIn [4]: client.auth.users.add()\n---------------------------------------------------------------------------\nTypeError Traceback (most recent call last)\n in \n----> 1 client.auth.users.add()\n\nTypeError: add() missing 3 required positional arguments: 'username', 'password1', and 'password2'\n\nIn [5]: client.auth.users.add('from_freshproject_client', '123qweASD)_+', '123qweASD)_+')\nOut[5]: {'response': , 'id': '5', 'created': True}\n\nIn [6]: client.auth.users.get('5')\nOut[6]:\n{'response': ,\n 'details': {'username': 'from_freshproject_client',\n 'password': '',\n 'first_name': '',\n 'last_name': '',\n 'email': '',\n 'is_active': '',\n 'is_staff': '',\n 'is_superuser': '',\n 'groups': [],\n 'user_permissions': [],\n 'last_login': '',\n 'date_joined': '2019-03-05'}}\n\nIn [7]: client.auth.users.find('from_freshproject_client')\nOut[7]: {'response': , 'id': '5'}\n\nIn [8]: client.auth.users.delete('5')\nOut[8]: {'response': , 'success': True}\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/y3g0r/django-admin-client", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-admin-client", "package_url": "https://pypi.org/project/django-admin-client/", "platform": "", "project_url": "https://pypi.org/project/django-admin-client/", "project_urls": { "Homepage": "https://gitlab.com/y3g0r/django-admin-client" }, "release_url": "https://pypi.org/project/django-admin-client/0.2.4/", "requires_dist": [ "requests", "BeautifulSoup4", "python-dotenv" ], "requires_python": "", "summary": "Django admin client", "version": "0.2.4" }, "last_serial": 4940389, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "32975134f32b0d06b832b6578b08aa5b", "sha256": "b03f665d747e85cea80799a816ffeaa89cf99ef825f16ce0b08285a24f14d71c" }, "downloads": -1, "filename": "django_admin_client-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "32975134f32b0d06b832b6578b08aa5b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10338, "upload_time": "2019-03-06T09:06:29", "url": "https://files.pythonhosted.org/packages/8c/98/13951aee59ec05e9edd43202d9b56f6dd79b4bc26135ddf4e42b03c465ba/django_admin_client-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "86874f5382b05b3cbede6bd8706d2ac6", "sha256": "1af284a7b3b377851db627fed1d735f95893a37be18cdc5f660d205aeb675dc5" }, "downloads": -1, "filename": "django-admin-client-0.1.2.tar.gz", "has_sig": false, "md5_digest": "86874f5382b05b3cbede6bd8706d2ac6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10552, "upload_time": "2019-03-06T09:06:34", "url": "https://files.pythonhosted.org/packages/e5/bc/3fd906a951e898757a496bcaea96d3adf400e732471f802cdbc794ab6c92/django-admin-client-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "40f705564667b678bf0e397498688382", "sha256": "dccc223de269b2bb475c3139b7fbdb8b07fa48386289fda3088acc9e49d5ca78" }, "downloads": -1, "filename": "django_admin_client-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "40f705564667b678bf0e397498688382", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10362, "upload_time": "2019-03-06T09:06:32", "url": "https://files.pythonhosted.org/packages/5e/df/8842456a262a6cf5722a9ba31b9685f9d9964949c02a57dd4753db5ffeda/django_admin_client-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "87188461a334825079610c6ba4ad47cd", "sha256": "a14c9e243b2d04c2eb4bb366d0fce46301bb5b40dd0e52c18c62e5dd999a78e9" }, "downloads": -1, "filename": "django-admin-client-0.1.3.tar.gz", "has_sig": false, "md5_digest": "87188461a334825079610c6ba4ad47cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10600, "upload_time": "2019-03-06T09:06:35", "url": "https://files.pythonhosted.org/packages/7f/ce/e463a28614967729dbf83f2a3909ef0d1c7194f4e811baf9327f413c1acb/django-admin-client-0.1.3.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "77586be78ee7124dca91f00e3d116940", "sha256": "a8c75dd68636e13d7a0e5aea6bbfd538f3c98a93c9eb7ed4bb6da7d6e85dce8f" }, "downloads": -1, "filename": "django_admin_client-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "77586be78ee7124dca91f00e3d116940", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11778, "upload_time": "2019-03-06T09:06:33", "url": "https://files.pythonhosted.org/packages/88/6e/4d67e3ed4964e4eaa7427be2e47e43863496fd33db9e3dccbdc3f5b35dc6/django_admin_client-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "be76d6ca9196d52aaa42318a8d53ef7e", "sha256": "89064b8c40e3fd766be809b83e4b11324e90ca2b7cfdf7146d9a6cc6dfca367d" }, "downloads": -1, "filename": "django-admin-client-0.2.0.tar.gz", "has_sig": false, "md5_digest": "be76d6ca9196d52aaa42318a8d53ef7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12893, "upload_time": "2019-03-06T09:06:37", "url": "https://files.pythonhosted.org/packages/2c/29/4e76a58975b67afa9561e523cc34bb31cd5c0e1d6f3dac8ccd191f64290d/django-admin-client-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f8cebbafe1a1f23f68ef8a93077ec842", "sha256": "bbfec9e08612277d138bcd8e089029bd0cd5039301bc7d7c785d1bbb2839ad46" }, "downloads": -1, "filename": "django-admin-client-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f8cebbafe1a1f23f68ef8a93077ec842", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10199, "upload_time": "2019-03-12T06:48:55", "url": "https://files.pythonhosted.org/packages/9f/14/3a2c44e8db84854d10c9e93e567ba4fb946188b030e5d3999570163552dc/django-admin-client-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "f811297216621e113a23870b041858a8", "sha256": "87834c94ce77088ba7b96f513c5dfc1021706fec3f986359950e8e71d9fb80fa" }, "downloads": -1, "filename": "django-admin-client-0.2.2.tar.gz", "has_sig": false, "md5_digest": "f811297216621e113a23870b041858a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10219, "upload_time": "2019-03-12T15:18:27", "url": "https://files.pythonhosted.org/packages/bf/bd/64d716e37c0c27f19518923ca59746557dfa3a5454ecd162a8f601f9a5e8/django-admin-client-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "62b946de9b88fab65efcf5aee0a468ca", "sha256": "87f49a41faa2376a1d720d01e7443740f7c8b2210dfc1fa1e599727f9e95715b" }, "downloads": -1, "filename": "django-admin-client-0.2.3.tar.gz", "has_sig": false, "md5_digest": "62b946de9b88fab65efcf5aee0a468ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9995, "upload_time": "2019-03-12T22:25:08", "url": "https://files.pythonhosted.org/packages/aa/56/4788769dadd09c24ca0b3f7a698d3d030f53e38f084101f600542954cb2d/django-admin-client-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "d1863e9cf93aa6374e6202142d3e998f", "sha256": "7e16c5b3a2c097b2c8af7470814830fc76661b23760ca94617420b3659156d25" }, "downloads": -1, "filename": "django_admin_client-0.2.4-py3-none-any.whl", "has_sig": false, "md5_digest": "d1863e9cf93aa6374e6202142d3e998f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11495, "upload_time": "2019-03-14T15:53:17", "url": "https://files.pythonhosted.org/packages/0e/61/7a1cb33195ca93af09985a8e0778f2cd707737c9d2b428940e2b7f0e9079/django_admin_client-0.2.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5af3f9613b34b3881b525ec8d0b51a26", "sha256": "c9212591176fb9047c731173020063725382ddbfa18476a92a36a585a0e4a73f" }, "downloads": -1, "filename": "django-admin-client-0.2.4.tar.gz", "has_sig": false, "md5_digest": "5af3f9613b34b3881b525ec8d0b51a26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12627, "upload_time": "2019-03-14T15:53:18", "url": "https://files.pythonhosted.org/packages/bf/91/c8023d201cd4585cd2eb9bad6ba1493ae496b2e6f05eeb82ebceba65eefe/django-admin-client-0.2.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d1863e9cf93aa6374e6202142d3e998f", "sha256": "7e16c5b3a2c097b2c8af7470814830fc76661b23760ca94617420b3659156d25" }, "downloads": -1, "filename": "django_admin_client-0.2.4-py3-none-any.whl", "has_sig": false, "md5_digest": "d1863e9cf93aa6374e6202142d3e998f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11495, "upload_time": "2019-03-14T15:53:17", "url": "https://files.pythonhosted.org/packages/0e/61/7a1cb33195ca93af09985a8e0778f2cd707737c9d2b428940e2b7f0e9079/django_admin_client-0.2.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5af3f9613b34b3881b525ec8d0b51a26", "sha256": "c9212591176fb9047c731173020063725382ddbfa18476a92a36a585a0e4a73f" }, "downloads": -1, "filename": "django-admin-client-0.2.4.tar.gz", "has_sig": false, "md5_digest": "5af3f9613b34b3881b525ec8d0b51a26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12627, "upload_time": "2019-03-14T15:53:18", "url": "https://files.pythonhosted.org/packages/bf/91/c8023d201cd4585cd2eb9bad6ba1493ae496b2e6f05eeb82ebceba65eefe/django-admin-client-0.2.4.tar.gz" } ] }