Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
cc07adb0
Verified
Commit
cc07adb0
authored
Oct 01, 2018
by
Sébastiaan Versteeg
Browse files
Move google maps creation to template tag and add parameters
parent
0fac9c0a
Changes
7
Hide whitespace changes
Inline
Side-by-side
docs/utils.templatetags.rst
View file @
cc07adb0
...
...
@@ -9,6 +9,14 @@ utils.templatetags package
Submodules
----------
utils.templatetags.google\_map\_url module
------------------------------------------
.. automodule:: utils.templatetags.google_map_url
:members:
:undoc-members:
:show-inheritance:
utils.templatetags.thumbnail module
-----------------------------------
...
...
website/events/services.py
View file @
cc07adb0
import
hmac
from
hashlib
import
sha1
from
base64
import
urlsafe_b64decode
,
urlsafe_b64encode
from
collections
import
OrderedDict
from
django.template.defaultfilters
import
urlencode
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
get_language
from
events
import
emails
from
events.exceptions
import
RegistrationError
from
events.models
import
Registration
,
RegistrationInformationField
from
django.conf
import
settings
def
is_user_registered
(
member
,
event
):
...
...
@@ -237,21 +232,3 @@ def registration_fields(member, event):
else
:
raise
RegistrationError
(
_
(
"You are not allowed to update this registration."
))
def
create_google_maps_url
(
event
):
maps_url
=
(
f
"/maps/api/staticmap?"
f
"center=
{
urlencode
(
event
.
map_location
)
}
&"
f
"zoom=13&size=450x250&"
f
"markers=
{
urlencode
(
event
.
map_location
)
}
&"
f
"key=
{
settings
.
GOOGLE_MAPS_API_KEY
}
"
)
decoded_key
=
urlsafe_b64decode
(
settings
.
GOOGLE_MAPS_API_SECRET
)
signature
=
hmac
.
new
(
decoded_key
,
maps_url
.
encode
(),
sha1
)
encoded_signature
=
urlsafe_b64encode
(
signature
.
digest
())
maps_url
+=
f
"&signature=
{
encoded_signature
.
decode
(
'utf-8'
)
}
"
return
"https://maps.googleapis.com"
+
maps_url
website/events/templates/events/event.html
View file @
cc07adb0
{% extends "base.html" %}
{% load i18n static bleach_tags thumbnail %}
{% load i18n static bleach_tags thumbnail
google_map_url
%}
{% block title %}{{ event.title }} — {% trans "Calendar"|capfirst %} — {{ block.super }}{% endblock %}
{% block opengraph_title %}{{ event.title }} — {% trans "Calendar"|capfirst %} — {{ block.super }}{% endblock %}
...
...
@@ -200,7 +200,7 @@
<div
class=
"span6"
>
<div
class=
"location-map"
>
<img
src=
"{
{
map
s
_url }}"
/>
<img
src=
"{
% google_
map_url
event.location %}"
alt=
"{{ event.location
}}"
/>
</div>
</div>
</div>
...
...
website/events/views.py
View file @
cc07adb0
"""Views provided by the events package"""
from
hashlib
import
sha1
import
hmac
from
base64
import
decodebytes
,
encodebytes
,
urlsafe_b64decode
,
\
urlsafe_b64encode
from
urllib.parse
import
quote
from
django.contrib
import
messages
from
django.contrib.auth.decorators
import
login_required
...
...
@@ -18,7 +13,6 @@ from events import services
from
events.exceptions
import
RegistrationError
from
.forms
import
FieldsForm
from
.models
import
Event
,
Registration
from
thaliawebsite
import
settings
class
EventIndex
(
TemplateView
):
...
...
@@ -70,8 +64,6 @@ class EventDetail(DetailView):
context
[
'date_now'
]
=
timezone
.
now
()
context
[
'maps_url'
]
=
services
.
create_google_maps_url
(
event
)
return
context
...
...
website/partners/templates/partners/partner.html
View file @
cc07adb0
{% extends "base.html" %}
{% load i18n bleach_tags %}
{% load i18n bleach_tags
google_map_url
%}
{% block title %}{{ partner.name }} — {% trans "Partners" %} — {% trans "Career" %} — {{ block.super }}{% endblock %}
{% block opengraph_title %}{{ partner.name }} — {% trans "Partners" %} — {% trans "Career" %} — {{ block.super }}{% endblock %}
...
...
@@ -69,7 +69,9 @@
{% endif %}
</div>
<div
class=
"span7 offset1"
>
<img
src=
"https://maps.google.com/maps/api/staticmap?center={{ partner.address|urlize }}%20{{ partner.zip_code|urlize }}%20{{ partner.city|urlize }},the+netherlands&zoom=10&size=620x200&maptype=roadmap&markers=color:0xE62272%7Clabel:%7C{{ partner.address|urlize }}%20{{ partner.zip_code|urlize }}%20{{ partner.city|urlize }},the+netherlands&sensor=false"
/>
{% with partner.address|add:" "|add:partner.zip_code|add:" "|add:partner.city|add:",The Netherlands"|urlize as location %}
<img
src=
"{% google_map_url location zoom=10 size='650x200' %}"
/>
{% endwith %}
</div>
</div>
...
...
website/utils/snippets.py
View file @
cc07adb0
"""Provides various utilities that are useful across the project"""
import
hmac
from
_sha1
import
sha1
from
base64
import
urlsafe_b64decode
,
urlsafe_b64encode
from
django.conf
import
settings
from
django.utils
import
timezone
from
django.template.defaultfilters
import
urlencode
def
datetime_to_lectureyear
(
date
):
...
...
@@ -26,3 +32,21 @@ def datetime_to_lectureyear(date):
if
date
<
sept_1
.
date
():
return
date
.
year
-
1
return
date
.
year
def
create_google_maps_url
(
location
,
zoom
,
size
):
maps_url
=
(
f
"/maps/api/staticmap?"
f
"center=
{
urlencode
(
location
)
}
&"
f
"zoom=
{
zoom
}
&size=
{
size
}
&"
f
"markers=
{
urlencode
(
location
)
}
&"
f
"key=
{
settings
.
GOOGLE_MAPS_API_KEY
}
"
)
decoded_key
=
urlsafe_b64decode
(
settings
.
GOOGLE_MAPS_API_SECRET
)
signature
=
hmac
.
new
(
decoded_key
,
maps_url
.
encode
(),
sha1
)
encoded_signature
=
urlsafe_b64encode
(
signature
.
digest
())
maps_url
+=
f
"&signature=
{
encoded_signature
.
decode
(
'utf-8'
)
}
"
return
"https://maps.googleapis.com"
+
maps_url
website/utils/templatetags/google_map_url.py
0 → 100644
View file @
cc07adb0
from
django
import
template
from
utils.snippets
import
create_google_maps_url
register
=
template
.
Library
()
@
register
.
simple_tag
()
def
google_map_url
(
location
,
zoom
=
13
,
size
=
'450x250'
):
return
create_google_maps_url
(
location
,
zoom
,
size
)
Luko van der Maas
@lukomaas
mentioned in commit
4d853a80
·
Oct 03, 2018
mentioned in commit
4d853a80
mentioned in commit 4d853a809f15f058bce124603c87b4d8b561b637
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment