If no teams or events are near the viewer (by geoip lookup) show them the 3 closest to them instead of redirecting them to create a team
This commit is contained in:
parent
da82627c2e
commit
83e0e709e2
2 changed files with 60 additions and 6 deletions
|
@ -49,13 +49,40 @@
|
|||
{% else %}
|
||||
<div class="col-12 mb-3">
|
||||
<div class="alert alert-info">
|
||||
There are no events near you.
|
||||
There are no events within {{ distance }}km of you.
|
||||
<a class="btn btn-success btn-sm" href="{% url 'create-event-team-select' %}">Create one now</a>
|
||||
or
|
||||
<a class="btn btn-primary btn-sm" href="{% url 'all-events' %}">View all events</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if closest_events %}
|
||||
{% for event in closest_events %}
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-4 box-shadow">
|
||||
<div class="card-banner">
|
||||
<a href="{{event.event_url}}">
|
||||
{% if event.img_url %}
|
||||
<img class="card-img-top" src="{{event.img_url}}" alt="{{event.event_title}}">
|
||||
{% else %}
|
||||
<img class="card-img-top" src="{% static 'img/team_placeholder.png' %}" alt="{{event.event_title}}">
|
||||
{% endif %}
|
||||
</a>
|
||||
<p class="card-title">{{event.group_name}}</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong><a class="card-link" href="{{event.event_url}}">{{event.event_title}}</a></strong></p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<small class="text-muted">{{ event.local_start_time }}<br/>{{event.location_name}}</small>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="{{event.event_url}}">View</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
@ -88,13 +115,36 @@
|
|||
{% else %}
|
||||
<div class="col-12">
|
||||
<div class="alert alert-info">
|
||||
There are no teams near you.
|
||||
There are no teams within {{ distance }}km of you.
|
||||
<a class="btn btn-success btn-sm" href="{% url 'create-team' %}">Create one now</a>
|
||||
or
|
||||
<a class="btn btn-primary btn-sm" href="{% url 'all-teams' %}">View all teams</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if closest_teams %}
|
||||
{% for team in closest_teams %}
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-4 box-shadow">
|
||||
<div class="card-banner">
|
||||
<a href="{% url 'show-team-by-slug' team.slug %}">
|
||||
<img class="card-img-top" src="{{team.card_img_url}}" alt="{{team.name}}">
|
||||
</a>
|
||||
<p class="card-title">{{team.name}}</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong><a class="card-link" href="{% url 'show-team-by-slug' team.slug %}">{{team.city}}</a></strong></p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<small class="text-muted">{{ team.members.count }} members</small>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="{% url 'show-team-by-slug' team.slug %}">View</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
</div>
|
||||
|
|
|
@ -106,13 +106,17 @@ def home(request, *args, **kwards):
|
|||
near_events = Searchable.objects.filter(latitude__gte=minlat, latitude__lte=maxlat, longitude__gte=minlng, longitude__lte=maxlng, end_time__gte=datetime.datetime.now())
|
||||
context['near_events'] = sorted(near_events, key=lambda searchable: location.searchable_distance_from(ll, searchable))
|
||||
|
||||
# # If there aren't any teams in the user's geoip area, show them the closest ones
|
||||
if context['geoip_lookup'] and len(near_events) < 1:
|
||||
context['closest_events'] = sorted(Searchable.objects.filter(end_time__gte=datetime.datetime.now()),
|
||||
key=lambda searchable: location.searchable_distance_from(ll, searchable))[:3]
|
||||
|
||||
near_teams = Team.objects.filter(city__latitude__gte=minlat, city__latitude__lte=maxlat, city__longitude__gte=minlng, city__longitude__lte=maxlng)
|
||||
context['near_teams'] = sorted(near_teams, key=lambda team: location.team_distance_from(ll, team))
|
||||
|
||||
# # If there aren't any teams in the user's geoip area, direct them to start one
|
||||
if context['geoip_lookup'] and len(near_teams) < 1 and len(near_events) < 1:
|
||||
messages.add_message(request, messages.INFO, message=_('There are no teams or events yet in your area, be the first to start one!'))
|
||||
return redirect('create-team')
|
||||
# # If there aren't any teams in the user's geoip area, show them the closest ones
|
||||
if context['geoip_lookup'] and len(near_teams) < 1:
|
||||
context['closest_teams'] = sorted(Team.objects.all(), key=lambda team: location.team_distance_from(ll, team))[:3]
|
||||
except Exception as err:
|
||||
print("Error looking up nearby teams and events", err)
|
||||
traceback.print_exc()
|
||||
|
|
Loading…
Reference in a new issue