Add longitude and latitude to city import, use it for searchable data when a Place isn't defined for an event
This commit is contained in:
parent
d5217c14f3
commit
bb88e55d49
5 changed files with 42 additions and 7 deletions
|
@ -47,7 +47,7 @@ class Command(BaseCommand):
|
|||
country = COUNTRY_CACHE.get(city[COUNTRY_CODE])
|
||||
spr = SPR_CACHE.get("%s.%s"%(city[COUNTRY_CODE], city[ADMIN1]))
|
||||
if country is not None and spr is not None:
|
||||
City.objects.get_or_create(name=city[NAME], spr=spr, tz=city[TIMEZONE])
|
||||
City.objects.update_or_create(name=city[NAME], spr=spr, defaults={'tz':city[TIMEZONE], 'longitude':city[LONGITUDE], 'latitude':city[LATITUDE]})
|
||||
else:
|
||||
print("Short line (%s): %s" % (len(city), city_line))
|
||||
cities_file.close()
|
||||
|
|
28
events/migrations/0007_add-city-lonlat.py
Normal file
28
events/migrations/0007_add-city-lonlat.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 2.0 on 2018-01-24 16:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('events', '0006_auto_20180124_0303'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='latitude',
|
||||
field=models.FloatField(blank=True, help_text='Latitude in Degrees North', null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='city',
|
||||
name='longitude',
|
||||
field=models.FloatField(blank=True, help_text='Longitude in Degrees East', null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='attendee',
|
||||
name='status',
|
||||
field=models.SmallIntegerField(choices=[(-1, 'No'), (0, 'Maybe'), (1, 'Yes')], db_index=True, default=1, verbose_name='Attending?'),
|
||||
),
|
||||
]
|
|
@ -87,12 +87,13 @@ class Event(models.Model):
|
|||
def update_event_searchable(event):
|
||||
site = Site.objects.get(id=1)
|
||||
event_url = "https://%s%s" % (site.domain, event.get_absolute_url())
|
||||
origin_url = "https://%s%s" % (site.domain, reverse('searchables'))
|
||||
try:
|
||||
searchable = Searchable.objects.get(event_url=event_url)
|
||||
except:
|
||||
searchable = Searchable(event_url)
|
||||
searchable.origin_node = "https://127.0.0.1:8000"
|
||||
searchable.federation_node = "https://127.0.0.1:8000"
|
||||
searchable.origin_node = origin_url
|
||||
searchable.federation_node = origin_url
|
||||
searchable.federation_time = datetime.datetime.now()
|
||||
|
||||
searchable.event_title = event.name
|
||||
|
@ -105,11 +106,14 @@ def update_event_searchable(event):
|
|||
searchable.location_name = str(event.place.city)
|
||||
searchable.venue_name = event.place.name
|
||||
searchable.longitude = event.place.longitude or None
|
||||
searchable.latitude = event.place.latitude
|
||||
searchable.latitude = event.place.latitude or None
|
||||
else:
|
||||
searchable.location_name = event.team.location_name
|
||||
searchable.longitude = None
|
||||
searchable.latitude = None
|
||||
|
||||
if event.team.city is not None and (searchable.longitude is None or searchable.latitude is None):
|
||||
searchable.longitude = event.team.city.longitude
|
||||
searchable.latitude = event.team.city.latitude
|
||||
|
||||
searchable.save()
|
||||
|
||||
def slugify(s, ok=SLUG_OK, lower=True, spaces=False):
|
||||
|
|
|
@ -91,6 +91,8 @@ class City(models.Model):
|
|||
name = models.CharField(_("Name"), max_length=100)
|
||||
spr = models.ForeignKey(SPR, on_delete=models.CASCADE)
|
||||
tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False, help_text=_('The most commonly used timezone for this Team.'))
|
||||
longitude = models.FloatField(help_text=_('Longitude in Degrees East'), null=True, blank=True)
|
||||
latitude = models.FloatField(help_text=_('Latitude in Degrees North'), null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return u'%s, %s, %s' % (self.name, self.spr.name, self.spr.country.name)
|
||||
|
|
|
@ -25,7 +25,8 @@ from . import views
|
|||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('searchables/', event_views.searchable_list),
|
||||
|
||||
path('searchables/', event_views.searchable_list, name='searchables'),
|
||||
path('api/places/', event_views.places_list),
|
||||
path('api/countries/', event_views.country_list),
|
||||
path('api/spr/', event_views.spr_list),
|
||||
|
|
Loading…
Reference in a new issue