Skip to content

Commit a6e075d

Browse files
author
Can Sarigol
committed
init
1 parent 52c3c5c commit a6e075d

21 files changed

+524
-64
lines changed

.github/workflows/release.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build-n-publish:
10+
name: Build and publish to PyPI
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Set up Python 3.6
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: 3.6
18+
- name: Install poetry
19+
run: >-
20+
python -m
21+
pip install
22+
poetry
23+
--user
24+
- name: Build
25+
run: >-
26+
python -m
27+
poetry build
28+
- name: Publish to PyPI
29+
env:
30+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_PASSWORD }}
31+
run: >-
32+
python -m
33+
poetry publish

.github/workflows/tests.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
9+
jobs:
10+
tests:
11+
name: "Check lint and tests"
12+
runs-on: "ubuntu-latest"
13+
steps:
14+
- uses: actions/checkout@master
15+
- name: Set up Python 3.6
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: 3.6
19+
- name: Install nox
20+
run: |
21+
pip install nox
22+
- name: Run check
23+
run: |
24+
nox --sessions check
25+
- name: Run test
26+
run: |
27+
nox --sessions test

MANIFEST.in

-3
This file was deleted.

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lint:
2+
poetry run nox --sessions lint
3+
4+
test:
5+
poetry run nox --sessions check && poetry run nox --sessions test

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# django-ismobile
2+
3+
4+
"is_mobile" middleware for Django
5+
6+
## Requirements
7+
Requires Django 2.0 or later.
8+
9+
## Installing
10+
11+
Install with `pip` or your favorite PyPi package manager.
12+
13+
```
14+
pip install django-ismobile
15+
```
16+
17+
## Using
18+
19+
Include to your INSTALLED_APPS:
20+
21+
```
22+
INSTALLED_APPS = (
23+
...
24+
'ismobile',
25+
...
26+
)
27+
```
28+
29+
Include MobileControlMiddleware into your MIDDLEWARE:
30+
31+
```
32+
MIDDLEWARE = (
33+
...
34+
'ismobile.middleware.MobileControlMiddleware',
35+
...
36+
)
37+
```

README.rst

-20
This file was deleted.

docs/blank.txt

-1
This file was deleted.

ismobile/middleware.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
from django.conf import settings
2+
13
from .utils import get_is_mobil
24

5+
36
class MobileControlMiddleware(object):
47
def __init__(self, get_response):
58
self.get_response = get_response
69

710
def __call__(self, request):
8-
request.IS_MOBILE = get_is_mobil(request.META.get('HTTP_USER_AGENT'))
11+
is_mobile_attr_name = getattr(settings, "IS_MOBILE", "IS_MOBILE")
12+
is_mobile_value = get_is_mobil(request.META.get("HTTP_USER_AGENT"))
13+
setattr(request, is_mobile_attr_name, is_mobile_value)
914
response = self.get_response(request)
1015
return response

ismobile/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import re
22

3+
is_mobile_re = re.compile(r".*(iphone|mobile|androidtouch)", re.IGNORECASE)
34

4-
is_mobile_re=re.compile(r".*(iphone|mobile|androidtouch)",re.IGNORECASE)
55

66
def get_is_mobil(http_user_agent):
77
if http_user_agent is None:
88
# Default to assuming desktop if no user-agent header is
99
# present.
1010
return False
11-
return is_mobile_re.match(http_user_agent) != None
11+
return is_mobile_re.match(http_user_agent) is not None

manage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

noxfile.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import nox
2+
3+
nox.options.stop_on_first_error = True
4+
5+
SOURCE_FILES = "ismobile", "tests", "noxfile.py"
6+
7+
8+
@nox.session
9+
def lint(session, reuse_venv=True):
10+
session.install("autoflake", "isort==5.*", "black")
11+
session.run("autoflake", "--in-place", "--recursive", *SOURCE_FILES)
12+
session.run("black", *SOURCE_FILES)
13+
session.run("isort", *SOURCE_FILES)
14+
15+
16+
@nox.session
17+
def check(session, reuse_venv=True):
18+
session.install("flake8", "isort==5.*", "black")
19+
session.run("flake8", *SOURCE_FILES)
20+
session.run("black", "--check", "--diff", *SOURCE_FILES)
21+
session.run("isort", "--check", "--diff", *SOURCE_FILES)
22+
23+
24+
@nox.session
25+
@nox.parametrize("django", ["2.0", "2.2", "3.0"])
26+
def test(session, django, reuse_venv=True):
27+
session.install(f"django=={django}", "pytest", "pytest-django", "pytest-cov")
28+
session.run("pytest", "--cov-report", "term-missing", "--cov=ismobile", "tests")

0 commit comments

Comments
 (0)