Code Monkey home page Code Monkey logo

django-mobile's People

Contributors

alanjds avatar alexandrevicenzi avatar dittaeva avatar gregmuellegger avatar igalarzab avatar mbaechtold avatar mikeurbanski avatar mucca avatar ojomio avatar prokaktus avatar sinkler avatar vikalp avatar wolfg1969 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

django-mobile's Issues

Withdrawn

Sorry, I misread the way this code works. Closing this.

self.request.flavour not work in view

I try in view:
if self.request.flavour == "mobile":

print self.request.flavour olways 'full' in view and in template request.flavour == "mobile"

class SetFlavourMiddleware(object):
def process_request(self, request):
_init_flavour(request) # it's not initialise right print self.request.flavour olways 'full' in view

RuntimeError: maximum recursion depth exceeded while calling a Python object

Hi there !

I don't know why but at the moment when I add the following line in my TEMPLATE_LOADERS:
'django_mobile.loader.Loader',

I get those errors in the console:

(recursion pattern of the same 4 errors)

File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django_mobile-0.2.2-py2.7.egg/django_mobile/loader.py", line 29, in load_template
return loader(template_name, template_dirs)
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django/template/loader.py", line 42, in call
return self.load_template(template_name, template_dirs)
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django/template/loaders/cached.py", line 44, in load_template
template, origin = self.find_template(template_name, template_dirs)
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django/template/loaders/cached.py", line 29, in find_template
for loader in self.loaders:
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django/template/loaders/cached.py", line 25, in loaders
self._cached_loaders.append(find_template_loader(loader))
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django/template/loader.py", line 104, in find_template_loader
func = TemplateLoader(*args)
File "/home/ybroy/public_html/gildan/local/lib/python2.7/site-packages/django_mobile-0.2.2-py2.7.egg/django_mobile/loader.py", line 12, in init
for loader_name in settings.FLAVOURS_TEMPLATE_LOADERS:
RuntimeError: maximum recursion depth exceeded while calling a Python object

I'm on Python 2.7.2 + Django 1.3.1

Adding Python 3 support

Now Django support for Python 3 can be considered as stable, I think it won't be a bad idea to start porting this app to Python 3.

I tried to make it work with Python 3 and it seems to work. I haven't done much testing that's why I haven't initialized a pull request.

Here is my code: https://github.com/machakux/django-mobile .

'function' object has no attribute 'get_full_path'

This is my url in urls.py:

('^', cache_page(IndexView.as_view(), CACHE_TIMEOUT, key_prefix=CACHE_PREFIX), {}, 'index'),

I get this error when i use django_mobile.cache.cache_page decorator:
'function' object has no attribute 'get_full_path'

Should i place CacheFlavourMiddleware somewhere?

Adding smart watch flavour ?

I am trying out things and wondered how I can add another flavour, from the doc it seems it could be implemented rather easy. Any clue as to how I could do this?

Got 'django.template.loader_tags.ExtendsError' when customizing admin interface in Django 1.9

I have customizedd admin page by extending 'admin/base_site.html' template. The admin page is broken after add 'django_mobile.loader.Loader' to loaders of TEMPLATES settings. The error is 'ExtendsError: Cannot extend templates recursively when using non-recursive template loaders'.

My TEMPLATES Settings is below:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'sekizai.context_processors.sekizai',
                'django_mobile.context_processors.flavour',
            ],
            'loaders': [
                'django_mobile.loader.Loader',
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ]
        },
    },
]

Added support for COOKIE.

like sessions, added support for setting cookies for flavour, as sessions get flushed on django auth user logout, and if you want to persist the non login flow on selected flavour there is no way, other then get requests.

Couple of things.

  1. COOKIE needs to be set by the code, i didn't change in set_flavour ( if author suggests i think we should do that)
  2. COOKIE will only be picked if flavor is None (We might have to look at precedence though in detail)

BTW very nice piece of code, hope this helps, and finds its way into main code. :)

Thanks.

Samsung tablet GT-P6800 isn't detected as mobile device

Hi,

My tablet isn't recognized as mobile device. Here is chrome browser user agent:

Mozilla/5.0 (Linux; Android 4.0.4; GT-P6800 Build/IMM76D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Safari/537.36

Is it possible to somehow fix this? Thanks!

"'WSGIRequest' object has no attribute 'flavour'" when flavour would be 'full'.

After installing django_mobile for the first time, I noticed that when hit a view with a desktop browser (either Firefox or Chromium), the flavour attribute on the request object doesn't exist. However, going to the same view on my phone results in flavour being set to 'mobile'.

Is it intended to not set the attribute in the case of a non-mobile client, or should it be set to 'full'? The later is what I'd expect.

Here's a little test project that reproduces this behavior: https://github.com/thatjpk/django_mobile_test
Tested on the django development server with Chromium 16, Firefox 9, and the Android browser on 4.0.3.

iPad not a mobile device?

OOTB, this does not recognize an iPad 2 as a mobile device. (At least, not when it's on wi-fi.)

What is the rationale for that?

Django 1.10 incompatibility

Hey,

I just upgraded to Django 1.10, and here's the startup error:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "xxx/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "xxx/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "xxx/venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "xxx/venv/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "xxx/venv/lib/python3.5/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/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 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "xxx/venv/lib/python3.5/site-packages/django_mobile/__init__.py", line 10, in <module>
    from django_mobile.conf import settings
  File "xxx/venv/lib/python3.5/site-packages/django_mobile/conf.py", line 23, in <module>
    class defaults(object):
  File "xxx/venv/lib/python3.5/site-packages/django_mobile/conf.py", line 33, in defaults
    for loader in django_settings.TEMPLATE_LOADERS:
  File "xxx/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 54, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'TEMPLATE_LOADERS'

Feature requiest: add switch flavour view

Hi Greg,

Thanks for creating this wonderful library, working perfectly!

Would you like the idea of adding a view for switching flavours, so users can switch flavours by going to /switch/flavour/xxx ? I am planning to include this view in every project, so maybe more people can benefit.

I'm currently using this view:

from django_mobile import set_flavour
from django.http import HttpResponseRedirect

def theme_switcher(request, flavour):
    """Switch to a different theme. Default options: full, mobile."""
    set_flavour(flavour, permanent=True)
    next_page = request.GET.get('next', '/')
    return HttpResponseRedirect(next_page)

Regards, Wim

ThreadLocals issue with multithreaded and multiprocess hosting of app on mod_wsgi

I don't know if you are or anyone else has faced this with django_mobile. But we ended up in a very nasty issue i think mainly because threadlocals has been used.

We host our app on mod_wsgi on multi threaded/multi process environment, the issue that we were facing was randomly the flavor set by middle ware gets overridden and hence on mobile randomly desktop or full templates are rendered.

I did a hack which is not so elegant, where in i override render_to_response and checked for flavour there as request object is available as a context there. hence overriding the threadlocals set_flavour call.

Now we are not facing that random issue. Just wanted to highlight that, would be great if there are options other then treadlocals to use.

iPad not detected as mobile

user_agent:

'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'

Testing

'Shortest' way to alter HTTP_USER_AGENT ... in settings.py when testing?

Of course this shouldn't work.

settings.py
if 'MOBILE' in os.environ and bool(os.environ['MOBILE']) == True:
    FLAVOURS = ('mobile')
$MOBILE=True ./manage.py test

django-mobile should not be packaged as a django project

django-mobile is currently packaged as a django project. This causes problems when installing django-mobile using pip editable mode. For example:

pip install -E my_environment git+git://github.com/gregmuellegger/django-mobile.git#egg=django-mobile

Since the django-mobile src dir is put into the pythonpath, the settings.py file takes precedence over my project's settings.py file.

Simply removing manage.py and settings.py should fix the problem.

How to disable mobile detection

Hello! Nice lib, big thanks to author.
I wonder if there is the way to disable mobile detection inside some of django apps?
Other should be still detected.
Thank you in advance.

recent version of opera mobile on android doesn't match

It identifies itself as "Opera/9.80 (Android 2.3.3; Linux; Opera Mobi/ADR-1111101157; U; en) Presto/2.9.201 Version/11.50". When I access my django-mobile enabled site with this client, I am still getting a full version of the site.

cache_page(per-page-cache) is not working correctly.

I've integrated django-mobile into my website along with Django Cache enabled but I noticed that the per-page-cache were not read and the framework sends database queries even though the pages exist in cache.

After some investigation, I found out that the issue was caused by cache_page and CacheFlavourMiddleware not taking into account the sequence of the cache process.

Expected Sequence:
Set "HTTP_X_FLAVOUR" header -> FetchFromCacheMiddleware -> Set "Vary: X-Flavour" header -> UpdateCacheMiddleware

Current Sequence:
FetchFromCacheMiddleware -> Set "HTTP_X_FLAVOUR" header -> Set "Vary: X-Flavour" header -> UpdateCacheMiddleware

So FetchFromCacheMiddleware always looks for invalid cache.

Django 1.10 support

Does this support 1.10 and on? Feels like it doesn't since I get the error:

AttributeError: 'Settings' object has no attribute 'TEMPLATE_LOADERS'

when I try to run django-mobile on anything above 1.9. Is that just me? I know that when I get it to work I skip the setup step involving the django_mobile.loader.Loader and just ignore that and it works perfectly fine.

Over time, more desktops are detecting as "mobile"...

We've used this package on a site (American Experience) and while it's done a great job for several years, we're getting complaints from some users that their browser is being detected as mobile when it's not. The frequency of these complaints is increasing with time. I've checked the lists in MobileDetectionMiddleware (middeware.py) and it doesn't appear to have changed...

Of course user complaints aren't providing information like "Oh and BTW, my user agent is [this] in case it helps" :-) so tracking down the offending user agent string(s) has not been successful.

Has anyone else experienced this effect? Has anyone made adjustments to the regex lists that improve accuracy? I'd appreciate any wisdom/suggestions...

CachedLoader breaks application

Hello!

We are using django-mobile in our project.

We use Django 1.9 and experienced trouble with cached loader: it ruined the application down with exceptions:

  1. ./manage.py runserver just crashed when tried to set flavour to mobile
  2. uwsgi has a maximum recursion depth exceeded when tried to set flavour to mobile

Our templates configuration is like this:

templates/base.html
templates/mobile/base.html

mobile/base.html has {% extends "base.html" %}

In this situation problem started to appear.

We had to turn off cached loaders at all, because django-mobile's loader is broken and Django's cached loader do not working with django-mobile.

As far as i see, the problem is in django-mobile's CachedLoader implementation β€” it does not understand what current flavour is, so it generate broken cache key for both base.html and mobile/base.html, which looks like this:

full:base.html

So the mobile template tries to extend "base.html", but gets itself content (with extend) instead of original, root base.html.

Template name for Class Based View.

Hey I've got it to work but when I created the 'mobile/directory/venue_index.html and venue_list.html it doesn't use the templates. Sure it's some small thing I just missed.

class VenueList(JSONResponseMixin, MultipleObjectTemplateResponseMixin, BaseListView):
    model = Venue
    paginate_by = 20
    context_object_name = 'venues'
    category = None
    slug_level = ""
    area = None

    template_name = 'directory/venue_index.html'

    def get_queryset(self):
        if self.request.is_mobile:
            qs = Venue.objects.filter(visible=True,).order_by('-hot', '-created')
            if self.kwargs.get('category', None):
                self.template_name = 'directory/venue_list.html'
                slugs = self.kwargs['category'].strip('/').split('/')
                self.category = get_object_or_404(Category, slug=slugs[-1])
                qs = qs.filter(categories__in=self.category.get_descendants(include_self=True))
            if self.kwargs.get('area', None):
                self.template_name = 'directory/venue_list.html'

                self.template_name = 'directory/venue_list.html'
                slugs = self.kwargs['area'].strip('/').split('/')
                self.area = get_object_or_404(Area, slug=slugs[-1])
                qs = qs.filter(area__in=self.area.get_descendants(include_self=True))
            if self.request.META.get('HTTP_ACCEPT', None) == 'application/json':
                qs = qs.filter(longitude__isnull=False, latitude__isnull=False).exclude(longitude=0, latitude=0).order_by('name')
            self.queryset = qs.distinct()
            return self.queryset

Android tablet not recog as mobile

django-mobile is not able to tell me I'm in a mobile device when accessing from an Android tablet. This problem occurs in every browser I've tested.

Follow the user agents:

Android browser: Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; GT-P7510 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30

Firefox for Android: Mozilla/5.0 (Android; Tablet; rv:29.0) Gecko/29.0 Firefox/29.0

Chrome for Android: Mozilla/5.0 (Linux; Android 4.0.4; GT-P7510 Build/IMM76D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.141 Safari/537.36

Skip mobile detection after flavour is saved permanently

Hi, thanks for this great middleware!

After reading the source around, I found that MobileDetectionMiddleware will work on every request, which I think maybe is not necessary. If the flavour is saved in backend, why not just read it?

Or there is something I have missed >_<

On first visit of a mobile device, {{ flavour }} eq 'mobile' even non-mobile device

I tested version 0.1.2.

I "runserver 0.0.0.0:8000", and tried the following sequence on the URL http://$IP:8000/

  • On desktop computer, Chromium browser (chrome under linux), the value of {{ flavour }} is 'full'
  • If I press reload on my Chromium: {{ flavour }} == 'full'.
  • On desktop computer, with Firefox: {{ flavour }} == 'full'
  • The I take my Android Nexus One, GET http://$ip:8000/, {{ flavour }} == 'mobile'

Everythings is alright there. it turn out weird after the first Mobile browser is used.

  • If I refresh on my Chrome browser, the value of {{ flavour }} == 'mobile' :(
  • If I refresh desktop firefox, {{ flavour }} == 'mobile'

Until I kill the Django-admin Python process and restart the web server, {{ flavour }} is always 'mobile'.
I do not use CACHE_BACKEND.

here are some sections of my settings.py

TEMPLATE_LOADERS = (
'django_mobile.loader.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

TEMPLATE_CONTEXT_PROCESSORS = (
'satchmo_store.shop.context_processors.settings',
'django.core.context_processors.auth',
'django_mobile.context_processors.flavour',
'django.core.context_processors.media',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django_mobile.middleware.MobileDetectionMiddleware',
'django_mobile.middleware.SetFlavourMiddleware',
'threaded_multihost.middleware.ThreadLocalMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'satchmo_store.shop.SSLMiddleware.SSLRedirect',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)

And django_mobile is in my INSTALLED_APPS

cache not being installed.

For some reason neither the version fro PIPY or running setup from a clone version here installed the django_mobile.cache module.

No option to provide empty exceptions

There is not possibility to provide empty list of exceptions search.

The default one is:
user_agents_exception_search = u"(?:%s)" % u'|'.join((
'ipad',
))

Providing:
user_agents_exception_search = u"(?:%s)" % u'|'.join((
))
crushes the detection.

Python warning about Template Loaders

Following documentation with py2.7 and django 1.2.3, getting this warning.

 /home/michela/dev/lib/python2.7/site-packages/django/template/loader.py:113: UserWarning:     Your TEMPLATE_LOADERS setting includes 'django_mobile.loader.Loader', but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS.
warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % loader)

set_flavour with permanent=False has no effect

I have a couple pages that I want to disable the mobile flavour for. To do this, I have written custom middleware that wraps the default middleware that sets flavour to 'full' always for these pages. To do this, I call set_flavour with permanent=False because I don't want them stuck on the 'full' version after this request. However, set_flavour with permanent=False has no effect.

I traced the code and figured out why. set_flavour does not set the flavour using the storage mechanism (typically cookies)...as expected. All good so far. But the problem is that get_flavour checks storage for the flavour before checking request.flavour or _local.flavour. Therefore, because set_flavour didn't a cookie, get_flavour will never return the temporary flavour I have forced.

It seems to me that get_flavour should simply check request.flavour or _local.flavour before checking flavour_storage.

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.