mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
Add Google Places lookup to event creation page #171
This commit is contained in:
parent
473366a928
commit
87ba6ea5bb
@ -38,6 +38,14 @@ def insert_admin_unit_for_user(admin_unit, user):
|
||||
admin_unit.logo.encoding_format,
|
||||
)
|
||||
db.session.add(organizer)
|
||||
|
||||
# Place anlegen
|
||||
place = EventPlace()
|
||||
place.admin_unit_id = admin_unit.id
|
||||
place.name = admin_unit.location.city
|
||||
place.location = Location()
|
||||
assign_location_values(place.location, admin_unit.location)
|
||||
db.session.add(place)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
||||
@ -4,13 +4,17 @@ from project import db
|
||||
from project.models import EventPlace, Location
|
||||
|
||||
|
||||
def upsert_event_place(admin_unit_id, name):
|
||||
result = EventPlace.query.filter(
|
||||
def get_event_place(admin_unit_id, name):
|
||||
return EventPlace.query.filter(
|
||||
and_(
|
||||
EventPlace.name == name,
|
||||
EventPlace.admin_unit_id == admin_unit_id,
|
||||
)
|
||||
).first()
|
||||
|
||||
|
||||
def upsert_event_place(admin_unit_id, name):
|
||||
result = get_event_place(admin_unit_id, name)
|
||||
if result is None:
|
||||
result = EventPlace(name=name, admin_unit_id=admin_unit_id)
|
||||
result.location = Location()
|
||||
|
||||
@ -660,7 +660,7 @@
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_google_place_autocomplete_header(location_only = False) %}
|
||||
{% macro render_google_place_autocomplete_header(location_only = False, prefix = '') %}
|
||||
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={{ "dev" | env_override('GOOGLE_MAPS_API_KEY') }}&libraries=places"></script>
|
||||
<script>
|
||||
function initialize() {
|
||||
@ -685,24 +685,24 @@
|
||||
} else if (addressType == 'locality') {
|
||||
city = val;
|
||||
} else if (addressType == 'administrative_area_level_1') {
|
||||
$('#location-state').val(val);
|
||||
$('#{{ prefix }}location-state').val(val);
|
||||
} else if (addressType == 'postal_code') {
|
||||
$('#location-postalCode').val(val);
|
||||
$('#{{ prefix }}location-postalCode').val(val);
|
||||
}
|
||||
}
|
||||
|
||||
{% if not location_only %}
|
||||
$('#name').val(place.name);
|
||||
$('#{{ prefix }}name').val(place.name);
|
||||
|
||||
if (place.website) {
|
||||
$('#url').val(place.website);
|
||||
$('#{{ prefix }}url').val(place.website);
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
$('#location-street').val([route, street_number].join(' '));
|
||||
$('#location-city').val(city);
|
||||
$('#location-latitude').val(place.geometry.location.lat());
|
||||
$('#location-longitude').val(place.geometry.location.lng());
|
||||
$('#{{ prefix }}location-street').val([route, street_number].join(' '));
|
||||
$('#{{ prefix }}location-city').val(city);
|
||||
$('#{{ prefix }}location-latitude').val(place.geometry.location.lat());
|
||||
$('#{{ prefix }}location-longitude').val(place.geometry.location.lng());
|
||||
|
||||
$('#location_search').val('');
|
||||
});
|
||||
@ -713,11 +713,13 @@
|
||||
|
||||
{% macro render_google_place_autocomplete_field() %}
|
||||
<div class="form-group row">
|
||||
<div class="input-group col-sm-12">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fab fa-google"></i></span>
|
||||
<div class="col-sm-12">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><span><i class="fab fa-google"></i></span></span>
|
||||
</div>
|
||||
<input id="location_search" type="text" class="form-control" placeholder="{{ _('Search location on Google') }}" runat="server" />
|
||||
</div>
|
||||
<input id="location_search" type="text" class="form-control" placeholder="{{ _('Search location on Google') }}" autocomplete="on" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
{% extends "layout.html" %}
|
||||
{% from "_macros.html" import render_cropper_header, render_cropper_code, render_crop_image_form_section, render_radio_buttons, render_datepicker_js, render_field_with_errors, render_field %}
|
||||
{% from "_macros.html" import render_google_place_autocomplete_field, render_google_place_autocomplete_header, render_cropper_header, render_cropper_code, render_crop_image_form_section, render_radio_buttons, render_datepicker_js, render_field_with_errors, render_field %}
|
||||
{% block title %}
|
||||
{{ _('Create event') }}
|
||||
{% endblock %}
|
||||
{% block header %}
|
||||
{{ render_cropper_header() }}
|
||||
{{ render_google_place_autocomplete_header(False, 'new_event_place-') }}
|
||||
<script>
|
||||
$( function() {
|
||||
|
||||
@ -119,6 +120,7 @@ $( function() {
|
||||
</div>
|
||||
|
||||
<div class="my-4" id="new_place_container">
|
||||
{{ render_google_place_autocomplete_field() }}
|
||||
{{ form.new_event_place.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.new_event_place.form.name, is_required=True) }}
|
||||
{{ form.new_event_place.form.location.hidden_tag() }}
|
||||
|
||||
@ -31,6 +31,7 @@ def test_create(client, app, utils, seeder):
|
||||
from project.access import has_current_user_member_role_for_admin_unit
|
||||
from project.services.admin_unit import get_admin_unit_by_name
|
||||
from project.services.organizer import get_event_organizer
|
||||
from project.services.place import get_event_place
|
||||
|
||||
admin_unit = get_admin_unit_by_name("Meine Crew")
|
||||
assert admin_unit is not None
|
||||
@ -46,7 +47,11 @@ def test_create(client, app, utils, seeder):
|
||||
assert organizer.name == "Meine Crew"
|
||||
assert organizer.location.city == "Goslar"
|
||||
assert organizer.location.postalCode == "38640"
|
||||
assert organizer is not None
|
||||
|
||||
place = get_event_place(admin_unit.id, "Goslar")
|
||||
assert place.name == "Goslar"
|
||||
assert place.location.city == "Goslar"
|
||||
assert place.location.postalCode == "38640"
|
||||
|
||||
|
||||
def test_create_duplicate(client, app, utils, seeder):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user