Giter VIP home page Giter VIP logo

django-user_agents's People

Contributors

bashu avatar caxap avatar dannyboscan avatar grschafer avatar hwkns avatar joehybird avatar mrjmad avatar selwin avatar therealtomrose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-user_agents's Issues

Extended RequestFactory should be provided

Django provides RequestFactory for testing views https://docs.djangoproject.com/en/dev/topics/testing/advanced/#the-request-factory . This django-user_agents module extends the Request object, but doesn't provide any extension to the RequestFactory and so makes blackbox testing of views difficult.

Two possible solutions might be:

  • Extend the README with a recipe for extending the RequestFactory result at test time.
  • Provide an extended RequestFactory that accepts user_agent parameters.

crash with django 4 and redis

i have a django 4 app using redis for cache

it work fine with memCache

but error while using redis

exc_info=(<class 'ModuleNotFoundError'>, ModuleNotFoundError("No module named 'redis'"), <traceback object at 0x7fe6b633de40>)

'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379',

already try pip install redis / django_redis but still error.

'WSGIRequest' object has no attribute 'user_agent'

If anyone can help with this error I'd be very appreciative. I think I have the settings correct:

INSTALLED_APPS = (
'... Lots of apps',
'django_user_agents'
)

MIDDLEWARE_CLASSES = (
'... Lots of middleware',
'django_user_agents.middleware.UserAgentMiddleware'
)

Traceback (most recent call last): File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/core/handlers/exception.py", line 42, in inner response = get_response(request) File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response response = self._get_response(request) File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "/Users/Greg/Development/propel/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch return handler(request, *args, **kwargs) File "/Users/Greg/Google Drive/Propel/PropelSurveySolutions/questionnaire/views.py", line 42, in post print self.request.user_agent.is_mobile AttributeError: 'WSGIRequest' object has no attribute 'user_agent'

Device not detected

Device is not detected while requesting from browser (Chrome, Firefox) on Ubuntu 16.04. Getting this:

Device(family='Other', brand=None, model=None)

Improvements for User Agent recognition

Here are some improvements I would recommend to apply.

These type of User Agents are not being recognized as "tablet":

Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPad5,4;FBMD/iPad;FBSN/iOS;FBSV/10.3.1;FBSS/2;FBCR/movistar;FBID/tablet;FBLC/es_ES;FBOP/5;FBRV/0]

These type of User Agents are not being recognized as "PC":

Mozilla/5.0 (X11; CrOS x86_64 9202.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.148 Safari/537.36

These types of User Agents are not being recognized as "mobile":

Mozilla/5.0 (iPod touch; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPod7,1;FBMD/iPod touch;FBSN/iOS;FBSV/10.2.1;FBSS/2;FBCR/;FBID/phone;FBLC/es_LA;FBOP/5;FBRV/56133369]

Mozilla/5.0 (Mobile; ALCATELOneTouch4019A; rv:28.0) Gecko/28.0 Firefox/28.0

It should be great to add the "is_smart_tv" feature for these type of User Agents:

Mozilla/5.0 (SMART-TV; Linux; Tizen 2.4.0) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.1 TV Safari/538.1

Also memcache is needed

Hello, another dependency that is needed to install via pip is python-memcached, but you did't mention it in the documentation.
Best regards.

Slowing down testing

Package is working great. When I am testing with a test db, though, I get a looong pause on:

Operations to perform:
  Synchronize unmigrated apps: admindocs, colorfield, dbbackup, django_archive, django_user_agents, messages, staticfiles
  Apply all migrations: admin, auth, benchmarks, contenttypes, gbook, sessions
Running pre-migrate handlers for application gbook
Running pre-migrate handlers for application benchmarks
Running pre-migrate handlers for application admin
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application django_user_agents
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
Running migrations:
  No migrations to apply.
Running post-migrate handlers for application gbook
Running post-migrate handlers for application benchmarks
Running post-migrate handlers for application admin
Running post-migrate handlers for application auth
Running post-migrate handlers for application contenttypes
Running post-migrate handlers for application sessions
Running post-migrate handlers for application django_user_agents

This last line - everything else goes by fast, and it takes a minute or more to clear the django_user_agents line. Anybody know what causes that or how to speed it up? Seen this before, @selwin ?

Thanks!

Django 1.11 issue

It's error with Django 1.11
mw_instance = middleware(handler)
TypeError: object() takes no parameters

Still maintained?

Hey @selwin, thanks for all of your work on this.

But are you still interested in maintaining this?

There are a few PRs and issues that can be merge and handled.

You can also turn it over to the jazzband organization for maintenance and new releases.

Chrome on Ipad returns True for Mobile and Tablet

On Chrome for Ipad the method is_mobile and is_tablet returns True for both cases.

Is this normal? Shouldn't it return False for mobile?

Are there any other known situations where mobile and tablet both return True?

Thanks!

New release

Could you release a new version? The fixes for using this with 1.10 would be particularly useful.

Thanks!

Caching is unnecessary

Caching the results seems unnecessary https://github.com/selwin/django-user_agents/blob/master/django_user_agents/utils.py#L41, since uap-python doesn't actually load the yamls anymore, but they are converted to python in the build process.

See here https://github.com/ua-parser/uap-python/blob/master/setup.py#L20 and here https://github.com/ua-parser/uap-python/blob/master/ua_parser/user_agent_parser.py#L548.

So this is loaded and imported once and then cached by the python importing system anyways.

Module Not Found.

Followed every steps provided in documentation but still it gives the following error while migrating.

Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    main()
  File "manage.py", line 19, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/local/Cellar/[email protected]/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_user_agents'

jazzband?

As I can see this project having quite a few users (and willing contributors), but a maintainer with a lack of time, it may be an option to transfer it to jazzband? (https://jazzband.co/) so it get's the attention it deserves, and less frustration... any opinion on this @selwin ?

adding screen size detection tags?

Wondered how 'screen size' detection can be added to the tag for mobile/ desktop templates. Today, many Android/ iOS devices have wide screen resolution. Mostly current solution is OS based mobile/desktop detection, so on a 1200px screen, mobile site is displayed.

none for USER_AGENTS_CACHE

I installed and used django-user-agents in a 2.7 django project, using v4 of this repo. The README advised None for USER_AGENTS__CACHE. Upon trying it I got an error, specifically, I got this:
InvalidCacheBackendError: Could not find config for 'None' in settings.CACHES

Commented the USER_AGENTS_CACHE out and it worked fine though.

pip install django-user-agents does not install django_user_agents folder

Hi,

Great package, I like it and am checking it out.
However, after pip install django-user-agents the django_user_agents folder with the templatetags folder and the test folder are not installed. Therefore the tests can't be run after installation. Is this supposed to be like that?

Best regards,

Guido

list of devices not detected

the following user agent info are detected as "Generic_Android"
hope you can add these devices detection

Mozilla/5.0 (Linux; Android 6.0; S9L Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/WIFI Language/zh_CN

Mozilla/5.0 (Linux; Android 8.0; STF-AL10 Build/HUAWEISTF-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.3.1260(0x26060339) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 8.0; HWI-AL00 Build/HUAWEIHWI-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.3.1260(0x26060339) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 5.1.1; NX529J Build/LMY47V; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 7.0; PRO 7-H Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; U; Android 6.0; zh-cn; NCE-AL10 Build/HUAWEINCE-AL10) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 Chrome/37.0.0.0 MQQBrowser/8.0 Mobile Safari/537.36

Mozilla/5.0 (Linux; U; Android 7.1.1; zh-CN; MX6 Build/NMF26O) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.0.970 Mobile Safari/537.36

Mozilla/5.0 (Linux; Android 6.0; PLK-TL01H Build/HONORPLK-TL01H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 7.1.2; M6 Note Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/WIFI Language/zh_CN

Mozilla/5.0 (Linux; Android 8.0; MHA-AL00 Build/HUAWEIMHA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060533) NetType/WIFI Language/zh_CN

Mozilla/5.0 (Linux; Android 6.0.1; KIW-AL10 Build/HONORKIW-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.3.1260(0x26060339) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 7.0; BLN-AL10 Build/HONORBLN-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/2G Language/zh_CN

Mozilla/5.0 (Linux; Android 5.1.1; KIW-AL10 Build/HONORKIW-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.5.23.1180 NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 7.0; DUK-AL20 Build/HUAWEIDUK-AL20; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043906 Mobile Safari/537.36 MicroMessenger/6.6.3.1260(0x26060339) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 7.0; BLN-AL40 Build/HONORBLN-AL40; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043906 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 8.0; H4133 Build/50.1.A.4.76; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.3.1260(0x26060339) NetType/WIFI Language/zh_CN

Mozilla/5.0 (Linux; Android 7.0; WAS-AL00 Build/HUAWEIWAS-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_CN

Mozilla/5.0 (Linux; Android 6.0.1; M3X Build/MMB29U; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043909 Mobile Safari/537.36 MicroMessenger/6.6.5.1280(0x26060532) NetType/4G Language/zh_HK

Type checking with mypy

I'm using mypy with the Django plugin. When I reference request.user_agent with a function like this:

from django.core.handlers.wsgi import WSGIRequest

def get_application(request: WSGIRequest) -> Application:
    if request.user_agent.is_mobile:
      pass

mypy complains:

error: "WSGIRequest" has no attribute "user_agent"

Is there a way to resolve this error? All I can think of right now is to ignore it with # type: ignore.

Here is the mypy config file for reference:

[mypy]
ignore_missing_imports = True

plugins =
    mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = myapp.settings.base

InvalidTemplateLibrary raised, trying to load 'django_user_agents.templatetags.user_agents' (Django 3.0.7)

Hello,

Seems that Django 3.0.7 with python3.9 breaks things

Here is the error
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'django_user_agents.templatetags.user_agents': cannot import name 'get_and_set_user_agent' from partially initialized module 'django_user_agents.utils' (most likely due to a circular import) (/blablablablablabla/python3.9/site-packages/django_user_agents/utils.py)

The problem appears randomly by restarting runserver (run and debugger with pycharm)

UserAgentMiddleware is not working in Django 1.10

UserAgentMiddleware is not working with Django 1.10. If it is inserted into the list of middlewares in settings file, an error occurs such as below.

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10e19c158>
Traceback (most recent call last):
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/Users/adrysn/.pyenv/versions/3.5.0/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/adrysn/lablup/neumann/neumann/wsgi.py", line 17, in <module>
    application = get_wsgi_application()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/Users/adrysn/.pyenv/versions/neumann35/lib/python3.5/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

This error is probably due to the changed style of middleware introduced in Django 1.10:
https://docs.djangoproject.com/en/1.10/topics/http/middleware/.

The middleware class should be updated to comply with the new style.

For the moment, one can replace object to MiddlewareMixin to enable the middleware.

from django.utils.deprecation import MiddlewareMixin

class UserAgentMiddleware(MiddlewareMixin):
...

Curl and other apps

So I am using curl to access my website. Your middleware detects Curl as "Other" browser family which is not what I (and probably many people) need. Could you change that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.