diff --git a/rowers/forms.py b/rowers/forms.py
index d3b23329..440e38cb 100644
--- a/rowers/forms.py
+++ b/rowers/forms.py
@@ -947,7 +947,26 @@ class PlanSelectForm(forms.Form):
class CourseSelectForm(forms.Form):
- course = forms.ModelChoiceField(queryset=GeoCourse.objects.all())
+ course = forms.ModelChoiceField(queryset=GeoCourse.objects.filter())
+
+ def __init__(self, *args, **kwargs):
+ course = kwargs.pop('course',None)
+ manager = kwargs.pop('manager',None)
+ super(CourseSelectForm,self).__init__(*args,**kwargs)
+ if course is not None:
+ print('aap',course)
+ d_min = 0.5*course.distance
+ d_max = 2*course.distance
+ country = course.country
+ countries = ['unknown',country]
+ print(countries)
+ self.fields['course'].queryset = self.fields['course'].queryset.filter(
+ distance__gt = d_min,distance__lt = d_max,
+ country__in = countries
+ ).exclude(id=course.id)
+ if manager is not None:
+ self.fields['course'].queryset = self.fields['course'].queryset.filter(manager=manager)
+ print(self.fields['course'].queryset)
class WorkoutSingleSelectForm(forms.Form):
workout = forms.ModelChoiceField(
diff --git a/rowers/models.py b/rowers/models.py
index a3f0d391..c292d8eb 100644
--- a/rowers/models.py
+++ b/rowers/models.py
@@ -1221,6 +1221,7 @@ class GeoCourse(models.Model):
name = models.CharField(max_length=150,blank=True)
country = models.CharField(max_length=150,blank=True)
notes = models.CharField(blank=True,max_length=200,verbose_name='Course Notes')
+
def __str__(self):
name = self.name
country = self.country
@@ -1236,6 +1237,10 @@ class GeoCourse(models.Model):
d = d,
)
+ @property
+ def coord(self):
+ return course_coord_center(self)
+
class GeoCourseEditForm(ModelForm):
class Meta:
model = GeoCourse
diff --git a/rowers/templates/course_view.html b/rowers/templates/course_view.html
index 312ee33f..b7c9da70 100644
--- a/rowers/templates/course_view.html
+++ b/rowers/templates/course_view.html
@@ -30,13 +30,16 @@
Notes {{ course.notes|linebreaks }}
+
+ Manager {{ course.manager }}
+
{{ mapdiv|safe }}
-
-
+
+
{{ mapscript|safe }}
diff --git a/rowers/templates/list_courses.html b/rowers/templates/list_courses.html
index 28b44e50..cff254e8 100644
--- a/rowers/templates/list_courses.html
+++ b/rowers/templates/list_courses.html
@@ -45,7 +45,7 @@
{{ course.distance }} m
-
+
{% endfor %}
@@ -64,6 +64,12 @@
+ {% if location %}
+
+ Filter nearby courses
+ All courses
+
+ {% endif %}
Add Courses
@@ -79,7 +85,7 @@
{% endfor %}
{% endif %}
-
+
@@ -89,27 +95,27 @@
test pieces and measure the time spent on the course (as opposed
to the total duration of a workout). This allows you to row and rank
marked courses.
-
+
To create a course, you use Google Earth
to mark the start and finish lines using polygons. The process is identical
to creating custom courses for the
CrewNerd
- app.
-
+ app.
+
CrewNerd has published a nice video tutorial of the process.
Click here to see the video. The part
we're interested in starts at 2:05.
-
+
In addition to start and finish areas, on rowsandall.com you can add additional
polygons to mark areas that you must pass (in that order). This allows for
courses with turns around buoys, respecting buoy lines, or respecting traffic
- patterns on rivers and lakes.
+ patterns on rivers and lakes.
-
+
Open Google Earth
@@ -126,7 +132,7 @@
You are allowed to have multiple courses in one KML file.
Your CrewNerd "courses.kml" file works out of the box
-
+
The site doesn't test for duplicate courses.
diff --git a/rowers/templates/virtualevents.html b/rowers/templates/virtualevents.html
index 07e34183..9eaddfe2 100644
--- a/rowers/templates/virtualevents.html
+++ b/rowers/templates/virtualevents.html
@@ -67,12 +67,19 @@
-
+
+
Click on the challenge name or on the Details button to see the challenge
details (and manage your participation and results). Click on the
course name to see the course details.
+ {% if location %}
+
+ Challenges in your area
+ All Challenges
+
+ {% endif %}
diff --git a/rowers/views/racesviews.py b/rowers/views/racesviews.py
index f75a84c2..cd668240 100644
--- a/rowers/views/racesviews.py
+++ b/rowers/views/racesviews.py
@@ -7,11 +7,34 @@ from rowers.views.statements import *
from rowsandall_app.settings import SITE_URL
from rowers.scoring import *
+from django.contrib.gis.geoip2 import GeoIP2
+
# List Courses
def courses_view(request):
r = getrower(request.user)
+ g = GeoIP2()
+ ip = request.META.get('REMOTE_ADDR')
+ try:
+ lat_lon = g.lat_lon(ip)
+ city = g.city(ip)
+ except:
+ lat_lon = None
+ city = None
+
+
+ courses = GeoCourse.objects.all().order_by("country","name","distance")
+ nearby = request.GET.get('nearby')
+
+ if nearby and lat_lon is not None:
+ newlist = []
+ for c in courses:
+ coords = c.coord
+ distance = geo_distance(lat_lon[0],lat_lon[1],coords[0],coords[1])[0]
+ if distance < 100:
+ newlist.append(c)
+ courses = newlist
+
- courses = GeoCourse.objects.all().order_by("country","name")
# add search processing
query = request.GET.get('q')
@@ -34,6 +57,7 @@ def courses_view(request):
'active':'nav-racing',
'searchform':searchform,
'rower':r,
+ 'location':lat_lon,
})
# List Courses
@@ -116,7 +140,7 @@ def course_replace_view(request,id=0):
r = getrower(request.user)
- thecourses = GeoCourse.objects.filter(manager=r).exclude(id=id)
+ #thecourses = GeoCourse.objects.filter(manager=r).exclude(id=id)
if request.method == 'POST':
form = CourseSelectForm(request.POST)
@@ -132,8 +156,8 @@ def course_replace_view(request,id=0):
return HttpResponseRedirect(url)
else:
- form = CourseSelectForm()
- form.fields["course"].queryset = thecourses
+ form = CourseSelectForm(course=course,manager=r)
+ #form.fields["course"].queryset = thecourses
script,div = course_map(course)
@@ -646,6 +670,15 @@ def virtualevents_view(request):
if request.is_ajax():
is_ajax = True
+ g = GeoIP2()
+ ip = request.META.get('REMOTE_ADDR')
+ try:
+ lat_lon = g.lat_lon(ip)
+ city = g.city(ip)
+ except:
+ lat_lon = None
+ city = None
+
# default races
races1 = VirtualRace.objects.filter(
startdate__gte=datetime.date.today(),
@@ -656,6 +689,8 @@ def virtualevents_view(request):
)
+
+
races = (races1 | races2).order_by("startdate","start_time")
if len(races) == 0:
@@ -718,10 +753,26 @@ def virtualevents_view(request):
else:
form = VirtualRaceSelectForm()
+ nearby = request.GET.get('nearby')
+ if nearby and lat_lon is not None:
+ newlist = []
+ for race in races:
+ if race.course is None:
+ newlist.append(race)
+ else:
+ c = race.course
+ coords = c.coord
+ distance = geo_distance(lat_lon[0],lat_lon[1],coords[0],coords[1])[0]
+ if distance < 100:
+ newlist.append(race)
+
+ races = newlist
+
if is_ajax:
return render(request,'racelist.html',
{ 'races':races,
'rower':r,
+ 'location': lat_lon,
})
breadcrumbs = [
@@ -737,6 +788,7 @@ def virtualevents_view(request):
'breadcrumbs':breadcrumbs,
'active':'nav-racing',
'rower':r,
+ 'location': lat_lon,
}
)
diff --git a/rowsandall_app/settings.py b/rowsandall_app/settings.py
index aea004aa..ef4239ec 100644
--- a/rowsandall_app/settings.py
+++ b/rowsandall_app/settings.py
@@ -535,3 +535,5 @@ try:
except KeyError:
RECAPTCHA_SITE_KEY = ''
RECAPTCHA_SITE_SECRET = ''
+
+GEOIP_PATH = STATIC_ROOT
diff --git a/static/GeoLite2-City.mmdb b/static/GeoLite2-City.mmdb
new file mode 100644
index 00000000..0a19bf12
Binary files /dev/null and b/static/GeoLite2-City.mmdb differ