Skip to content

Commit

Permalink
Switch to using django-user-agent instead od smartagent
Browse files Browse the repository at this point in the history
  • Loading branch information
crawley committed May 25, 2013
1 parent 2418482 commit b8f3913
Show file tree
Hide file tree
Showing 4 changed files with 893 additions and 7 deletions.
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
'pystache==0.5.2', # For server-side Mustache rendering to aid SEO
'rdflib==3.2.1', # For ANZSRCO parsing for ANZSRC FoR codes
'rdfextras==0.2', # For parsing n3 ANZSRCO
],
'django-user-agents==0.2.2', # For user agent sensing
'user-agents==0.1.1',
'ua-parser==0.3.2',
'PyYAML==3.10',
],
dependency_links = [
'https://github.com/dahlia/wand/tarball/warning-bugfix#egg=Wand-0.1.10',
'https://github.com/UQ-CMM-Mirage/django-celery/tarball/2.5#egg=django-celery-2.5.5',
Expand Down
17 changes: 15 additions & 2 deletions tardis/settings_changeme.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
'tardis.tardis_portal.auth.AuthorizationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'smartagent.middleware.UserAgentDetectorMiddleware')
)

ROOT_URLCONF = 'tardis.urls'

Expand Down Expand Up @@ -200,7 +200,6 @@ def get_admin_media_path():
'kombu.transport.django',
'bootstrapform',
'mustachejs',
'smartagent',
)

JASMINE_TEST_DIRECTORY = path.abspath(path.join(path.dirname(__file__),
Expand Down Expand Up @@ -395,3 +394,17 @@ def get_admin_media_path():

# Site's preferred archive types, with the most preferred first
DEFAULT_ARCHIVE_FORMATS = ['zip', 'tar']

# If you want enable user agent sensing, copy this to settings.py
# and uncomment it.
#
#USER_AGENT_SENSING = True
#if USER_AGENT_SENSING:
# from os import environ
# # Workaround for bug in ua_parser ... can't find its builtin copy
# # of regexes.yaml ... in versions 0.3.2 and earlier. Remove when fixed.
# environ['UA_PARSER_YAML'] = '/opt/mytardis/current/ua_parser_regexes.yaml'
#
# INSTALLED_APPS = INSTALLED_APPS + ('django_user_agents',)
# MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + \
# ('django_user_agents.middleware.UserAgentMiddleware',)
12 changes: 8 additions & 4 deletions tardis/tardis_portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,23 @@ def _add_protocols_and_organizations(request, experiment, c):
streaming ZIP, the best way to avoid 'user disappointment'
is to not offer ZIP."""

logger.error('browser_data is %s' % getattr(request, 'browser_data', {}))
mac = getattr(request, 'browser_data', {}).get('platform') == 'MacOSX'
if getattr(settings, 'USER_AGENT_SENSING', False) and \
request.user_agent:
logger.debug('user_agent.os.family: %s' % request.user_agent.os.family)
cannot_do_zip = request.user_agent.os.family == 'Macintosh'
else:
cannot_do_zip = False

c['protocol'] = []
download_urls = experiment.get_download_urls()
for key, value in download_urls.iteritems():
if mac and key == 'zip':
if cannot_do_zip and key == 'zip':
continue
c['protocol'] += [[key, value]]

formats = getattr(settings, 'DEFAULT_ARCHIVE_FORMATS', ['zip', 'tar'])
c['default_format'] = filter(
lambda x: not (mac and x == 'zip'), formats)[0]
lambda x: not (cannot_do_zip and x == 'zip'), formats)[0]

from tardis.tardis_portal.download import get_download_organizations
c['organization'] = ['classic'] + get_download_organizations()
Expand Down
Loading

0 comments on commit b8f3913

Please sign in to comment.