summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-05-05 12:25:55 +0000
committerCoprDistGit <infra@openeuler.org>2023-05-05 12:25:55 +0000
commitaa89eb2297867a7af2f684c06e686e7cb2fa2047 (patch)
treeea616b8a3672eb32ea95889116c4109468b17593
parent2accf51824ba22b2728b9f46bcc46a57460ff45c (diff)
automatic import of python-django-middleware-global-requestopeneuler20.03
-rw-r--r--.gitignore1
-rw-r--r--python-django-middleware-global-request.spec613
-rw-r--r--sources1
3 files changed, 615 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..3272daa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/django-middleware-global-request-0.3.1.tar.gz
diff --git a/python-django-middleware-global-request.spec b/python-django-middleware-global-request.spec
new file mode 100644
index 0000000..6aa22e1
--- /dev/null
+++ b/python-django-middleware-global-request.spec
@@ -0,0 +1,613 @@
+%global _empty_manifest_terminate_build 0
+Name: python-django-middleware-global-request
+Version: 0.3.1
+Release: 1
+Summary: Django middleware that keep request instance for every thread.
+License: MIT
+URL: https://pypi.org/project/django-middleware-global-request/
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/91/e2/638e6500cc4ebc9ddfa3687bfd02271afd8d3ef1e80050942b54f7b622ad/django-middleware-global-request-0.3.1.tar.gz
+BuildArch: noarch
+
+Requires: python3-django
+
+%description
+# django-middleware-global-request
+
+
+Django middleware that keep request instance for every thread.
+
+## Install
+
+
+```shell
+pip install django-middleware-global-request
+```
+## Note
+
+- It's NOT good to use global request, you should pass the request instance from view to anywhere you want to use it.
+- If you use the global request in Model layout, it means when you call the Model method from Django Shell, you get a None request.
+
+## Usage
+
+1. Add django application `django_middleware_global_request` to INSTALLED_APPS in `pro/settings.py`:
+
+ ```python
+ INSTALLED_APPS = [
+ ...
+ 'django_middleware_global_request',
+ ...
+ ]
+ ```
+
+2. Add `GlobalRequestMiddleware` to MIDDLEWARE in `pro/settings.py`:
+
+
+ ```python
+ MIDDLEWARE = [
+ ...
+ 'django_middleware_global_request.middleware.GlobalRequestMiddleware',
+ ...
+ ]
+ ```
+
+3. Use `get_request` to get the global request instance from a function in `pro/models.py`:
+
+ ```python
+ from django.db import models
+ from django.conf import settings
+ from django_middleware_global_request import get_request
+
+ class Book(models.Model):
+ name = models.CharField(max_length=64)
+ author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)
+
+ def __str__(self):
+ return self.name
+
+ def save(self, *args, **kwargs):
+ if not self.author:
+ request = get_request()
+ if request:
+ self.author = request.user
+ return super().save(*args, **kwargs)
+ ```
+
+4. Use `with GlobalRequest(xxx): pass` to set the global request to a new value in NON-USER-REQUEST context, e.g. in `management command` context or in `python manage.py shell` context. Out of the `with scope`, the global request instance will be reset to the value when entering into the `with scope`.
+
+ ```python
+ import djclick as click
+ from django.contrib.auth import get_user_model
+ from django_middleware_global_request_example.models import Book
+ from django_middleware_global_request import GlobalRequest
+
+
+ @click.command()
+ @click.option("-n", "--number", type=int, default=10)
+ def create(number):
+ admin = get_user_model().objects.all()[0]
+ with GlobalRequest(user=admin):
+ for i in range(number):
+ book = Book(name="book{idx}".format(idx=i+1))
+ book.save()
+ print(i, book.name, book.author.username)
+ ```
+
+5. Use `GlobalRequestStorage` to set the global request instance for current thread context. The global request instance will all time exists until you changed it by another value.
+
+*example.py*
+
+```
+from django.contrib.auth import get_user_model
+from django_middleware_global_request_example.models import Book
+from django_middleware_global_request import GlobalRequestStorage
+
+b1 = Book(name="b1")
+b1.save()
+print(b1, b1.author)
+
+admin = get_user_model().objects.get(username="admin")
+GlobalRequestStorage().set_user(admin)
+
+b2 = Book(name="b2")
+b2.save()
+print(b2, b2.author)
+
+b3 = Book(name="b3")
+b3.save()
+print(b3, b3.author)
+```
+
+*example result in python3 manage.py shell context*
+
+```
+test@test django-middleware-global-request % python3.9 manage.py shell
+Python 3.9.13 (main, Jun 8 2022, 15:40:49)
+Type 'copyright', 'credits' or 'license' for more information
+IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
+
+In [1]: import example
+b1 None
+b2 admin
+b3 admin
+```
+
+## Test report
+
+### Django 1.11.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+
+### Django 2.2.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 3.2.xx
+
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 4.0.xx
+
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+
+## Releases
+
+### v0.3.1
+
+- Add `app_middleware_requires` to module \_\_init\_\_.py to work with `django-app-requires`.
+
+### v0.3.0
+
+- Add `GlobalRequest` and `GlobalRequestStorage` to set the global request instance value for NON-USER-REQUEST context.
+
+### v0.2.0
+
+- Rename the core package from django_global_request to django_middleware_global_request so that it matches with the package name. **Note:** It's NOT backward compatible, all applications that using old name MUST do changes.
+
+### v0.1.2
+
+- Some changes.
+
+### v0.1.1
+
+- Some changes.
+
+### v0.1.0
+
+- First release.
+
+
+
+%package -n python3-django-middleware-global-request
+Summary: Django middleware that keep request instance for every thread.
+Provides: python-django-middleware-global-request
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-django-middleware-global-request
+# django-middleware-global-request
+
+
+Django middleware that keep request instance for every thread.
+
+## Install
+
+
+```shell
+pip install django-middleware-global-request
+```
+## Note
+
+- It's NOT good to use global request, you should pass the request instance from view to anywhere you want to use it.
+- If you use the global request in Model layout, it means when you call the Model method from Django Shell, you get a None request.
+
+## Usage
+
+1. Add django application `django_middleware_global_request` to INSTALLED_APPS in `pro/settings.py`:
+
+ ```python
+ INSTALLED_APPS = [
+ ...
+ 'django_middleware_global_request',
+ ...
+ ]
+ ```
+
+2. Add `GlobalRequestMiddleware` to MIDDLEWARE in `pro/settings.py`:
+
+
+ ```python
+ MIDDLEWARE = [
+ ...
+ 'django_middleware_global_request.middleware.GlobalRequestMiddleware',
+ ...
+ ]
+ ```
+
+3. Use `get_request` to get the global request instance from a function in `pro/models.py`:
+
+ ```python
+ from django.db import models
+ from django.conf import settings
+ from django_middleware_global_request import get_request
+
+ class Book(models.Model):
+ name = models.CharField(max_length=64)
+ author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)
+
+ def __str__(self):
+ return self.name
+
+ def save(self, *args, **kwargs):
+ if not self.author:
+ request = get_request()
+ if request:
+ self.author = request.user
+ return super().save(*args, **kwargs)
+ ```
+
+4. Use `with GlobalRequest(xxx): pass` to set the global request to a new value in NON-USER-REQUEST context, e.g. in `management command` context or in `python manage.py shell` context. Out of the `with scope`, the global request instance will be reset to the value when entering into the `with scope`.
+
+ ```python
+ import djclick as click
+ from django.contrib.auth import get_user_model
+ from django_middleware_global_request_example.models import Book
+ from django_middleware_global_request import GlobalRequest
+
+
+ @click.command()
+ @click.option("-n", "--number", type=int, default=10)
+ def create(number):
+ admin = get_user_model().objects.all()[0]
+ with GlobalRequest(user=admin):
+ for i in range(number):
+ book = Book(name="book{idx}".format(idx=i+1))
+ book.save()
+ print(i, book.name, book.author.username)
+ ```
+
+5. Use `GlobalRequestStorage` to set the global request instance for current thread context. The global request instance will all time exists until you changed it by another value.
+
+*example.py*
+
+```
+from django.contrib.auth import get_user_model
+from django_middleware_global_request_example.models import Book
+from django_middleware_global_request import GlobalRequestStorage
+
+b1 = Book(name="b1")
+b1.save()
+print(b1, b1.author)
+
+admin = get_user_model().objects.get(username="admin")
+GlobalRequestStorage().set_user(admin)
+
+b2 = Book(name="b2")
+b2.save()
+print(b2, b2.author)
+
+b3 = Book(name="b3")
+b3.save()
+print(b3, b3.author)
+```
+
+*example result in python3 manage.py shell context*
+
+```
+test@test django-middleware-global-request % python3.9 manage.py shell
+Python 3.9.13 (main, Jun 8 2022, 15:40:49)
+Type 'copyright', 'credits' or 'license' for more information
+IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
+
+In [1]: import example
+b1 None
+b2 admin
+b3 admin
+```
+
+## Test report
+
+### Django 1.11.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+
+### Django 2.2.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 3.2.xx
+
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 4.0.xx
+
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+
+## Releases
+
+### v0.3.1
+
+- Add `app_middleware_requires` to module \_\_init\_\_.py to work with `django-app-requires`.
+
+### v0.3.0
+
+- Add `GlobalRequest` and `GlobalRequestStorage` to set the global request instance value for NON-USER-REQUEST context.
+
+### v0.2.0
+
+- Rename the core package from django_global_request to django_middleware_global_request so that it matches with the package name. **Note:** It's NOT backward compatible, all applications that using old name MUST do changes.
+
+### v0.1.2
+
+- Some changes.
+
+### v0.1.1
+
+- Some changes.
+
+### v0.1.0
+
+- First release.
+
+
+
+%package help
+Summary: Development documents and examples for django-middleware-global-request
+Provides: python3-django-middleware-global-request-doc
+%description help
+# django-middleware-global-request
+
+
+Django middleware that keep request instance for every thread.
+
+## Install
+
+
+```shell
+pip install django-middleware-global-request
+```
+## Note
+
+- It's NOT good to use global request, you should pass the request instance from view to anywhere you want to use it.
+- If you use the global request in Model layout, it means when you call the Model method from Django Shell, you get a None request.
+
+## Usage
+
+1. Add django application `django_middleware_global_request` to INSTALLED_APPS in `pro/settings.py`:
+
+ ```python
+ INSTALLED_APPS = [
+ ...
+ 'django_middleware_global_request',
+ ...
+ ]
+ ```
+
+2. Add `GlobalRequestMiddleware` to MIDDLEWARE in `pro/settings.py`:
+
+
+ ```python
+ MIDDLEWARE = [
+ ...
+ 'django_middleware_global_request.middleware.GlobalRequestMiddleware',
+ ...
+ ]
+ ```
+
+3. Use `get_request` to get the global request instance from a function in `pro/models.py`:
+
+ ```python
+ from django.db import models
+ from django.conf import settings
+ from django_middleware_global_request import get_request
+
+ class Book(models.Model):
+ name = models.CharField(max_length=64)
+ author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)
+
+ def __str__(self):
+ return self.name
+
+ def save(self, *args, **kwargs):
+ if not self.author:
+ request = get_request()
+ if request:
+ self.author = request.user
+ return super().save(*args, **kwargs)
+ ```
+
+4. Use `with GlobalRequest(xxx): pass` to set the global request to a new value in NON-USER-REQUEST context, e.g. in `management command` context or in `python manage.py shell` context. Out of the `with scope`, the global request instance will be reset to the value when entering into the `with scope`.
+
+ ```python
+ import djclick as click
+ from django.contrib.auth import get_user_model
+ from django_middleware_global_request_example.models import Book
+ from django_middleware_global_request import GlobalRequest
+
+
+ @click.command()
+ @click.option("-n", "--number", type=int, default=10)
+ def create(number):
+ admin = get_user_model().objects.all()[0]
+ with GlobalRequest(user=admin):
+ for i in range(number):
+ book = Book(name="book{idx}".format(idx=i+1))
+ book.save()
+ print(i, book.name, book.author.username)
+ ```
+
+5. Use `GlobalRequestStorage` to set the global request instance for current thread context. The global request instance will all time exists until you changed it by another value.
+
+*example.py*
+
+```
+from django.contrib.auth import get_user_model
+from django_middleware_global_request_example.models import Book
+from django_middleware_global_request import GlobalRequestStorage
+
+b1 = Book(name="b1")
+b1.save()
+print(b1, b1.author)
+
+admin = get_user_model().objects.get(username="admin")
+GlobalRequestStorage().set_user(admin)
+
+b2 = Book(name="b2")
+b2.save()
+print(b2, b2.author)
+
+b3 = Book(name="b3")
+b3.save()
+print(b3, b3.author)
+```
+
+*example result in python3 manage.py shell context*
+
+```
+test@test django-middleware-global-request % python3.9 manage.py shell
+Python 3.9.13 (main, Jun 8 2022, 15:40:49)
+Type 'copyright', 'credits' or 'license' for more information
+IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
+
+In [1]: import example
+b1 None
+b2 admin
+b3 admin
+```
+
+## Test report
+
+### Django 1.11.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+
+### Django 2.2.xx
+
+- Python 3.5 passed
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 3.2.xx
+
+- Python 3.6 passed
+- Python 3.7 passed
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+### Django 4.0.xx
+
+- Python 3.8 passed
+- Python 3.9 passed
+- Python 3.10 passed
+
+
+## Releases
+
+### v0.3.1
+
+- Add `app_middleware_requires` to module \_\_init\_\_.py to work with `django-app-requires`.
+
+### v0.3.0
+
+- Add `GlobalRequest` and `GlobalRequestStorage` to set the global request instance value for NON-USER-REQUEST context.
+
+### v0.2.0
+
+- Rename the core package from django_global_request to django_middleware_global_request so that it matches with the package name. **Note:** It's NOT backward compatible, all applications that using old name MUST do changes.
+
+### v0.1.2
+
+- Some changes.
+
+### v0.1.1
+
+- Some changes.
+
+### v0.1.0
+
+- First release.
+
+
+
+%prep
+%autosetup -n django-middleware-global-request-0.3.1
+
+%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-middleware-global-request -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.3.1-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..e73f63a
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+a13e2c0b0f5de84e685ee99688408b7d django-middleware-global-request-0.3.1.tar.gz