Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions transit/migrations/0002_rename_threshold_eta_usersettings_start.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
14 changes: 14 additions & 0 deletions transit/migrations/0007_merge_20220327_1558.py
Original file line number Diff line number Diff line change
@@ -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 = [
]
11 changes: 11 additions & 0 deletions transit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion transit/templates/transit/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
{% block content %}
<div class = "content">
<div class = "container-fluid mt-2" style = "min-height: 80vh;">

{% for stop in stops %}
<div class = "row py-2">
<div class="card mx-auto w-75">
<h5 class="card-header">{{ stop.name }} </h5>
<div class="card-body d-flex">
<p class="card-text w-75">{{ stop.route_str }}</p>
<span class="w-25 text-right">
<a href="#" class="btn btn-primary my-0 my-auto">Track</a>
</span>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion transit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
10 changes: 9 additions & 1 deletion transit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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}
Expand Down