diff --git a/transit/migrations/0002_rename_threshold_eta_usersettings_start.py b/transit/migrations/0002_rename_threshold_eta_usersettings_start.py new file mode 100644 index 0000000..dd090f8 --- /dev/null +++ b/transit/migrations/0002_rename_threshold_eta_usersettings_start.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.3 on 2022-03-27 07:53 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('transit', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='usersettings', + old_name='threshold_eta', + new_name='start', + ), + ] diff --git a/transit/migrations/0007_merge_20220327_1558.py b/transit/migrations/0007_merge_20220327_1558.py new file mode 100644 index 0000000..9d3bdcf --- /dev/null +++ b/transit/migrations/0007_merge_20220327_1558.py @@ -0,0 +1,14 @@ +# Generated by Django 3.2.12 on 2022-03-27 15:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('transit', '0002_rename_threshold_eta_usersettings_start'), + ('transit', '0006_usersettings_fav_stop'), + ] + + operations = [ + ] diff --git a/transit/models.py b/transit/models.py index 0e65ddb..a59586b 100644 --- a/transit/models.py +++ b/transit/models.py @@ -18,6 +18,17 @@ class Stop(models.Model): lat = models.DecimalField(max_digits=17,decimal_places=15) code = models.IntegerField() routes = models.ManyToManyField(Route) + route_str = models.TextField(default="No routes to display") + + def __str__(self): + return str(self.code) + + def format_routes(self): + str = "Routes: " + for route in self.routes.all(): + str += route.long_name.lower().title() + ", " + + return str[:len(str)-2] def __str__(self): return str(self.code) diff --git a/transit/templates/transit/dashboard.html b/transit/templates/transit/dashboard.html index e3528e5..3330b61 100644 --- a/transit/templates/transit/dashboard.html +++ b/transit/templates/transit/dashboard.html @@ -4,7 +4,19 @@ {% block content %}
- + {% for stop in stops %} +
+
+
{{ stop.name }}
+
+

{{ stop.route_str }}

+ + Track + +
+
+
+ {% endfor %}
{% endblock %} \ No newline at end of file diff --git a/transit/urls.py b/transit/urls.py index b553404..e4134e7 100644 --- a/transit/urls.py +++ b/transit/urls.py @@ -6,7 +6,7 @@ from . import views urlpatterns = [ - path('', TemplateView.as_view(template_name="transit/dashboard.html")), + path('', views.dashboard_view, name = "dashboard_view"), path('settings/', views.settings_view, name = "settings_view"), path('settings/retry/', views.change_settings, name = "change_settings"), path('accounts/', include('allauth.urls')), diff --git a/transit/views.py b/transit/views.py index 16e81dd..6206849 100644 --- a/transit/views.py +++ b/transit/views.py @@ -42,6 +42,15 @@ def get_eta(pos1, pos2): eta_str2 = re.compile('\d+ min').search(eta_str)[0] return int(eta_str2[:-4]) # number of minutes +def dashboard_view(request): + stops = Stop.objects.all().order_by('name') + + for stop in stops: + stop.route_str = stop.format_routes() + stop.save() + + return render(request, "transit/dashboard.html", {'stops': stops}) + def settings_view(request): form = UserSettingsForm() return render(request, "transit/settings.html", {'form': form}) @@ -117,7 +126,6 @@ def create_stops(): except IndexError: continue - def create_or_update_vehicles(): devhub_url = 'https://api.devhub.virginia.edu/v1/transit/vehicles' devhub_data = {'success': False}