Commit 53ed60a4 authored by Elger Jonker's avatar Elger Jonker

[wip] removed google map widgets, severly improved creating new organizations


Former-commit-id: a97c2bdd
parent 345384e0
......@@ -11,9 +11,7 @@ from django.forms import ValidationError
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django_countries.fields import CountryField
from django_countries.widgets import CountrySelectWidget
from django_select2.forms import Select2TagWidget
from mapwidgets.widgets import GooglePointFieldWidget
from failmap.game.models import Contest, OrganizationSubmission, Team, UrlSubmission
from failmap.organizations.models import Organization, OrganizationType, Url
......@@ -107,54 +105,56 @@ class OrganisationSubmissionForm(forms.Form):
super(OrganisationSubmissionForm, self).__init__(*args, **kwargs)
field_order = ('organization_country', 'organization_type_name', 'organization_name',
'organization_address_geocoded', 'organization_address',
'organization_evidence')
organization_country = CountryField().formfield(
label="Country",
widget=CountrySelectWidget(),
initial="NL"
)
# todo: filter based on country and organization type.
# todo: but how to suggest new organizations?
organization_type_name = forms.ModelChoiceField(
queryset=OrganizationType.objects.all(),
widget=autocomplete.ModelSelect2(url='/game/autocomplete/organization-type-autocomplete/'),
label="Type",
help_text="All types are rendered as separate layers on the map."
)
organization_name = forms.CharField(
label="Name"
)
organization_address_geocoded = forms.CharField(
widget=GooglePointFieldWidget,
label="Address"
latitude = forms.DecimalField(
max_digits=9,
decimal_places=6,
)
organization_address = forms.CharField(
widget=forms.Textarea
longitude = forms.DecimalField(
max_digits=9,
decimal_places=6,
)
organization_evidence = forms.CharField(
# "The full address of this organization, at it's current address. If there are multiple addresses, "
# "take the one that's the most important. If they are equally important, just add them with a location"
# "address. The points will be merged lateron."
organization_address = forms.CharField(
widget=forms.Textarea,
label="Sources verifying the existence of this organization"
required=True
)
organization_wikipedia = forms.URLField(
label="Wikipedia page",
help_text="To quickly find the correct wiki page, start a search by "
help_text="Autofilled. Might be wrong. To quickly find the correct wiki page, start a search by "
"clicking <a href='https://en.wikipedia.org/w/index.php?search="
"ministry+van+binnenlandse+zaken&title=Special:Search&go=Go'>here: search wikipedia</a>."
"ministry+van+binnenlandse+zaken&title=Special:Search&go=Go'>here: search wikipedia</a>.",
required=False
)
organization_wikidata = forms.CharField(
label="Wikidata code",
help_text="Find a Q code on <a href='https://www.wikidata.org/wiki/"
"Wikidata:Main_Page' target='_blank'>wikidata</a>."
help_text="Autofilled. Might be wrong. Find a Q code on <a href='https://www.wikidata.org/wiki/"
"Wikidata:Main_Page' target='_blank'>wikidata</a>.",
required=False
)
organization_type_name = forms.ModelChoiceField(
queryset=OrganizationType.objects.all(),
widget=autocomplete.ModelSelect2(url='/game/autocomplete/organization-type-autocomplete/'),
label="Type / Map Layer",
help_text="Types are rendered as separate layers on the map."
)
organization_evidence = forms.CharField(
widget=forms.Textarea,
label="Sources verifying the existence of this organization",
required=False,
help_text=""
)
# todo: clean the geolocated address to fit the rest of the system. The ugly
......@@ -166,7 +166,7 @@ class OrganisationSubmissionForm(forms.Form):
cleaned_data = super().clean()
organization_type_name = cleaned_data.get("organization_type_name")
name = cleaned_data.get("organization_name")
country = cleaned_data.get("organization_country")
country = self.contest.target_country
exists = Organization.objects.all().filter(
type=organization_type_name, name=name, is_dead=False, country=country).exists()
......@@ -195,6 +195,7 @@ class OrganisationSubmissionForm(forms.Form):
organization_evidence = self.cleaned_data.get('organization_address', None)
organization_wikipedia = self.cleaned_data.get('organization_wikipedia', None)
organization_wikidata = self.cleaned_data.get('organization_wikidata', None)
# organization_address_geocoded comes from the new input... todo
organization_address_geocoded = self.cleaned_data.get('organization_address_geocoded', None)
if not all([organization_name, organization_type_name, organization_address, organization_evidence]):
......@@ -218,6 +219,13 @@ class OrganisationSubmissionForm(forms.Form):
)
submission.save()
# based on: https://www.gyford.com/phil/writing/2017/03/16/django-admin-map/
# Loading this JS AFTER via the media options doesn't work...
class Media:
css = {
'all': ('css/location_picker.css',),
}
class UrlSubmissionForm(forms.Form):
......
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map33 {
height: 400px;
}
#description {
font-family: Roboto;
font-size: 15px;
font-weight: 300;
}
#infowindow-content .title {
font-weight: bold;
}
#infowindow-content {
display: none;
}
#map #infowindow-content {
display: inline;
}
.pac-card {
margin: 10px 10px 0 0;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
background-color: #fff;
font-family: Roboto;
}
#pac-container {
padding-bottom: 12px;
margin-right: 12px;
}
.pac-controls {
display: inline-block;
padding: 5px 11px;
}
.pac-controls label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 400px;
}
#pac-input:focus {
border-color: #4d90fe;
}
#title {
color: #fff;
background-color: #4d90fe;
font-size: 25px;
font-weight: 500;
padding: 6px 12px;
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ from datetime import datetime
import pytz
from dal import autocomplete
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, Q
......@@ -97,9 +98,10 @@ def submit_organisation(request):
return render(request, 'game/submit_organisation.html', {'form': form, 'success': True})
else:
form = OrganisationSubmissionForm(team=request.session.get('team'), contest=get_default_contest(request))
form = OrganisationSubmissionForm(team=request.session.get('team'), contest=get_default_contest(request),)
return render(request, 'game/submit_organisation.html', {'form': form})
return render(request, 'game/submit_organisation.html', {'form': form,
'GOOGLE_MAPS_API_KEY': settings.GOOGLE_MAPS_API_KEY})
def scores(request):
......@@ -404,16 +406,12 @@ class OrganizationAutocomplete(autocomplete.Select2QuerySetView):
class OrganizationTypeAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = OrganizationType.objects.all().filter()
paginate_by = 100
def get_queryset(self):
# country = self.forwarded.get('country', None)
#
# todo: this gives a cartesian product, of course. Distinct on fields not supported by sqlite...
# so that doesn't work during development.
# if country:
# qs = qs.filter(organization__country=country)
qs = OrganizationType.objects.all().filter().order_by('name')
if self.q:
qs = qs.filter(name__icontains=self.q)
......
......@@ -382,45 +382,44 @@ var failmap = {
// mapdata.onEachFeature(function (new_feature){ doesn;'t work
mapdata.features.forEach(function (new_feature){
if (existing_feature.properties.organization_name !== new_feature.properties.organization_name) {
return;
}
if (JSON.stringify(new_feature.geometry.coordinates) !== JSON.stringify(existing_feature.geometry.coordinates)) {
// Geometry changed, updating shape. Will not fade.
// It seems not possible to update the geometry of a shape, too bad.
failmap.polygons.removeLayer(layer);
failmap.polygons.addData(new_feature);
});
for (i = 0; i < mapdata.features.length; i++) {
new_feature = mapdata.features[i];
if (existing_feature.properties.organization_name === new_feature.properties.organization_name) {
// No simple array comparison in JS
// So new_feature.geometry.coordinates !== existing_feature.geometry.coordinates will not work.
// https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript#19746771
if (JSON.stringify(new_feature.geometry.coordinates) !== JSON.stringify(existing_feature.geometry.coordinates)){
// Geometry changed, updating shape. Will not fade.
// It seems not possible to update the geometry of a shape, too bad.
failmap.polygons.removeLayer(layer);
failmap.polygons.addData(new_feature);
} else {
// colors changed, shapes / points on the map stay the same.
existing_feature.properties.Overall = new_feature.properties.Overall;
existing_feature.properties.color = new_feature.properties.color;
// make the transition
switch(existing_feature.geometry.type){
case "Polygon":
case "MultiPolygon":
layer.setStyle(failmap.style(layer.feature)); break;
case "Point":
switch(layer.feature.properties.color) {
case "red": layer.setIcon(failmap.redIcon); break;
case "orange": layer.setIcon(failmap.orangeIcon); break;
case "green": layer.setIcon(failmap.greenIcon); break;
default: layer.setIcon(failmap.grayIcon);
}
break;
}
} else {
// colors changed, shapes / points on the map stay the same.
existing_feature.properties.Overall = new_feature.properties.Overall;
existing_feature.properties.color = new_feature.properties.color;
// make the transition
switch (existing_feature.geometry.type) {
case "Polygon":
case "MultiPolygon":
layer.setStyle(failmap.style(layer.feature));
break;
case "Point":
switch (layer.feature.properties.color) {
case "red":
layer.setIcon(failmap.redIcon);
break;
case "orange":
layer.setIcon(failmap.orangeIcon);
break;
case "green":
layer.setIcon(failmap.greenIcon);
break;
default:
layer.setIcon(failmap.grayIcon);
}
break;
}
}
}
});
},
showreport: function (e) {
......
......@@ -793,17 +793,10 @@ LOGIN_REDIRECT_URL = '/game/'
LOGIN_URL = '/authentication/login/'
LOGOUT_REDIRECT_URL = '/'
MAP_WIDGETS = {
"GooglePointFieldWidget": (
("zoom", 4),
("mapCenterLocationName", "Europe"),
("GooglePlaceAutocompleteOptions", {'componentRestrictions': {}}), # 'country': 'nl'
("markerFitZoom", 17),
),
"GOOGLE_MAP_API_KEY": os.environ.get('GOOGLE_MAP_API_KEY', "AIzaSyBXJbEUxGW1dAB4hJOlmKdYelfoRY6_fjo")
}
CRISPY_TEMPLATE_PACK = 'bootstrap3'
GOOGLE_MAPS_API_KEY = os.environ.get('GOOGLE_MAP_API_KEY', "AIzaSyBXJbEUxGW1dAB4hJOlmKdYelfoRY6_fjo")
# End game settigns
#######
......
......@@ -93,8 +93,6 @@ django-fsm-log
# game requirements
django-crispy-forms
django-autocomplete-light
geocoder
django-map-widgets # uses gdal, now in alpine edge :)
django-admin-sortable2 # nice sorting in the admin, used in map configurations.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment