mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-03 01:17:56 +03:00
Updated checkbrowser to recognize ie, new ie (11), opera, safari, firefox & webkit based browsers
This commit is contained in:
parent
ae9f3c7e78
commit
6e0511add3
@ -32,6 +32,7 @@
|
|||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -73,39 +74,80 @@ def extractKey(dictionary, key, **kwargs):
|
|||||||
value = default
|
value = default
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
# Regular expressions for User Agents
|
||||||
|
# These both are for Internet Explorer
|
||||||
|
_msie = re.compile('MSIE ([0-9]+)\.([0-9]+)')
|
||||||
|
_trident = re.compile('Trident/.*rv:([0-9]+)\.([0-9]+)')
|
||||||
|
# Opera
|
||||||
|
_opera = re.compile('OPR/([0-9]+)\.([0-9]+)')
|
||||||
|
# Firefox
|
||||||
|
_firefox = re.compile('Firefox/([0-9]+)\.([0-9]+)')
|
||||||
|
# Chrome
|
||||||
|
_chrome = re.compile('Chrome/([0-9]+)\.([0-9]+)')
|
||||||
|
# Webkit in general
|
||||||
|
_webkit = re.compile('AppleWebKit/([0-9]+)\.([0-9]+)')
|
||||||
|
|
||||||
|
_browsers = {
|
||||||
|
'ie' : [_trident, _msie],
|
||||||
|
'opera': [_opera],
|
||||||
|
'firefox': [_firefox],
|
||||||
|
'chrome': [_chrome],
|
||||||
|
'webkit': [_webkit],
|
||||||
|
}
|
||||||
|
|
||||||
def checkBrowser(user_agent, browser):
|
def checkBrowser(user_agent, browser):
|
||||||
'''
|
'''
|
||||||
Known browsers right now:
|
Known browsers right now:
|
||||||
ie[version]
|
ie[version]
|
||||||
ie<[version]
|
ie<[version]
|
||||||
'''
|
'''
|
||||||
import re
|
|
||||||
# Split brwosers we look for
|
# Split brwosers we look for
|
||||||
needs_msie = False
|
needs_browser = None
|
||||||
needs_version = 6
|
needs_version = 0
|
||||||
needs = '='
|
needs = ''
|
||||||
|
|
||||||
if browser[:2] == 'ie':
|
regexs = None
|
||||||
needs_msie = True
|
|
||||||
if browser[2] == '<' or browser[2] == '>' or browser[2] == '=':
|
|
||||||
needs = browser[2]
|
|
||||||
needs_version = int(browser[3:])
|
|
||||||
else:
|
|
||||||
needs_version = int(browser[2:])
|
|
||||||
|
|
||||||
try:
|
for b, res in _browsers.iteritems():
|
||||||
if needs_msie:
|
if browser.startswith(b):
|
||||||
msie = re.compile('MSIE ([0-9]+)\.([0-9]+)')
|
logger.debug('Found: {0}'.format(b))
|
||||||
matches = msie.search(user_agent)
|
regexs = res
|
||||||
if matches is None:
|
browser = browser[len(b):]
|
||||||
return False
|
|
||||||
version = int(matches.groups()[0])
|
if regexs is None:
|
||||||
if needs == '<':
|
return False
|
||||||
return version < needs_version
|
|
||||||
elif needs == '>':
|
browser += ' ' # So we ensure we have at least beowser 0
|
||||||
return version > needs_version
|
|
||||||
|
if browser[0] == '<' or browser[0] == '>' or browser[0] == '=':
|
||||||
|
needs = browser[0]
|
||||||
|
needs_version = int(browser[1:])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
needs = '='
|
||||||
|
needs_version = int(browser)
|
||||||
|
except:
|
||||||
|
needs = ''
|
||||||
|
needs_version = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
matches = None
|
||||||
|
for r in regexs:
|
||||||
|
matches = r.search(user_agent)
|
||||||
|
if matches is not None:
|
||||||
|
break
|
||||||
|
if matches is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
version = int(matches.groups()[0])
|
||||||
|
if needs == '<':
|
||||||
|
return version < needs_version
|
||||||
|
elif needs == '>':
|
||||||
|
return version > needs_version
|
||||||
|
elif needs == '=':
|
||||||
return version == needs_version
|
return version == needs_version
|
||||||
|
|
||||||
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -29,12 +29,14 @@
|
|||||||
width: 48px;
|
width: 48px;
|
||||||
height: 48px;
|
height: 48px;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% ifbrowser ie<9 %}
|
/* We need to write under button */
|
||||||
.btn-group {
|
.btn-group {
|
||||||
max-width: 114px;
|
max-width: 114px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{% ifbrowser firefox %}
|
||||||
|
{% else %}
|
||||||
.btn .caret {
|
.btn .caret {
|
||||||
margin-left: -4px;
|
margin-left: -4px;
|
||||||
}
|
}
|
||||||
@ -60,6 +62,9 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
{% ifbrowser webkit %}
|
||||||
|
webkit!!!
|
||||||
|
{% endifbrowser %}
|
||||||
<h2>{% trans "Services" %}</h2>
|
<h2>{% trans "Services" %}</h2>
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
{% for ser in services %}
|
{% for ser in services %}
|
||||||
@ -121,7 +126,8 @@
|
|||||||
<p>{% trans "Ip" %}: {{ ip }}</p>
|
<p>{% trans "Ip" %}: {{ ip }}</p>
|
||||||
<p>{% trans "Networks" %}: {{ nets }}</p>
|
<p>{% trans "Networks" %}: {{ nets }}</p>
|
||||||
<p>{% trans "Transports" %}: {{ transports }}</p>
|
<p>{% trans "Transports" %}: {{ transports }}</p>
|
||||||
|
<p>{% trans "User Agent" %}: {{ request.META.HTTP_USER_AGENT }}</p>
|
||||||
|
<p>{% trans "OS" %}: {{ request.session.OS.OS }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -431,4 +431,4 @@ def download(request, idDownload):
|
|||||||
last_modified_date = timezone.now()
|
last_modified_date = timezone.now()
|
||||||
@last_modified(lambda req, **kw: last_modified_date)
|
@last_modified(lambda req, **kw: last_modified_date)
|
||||||
def jsCatalog(request, lang, domain='djangojs', packages=None):
|
def jsCatalog(request, lang, domain='djangojs', packages=None):
|
||||||
return javascript_catalog(request, domain, packages)
|
return javascript_catalog(request, domain, packages)
|
||||||
|
Loading…
Reference in New Issue
Block a user