diff --git a/events/management/commands/load_cities.py b/events/management/commands/load_cities.py index 16cb6df..d7b649e 100644 --- a/events/management/commands/load_cities.py +++ b/events/management/commands/load_cities.py @@ -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() diff --git a/events/migrations/0007_add-city-lonlat.py b/events/migrations/0007_add-city-lonlat.py new file mode 100644 index 0000000..573acae --- /dev/null +++ b/events/migrations/0007_add-city-lonlat.py @@ -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?'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 3316f82..29f1a57 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -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): diff --git a/events/models/locale.py b/events/models/locale.py index f6164ad..561bd37 100644 --- a/events/models/locale.py +++ b/events/models/locale.py @@ -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) diff --git a/get_together/urls.py b/get_together/urls.py index bf86a28..fa4c9e9 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -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),