diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-django-hint.spec | 291 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 293 insertions, 0 deletions
@@ -0,0 +1 @@ +/django_hint-0.2.0.tar.gz diff --git a/python-django-hint.spec b/python-django-hint.spec new file mode 100644 index 0000000..f34265f --- /dev/null +++ b/python-django-hint.spec @@ -0,0 +1,291 @@ +%global _empty_manifest_terminate_build 0 +Name: python-django-hint +Version: 0.2.0 +Release: 1 +Summary: Type hinting package for django +License: MIT License +URL: https://github.com/Vieolo/django-hint +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/e4/7b/0047eae765c40705a3f7b6c8c3c25849528b6b35026ea898b844a267cb6c/django_hint-0.2.0.tar.gz +BuildArch: noarch + + +%description +`Django_hint` is a module to help you type hint your django project to work with different IDEs. It has been tested in PyCharm and with pylint in VSCode. + +``` +Notice: Python3.6 or later is required for this module +``` +<br> + +## Installation +You can use the `pip` to install django_hint + +``` +pip3 install django_hint +``` + +## Usage +The following use cases can be type hinted using `django_hint` to help your IDE recognize the type of variable. +1. Database QuerySet +2. WSGIRequest +3. Django-Rest-Framework Token Authentication +4. Model Class + +As a bonus, all of the native python type hints such as `List`, `Union`, `Optional` etc. from `typing` module can be imported from `django_hint` + +## Database QuerySet +It is used to hint that the variable is an `QuerySet` object containing multiple objects whose nature we will determine.<br> +You need to hint it to `QueryType` and pass the object type inside the `[]`. Example: +```python +from django_hint import QueryType + +sample_query: QueryType[SampleModel] = SampleModel.objects.filter(name='sample') +``` + +The `sample_query` variable will be treated as a `QuerySet`. While looping through the objects, each object will be treated as a `SampleModel` + +## WSGIRequest +It is used to hint the nature of the `request` argument of the view (both function and class based). +The `request` will be treated as a `HttpRequest` having the `user` variable attached to it. Example: +```python +from django_hint import RequestType + +def sample_view(request: RequestType): + if request.user.is_authenticated: + print(request.POST.get('data')) +``` + +## Django-Rest-Framework Token Authentication +If you are using the token authentication of the `Django-Rest-Framework`, the request object will have a `user` variable and an `auth` variable of `rest_framework.authtoken.models.Token` instance. `DRFTokenRequestType` will hint the IDE of those two variables. + +```python +from django_hint import DRFTokenRequestType + +def sample_view(request: DRFTokenRequestType): + print(request.auth.key) +``` + +## Model Class +Django adds a few attributes to a `Model` instance which are not available in the `models.Model` and will not be available in your IDE. +The most notable attribute is the `Manager` which is accessible via an attribute called `objects`.<br> +To include these attributes in your IDE, You have to extend your model to the `StandardModelType` class of `django_hint` as well as `models.Model` and use it just like any other model class.<br> +Note that `StandardModeltype` will NOT have any effect on your database and will NOT make new migrations on `makemigrations` command. + +```python +from django.db import models +from django_hint import StandardModelType + +class SampleModel(models.Model, StandardModelType): + """Just like any other model""" + pass +``` + + + + + + +%package -n python3-django-hint +Summary: Type hinting package for django +Provides: python-django-hint +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-django-hint +`Django_hint` is a module to help you type hint your django project to work with different IDEs. It has been tested in PyCharm and with pylint in VSCode. + +``` +Notice: Python3.6 or later is required for this module +``` +<br> + +## Installation +You can use the `pip` to install django_hint + +``` +pip3 install django_hint +``` + +## Usage +The following use cases can be type hinted using `django_hint` to help your IDE recognize the type of variable. +1. Database QuerySet +2. WSGIRequest +3. Django-Rest-Framework Token Authentication +4. Model Class + +As a bonus, all of the native python type hints such as `List`, `Union`, `Optional` etc. from `typing` module can be imported from `django_hint` + +## Database QuerySet +It is used to hint that the variable is an `QuerySet` object containing multiple objects whose nature we will determine.<br> +You need to hint it to `QueryType` and pass the object type inside the `[]`. Example: +```python +from django_hint import QueryType + +sample_query: QueryType[SampleModel] = SampleModel.objects.filter(name='sample') +``` + +The `sample_query` variable will be treated as a `QuerySet`. While looping through the objects, each object will be treated as a `SampleModel` + +## WSGIRequest +It is used to hint the nature of the `request` argument of the view (both function and class based). +The `request` will be treated as a `HttpRequest` having the `user` variable attached to it. Example: +```python +from django_hint import RequestType + +def sample_view(request: RequestType): + if request.user.is_authenticated: + print(request.POST.get('data')) +``` + +## Django-Rest-Framework Token Authentication +If you are using the token authentication of the `Django-Rest-Framework`, the request object will have a `user` variable and an `auth` variable of `rest_framework.authtoken.models.Token` instance. `DRFTokenRequestType` will hint the IDE of those two variables. + +```python +from django_hint import DRFTokenRequestType + +def sample_view(request: DRFTokenRequestType): + print(request.auth.key) +``` + +## Model Class +Django adds a few attributes to a `Model` instance which are not available in the `models.Model` and will not be available in your IDE. +The most notable attribute is the `Manager` which is accessible via an attribute called `objects`.<br> +To include these attributes in your IDE, You have to extend your model to the `StandardModelType` class of `django_hint` as well as `models.Model` and use it just like any other model class.<br> +Note that `StandardModeltype` will NOT have any effect on your database and will NOT make new migrations on `makemigrations` command. + +```python +from django.db import models +from django_hint import StandardModelType + +class SampleModel(models.Model, StandardModelType): + """Just like any other model""" + pass +``` + + + + + + +%package help +Summary: Development documents and examples for django-hint +Provides: python3-django-hint-doc +%description help +`Django_hint` is a module to help you type hint your django project to work with different IDEs. It has been tested in PyCharm and with pylint in VSCode. + +``` +Notice: Python3.6 or later is required for this module +``` +<br> + +## Installation +You can use the `pip` to install django_hint + +``` +pip3 install django_hint +``` + +## Usage +The following use cases can be type hinted using `django_hint` to help your IDE recognize the type of variable. +1. Database QuerySet +2. WSGIRequest +3. Django-Rest-Framework Token Authentication +4. Model Class + +As a bonus, all of the native python type hints such as `List`, `Union`, `Optional` etc. from `typing` module can be imported from `django_hint` + +## Database QuerySet +It is used to hint that the variable is an `QuerySet` object containing multiple objects whose nature we will determine.<br> +You need to hint it to `QueryType` and pass the object type inside the `[]`. Example: +```python +from django_hint import QueryType + +sample_query: QueryType[SampleModel] = SampleModel.objects.filter(name='sample') +``` + +The `sample_query` variable will be treated as a `QuerySet`. While looping through the objects, each object will be treated as a `SampleModel` + +## WSGIRequest +It is used to hint the nature of the `request` argument of the view (both function and class based). +The `request` will be treated as a `HttpRequest` having the `user` variable attached to it. Example: +```python +from django_hint import RequestType + +def sample_view(request: RequestType): + if request.user.is_authenticated: + print(request.POST.get('data')) +``` + +## Django-Rest-Framework Token Authentication +If you are using the token authentication of the `Django-Rest-Framework`, the request object will have a `user` variable and an `auth` variable of `rest_framework.authtoken.models.Token` instance. `DRFTokenRequestType` will hint the IDE of those two variables. + +```python +from django_hint import DRFTokenRequestType + +def sample_view(request: DRFTokenRequestType): + print(request.auth.key) +``` + +## Model Class +Django adds a few attributes to a `Model` instance which are not available in the `models.Model` and will not be available in your IDE. +The most notable attribute is the `Manager` which is accessible via an attribute called `objects`.<br> +To include these attributes in your IDE, You have to extend your model to the `StandardModelType` class of `django_hint` as well as `models.Model` and use it just like any other model class.<br> +Note that `StandardModeltype` will NOT have any effect on your database and will NOT make new migrations on `makemigrations` command. + +```python +from django.db import models +from django_hint import StandardModelType + +class SampleModel(models.Model, StandardModelType): + """Just like any other model""" + pass +``` + + + + + + +%prep +%autosetup -n django-hint-0.2.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-django-hint -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.0-1 +- Package Spec generated @@ -0,0 +1 @@ +a65a1ea6ffcf3724faf76f41172ed2ce django_hint-0.2.0.tar.gz |
