Change waze link based on user-agent : waze app if on mobile, waze website on computer

This commit is contained in:
Gabriel Augendre 2018-04-03 18:10:07 +02:00
parent 8659460df0
commit 8dcf4512cc
No known key found for this signature in database
GPG key ID: F360212F958357D4
4 changed files with 39 additions and 14 deletions

View file

@ -16,7 +16,8 @@ dj-database-url = "*"
django-dotenv = "*" django-dotenv = "*"
plotly = "*" plotly = "*"
django-mailgun = "*" django-mailgun = "*"
GitPython = "*" gitpython = "*"
user-agents = "*"
[dev-packages] [dev-packages]

29
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "ff9c47e65fda61f6f8bea06608d98efd43543fc0a3f8ec6875ec19194e4d9116" "sha256": "cc44337d7912156851006c24c9009a73569bebb47744ad4cf669878219127a10"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": {}, "requires": {},
@ -45,11 +45,11 @@
}, },
"django": { "django": {
"hashes": [ "hashes": [
"sha256:3d9916515599f757043c690ae2b5ea28666afa09779636351da505396cbb2f19", "sha256:2d8b9eed8815f172a8e898678ae4289a5e9176bc08295676eff4228dd638ea61",
"sha256:769f212ffd5762f72c764fa648fca3b7f7dd4ec27407198b68e7c4abf4609fd0" "sha256:d81a1652963c81488e709729a80b510394050e312f386037f26b54912a3a10d0"
], ],
"index": "pypi", "index": "pypi",
"version": "==2.0.3" "version": "==2.0.4"
}, },
"django-bootstrap4": { "django-bootstrap4": {
"hashes": [ "hashes": [
@ -75,11 +75,11 @@
}, },
"djangorestframework": { "djangorestframework": {
"hashes": [ "hashes": [
"sha256:1f6baf40ed456ed2af6bd1a4ff8bbc3503cebea16509993aea2b7085bc097766", "sha256:bb9d74756a6b157bfb2e395b200b11f87c837f45f5e097b2308ed7a526e7dcbe",
"sha256:9f9e94e8d22b100ed3a43cee8c47a7ff7b185e778a1f2da9ec5c73fc4e081b87" "sha256:be299fb3f289e22ddca0ff88294924cd06aa3bcfa5043f72792d2a18d96dabe8"
], ],
"index": "pypi", "index": "pypi",
"version": "==3.7.7" "version": "==3.8.0"
}, },
"gitdb2": { "gitdb2": {
"hashes": [ "hashes": [
@ -221,12 +221,27 @@
], ],
"version": "==4.3.2" "version": "==4.3.2"
}, },
"ua-parser": {
"hashes": [
"sha256:0aafb05a67b621eb4d69f6c1c3972f2d9443982bcd9132a8b665d90cd48a1add",
"sha256:c39c50c948f915601564a1cf98bdc578e72a29595181b3d133f5ab4a5c9fb6e3"
],
"version": "==0.7.3"
},
"urllib3": { "urllib3": {
"hashes": [ "hashes": [
"sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b",
"sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"
], ],
"version": "==1.22" "version": "==1.22"
},
"user-agents": {
"hashes": [
"sha256:0ce5b1b44c8d11b9f3d6152ef9c8a2109409273ef8de600d577f549a3a3cbc6c",
"sha256:643d16772280052b546d956971d719989ef6dc9b17d9ff0386aa21391a038039"
],
"index": "pypi",
"version": "==1.1.0"
} }
}, },
"develop": {} "develop": {}

View file

@ -42,11 +42,20 @@ class RoomDetailView(LoginRequiredMixin, QuickActionsMixin, SessionResetMixin, g
] ]
if self.object.latitude and self.object.longitude: if self.object.latitude and self.object.longitude:
from user_agents import parse
user_agent = parse(self.request.META.get('HTTP_USER_AGENT'))
if user_agent.is_mobile:
quick_actions.append({ quick_actions.append({
'url': f"waze://?ll={self.object.latitude},{self.object.longitude}&navigate=yes", 'url': f"waze://?ll={self.object.latitude},{self.object.longitude}&navigate=yes",
'category': 'info', 'category': 'info',
'display': 'Waze' 'display': 'Waze'
}) })
else:
quick_actions.append({
'url': f"https://waze.com/ul?ll={self.object.latitude},{self.object.longitude}",
'category': 'info',
'display': 'Waze'
})
return quick_actions return quick_actions
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):

View file

@ -29,8 +29,8 @@ DEBUG = os.getenv('DJANGO_ENV', 'prod') == 'dev'
ALLOWED_HOSTS = ['workout.augendre.info', 'web', 'workout', 'workout-web'] ALLOWED_HOSTS = ['workout.augendre.info', 'web', 'workout', 'workout-web']
if DEBUG: if DEBUG:
ALLOWED_HOSTS.extend([ ALLOWED_HOSTS.extend([
'192.168.1.27',
'localhost', 'localhost',
os.getenv('CURRENT_IP', '192.168.1.27')
]) ])
ADMINS = [('Gabriel', os.getenv('ADMIN_EMAIL')), ] ADMINS = [('Gabriel', os.getenv('ADMIN_EMAIL')), ]