Skip to content

Commit 17d291d

Browse files
author
can
committed
changed attr name
1 parent a6e075d commit 17d291d

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ pip install django-ismobile
1616

1717
## Using
1818

19-
Include to your INSTALLED_APPS:
19+
Include MobileControlMiddleware into your MIDDLEWARE:
2020

2121
```
22-
INSTALLED_APPS = (
22+
MIDDLEWARE = (
2323
...
24-
'ismobile',
24+
'ismobile.middleware.MobileControlMiddleware',
2525
...
2626
)
2727
```
2828

29-
Include MobileControlMiddleware into your MIDDLEWARE:
29+
## Config
30+
31+
In order to change request attribute name,
32+
set **IS_MOBILE_ATTR_NAME** in django **settings** file.
3033

3134
```
32-
MIDDLEWARE = (
33-
...
34-
'ismobile.middleware.MobileControlMiddleware',
35-
...
36-
)
35+
IS_MOBILE_ATTR_NAME="custom_name"
3736
```

ismobile/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self, get_response):
88
self.get_response = get_response
99

1010
def __call__(self, request):
11-
is_mobile_attr_name = getattr(settings, "IS_MOBILE", "IS_MOBILE")
11+
is_mobile_attr_name = getattr(settings, "IS_MOBILE_ATTR_NAME", "IS_MOBILE")
1212
is_mobile_value = get_is_mobil(request.META.get("HTTP_USER_AGENT"))
1313
setattr(request, is_mobile_attr_name, is_mobile_value)
1414
response = self.get_response(request)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-ismobile"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "Middleware for Django."
55
authors = ["Can Sarigol <ertugrulsarigol@gmail.com>"]
66
packages = [

tests/test_middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_middleware(self):
77
request = Client().get("/").wsgi_request
88
assert hasattr(request, "IS_MOBILE")
99

10-
@override_settings(IS_MOBILE="ismobile")
10+
@override_settings(IS_MOBILE_ATTR_NAME="ismobile")
1111
def test_middleware_custom_attr(self):
1212
request = Client().get("/").wsgi_request
1313
assert hasattr(request, "ismobile")

0 commit comments

Comments
 (0)