Skip to content

Commit

Permalink
Merge branch 'jclgoodwin:main' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
iMarkeh authored Jan 23, 2025
2 parents 9611ae2 + c442f7d commit c4153d7
Show file tree
Hide file tree
Showing 32 changed files with 1,504 additions and 1,205 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
rev: v0.9.2
hooks:
- id: ruff
args: [--fix]
Expand All @@ -26,7 +26,7 @@ repos:
args: [--target-version, "5.1"] # Django version

- repo: https://github.com/biomejs/pre-commit
rev: v0.6.0
rev: v0.6.1
hooks:
- id: biome-check
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN apt-get update && \
ENV VIRTUAL_ENV=/opt/poetry
RUN python -m venv $VIRTUAL_ENV
ENV PATH=$VIRTUAL_ENV/bin:$PATH
RUN $VIRTUAL_ENV/bin/pip install poetry==1.8.3
RUN $VIRTUAL_ENV/bin/pip install poetry==2.0.0

WORKDIR /app/

Expand Down
1 change: 0 additions & 1 deletion busstops/management/commands/naptan_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def get_stop(self, element):

if atco_code.startswith(stop.admin_area_id):
stop.admin_area = self.admin_areas.get(stop.admin_area_id)
logger.info(f"{atco_code} {stop.admin_area}")

for xml_path, key in self.mapping:
value = element.findtext(xml_path, "")
Expand Down
18 changes: 18 additions & 0 deletions busstops/migrations/0006_servicecolour_use_name_as_brand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.5 on 2025-01-19 01:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('busstops', '0005_alter_stoppoint_atco_code'),
]

operations = [
migrations.AddField(
model_name='servicecolour',
name='use_name_as_brand',
field=models.BooleanField(default=True),
),
]
1 change: 1 addition & 0 deletions busstops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ class ServiceColour(models.Model):
foreground = models.CharField(max_length=20, blank=True)
background = models.CharField(max_length=20, blank=True)
border = models.CharField(max_length=20, blank=True)
use_name_as_brand = models.BooleanField(default=False)

def __str__(self):
return self.name
Expand Down
26 changes: 1 addition & 25 deletions busstops/templates/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<h1>Privacy policy</h1>

<p class="credit">
Last updated: <a href="https://github.com/jclgoodwin/bustimes.org/blob/main/busstops/templates/cookies.html">21 August 2023</a>
Last updated: <a href="https://github.com/jclgoodwin/bustimes.org/blob/main/busstops/templates/cookies.html">8 January 2025</a>

<p>
bustimes.org (“this website”) is owned and operated by Bus Times Ltd (“I”, “we”).
Expand Down Expand Up @@ -80,28 +80,4 @@ <h2>Cookies</h2>
</tbody>
</table>

<p>We use Google Analytics to measure website usage, which sets these cookies:</p>

<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Default expiration time</th>
<th scope="col">Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td>_ga</td>
<td>2 years</td>
<td>Distinguish users</td>
</tr>
<tr>
<td>_ga_&lt;container-id&gt;</td>
<td>2 years</td>
<td>Persist session state </td>
</tr>
</tbody>
</table>

{% endblock content %}
26 changes: 12 additions & 14 deletions busstops/templates/jinja2/busstops/service_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h1>{{ object }}</h1>
<div id="AFM_inContentTop_ad"></div>
</div>


{% if object.geometry %}
<div id="map"><div class="service-map"><a href="#" class="map-button">Close map</a></div></div>

Expand All @@ -45,6 +46,17 @@ <h1>{{ object }}</h1>
<li><a href="{{ tickets_link }}">Tickets</a></li>
{% endif %}
</ul>

<script>
SERVICE_ID = {{ object.id }};
EXTENT = [{{ object.geometry.extent|join(",") }}];
LIVERIES_CSS_URL = "/liveries.{{ liveries_css_version() }}.css";
</script>
<script async src="{{ static('dist/js/app.js') }}"></script>
{% else %}
<script>
SERVICE_ID = {{ object.id }};
</script>
{% endif %}

<div id="timetable">
Expand Down Expand Up @@ -109,23 +121,9 @@ <h2>More information</h2>
<p>Mobile tickets and live bus tracking available on <a href="{{ app.url }}">the {{ app.name }}</a></p>
{% endif %}

{% if fare_cap %}
<p><a href="{{ fare_cap.url }}">Get around for £2</a> – single fares are capped at £2 on this service</p>
{% endif %}

{% endblock content %}

{% block foot %}
<script>
SERVICE_ID = {{ object.id }};
{% if object.geometry %}
{% if object.tracking %}SERVICE_TRACKING = true;{% endif %}
EXTENT = [{{ object.geometry.extent|join(",") }}];
LIVERIES_CSS_URL = "/liveries.{{ liveries_css_version() }}.css";
</script>
<script async src="{{ static('dist/js/app.js') }}"></script>
{% else %}</script>{% endif %}

<script src="{{ static('js/reqwest.min.js') }}"></script>
<script async src="{{ static('js/timetable.js') }}"></script>
{% if fare_tables %}
Expand Down
3 changes: 1 addition & 2 deletions busstops/templates/jinja2/timetable.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ <h2>{{ linebreaksbr(grouping) }}</h2>
{% endfor %}

{% for credit in timetable.credits() %}{% if loop.first %}
<p class="credit">Timetable data from {% else %}, {% endif %}{{ credit }}{% if loop.last %}{% if 'bus-data.dft.gov.uk' in credit %}.
We’re not endorsed by, affiliated with or supported by them, and they don’t warrant the accuracy or quality of the information.{% endif %}
<p class="credit">Timetable data from {% else %}, {% endif %}{{ credit }}{% if loop.last %}
</p>{% endif %}{% endfor %}

{% endcache %}
Expand Down
1 change: 1 addition & 0 deletions busstops/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<script>if(typeof Array.prototype.includes!=="undefined"){s=document.getElementsByTagName('script')[0];var sc=document.createElement('script');sc.type='text/javascript';sc.async=true;sc.src='https://cdn.adfirst.media/hb/bustimes.js?v'+Math.floor(new Date().getTime()/600000);s.parentNode.insertBefore(sc,s);}</script>
{% endif %}
{% endblock fuse %}
<script src="https://analytics.ahrefs.com/analytics.js" data-key="JnhFOzy1izIU9JV+msWPhA" async></script>

</head>
<body class="{% block bodyclass %}wide{% endblock %}{% if ad is False %} no-ads{% endif %}">
Expand Down
7 changes: 2 additions & 5 deletions busstops/templatetags/urlise.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ def urlise(value, autoescape=None):
)
markup = markup.replace("/</a>", "</a>", 1)
if "megabus" in markup:
megabus = '"https://www.awin1.com/awclick.php?mid=2678&amp;id=242611&amp;clickref=urlise&amp;p=https%3A%2F%2Fuk.megabus.com"'
markup = markup.replace('"http://megabus.com"', megabus, 1)
markup = markup.replace('"https://uk.megabus.com"', megabus, 1)
megabus = '"https://www.awin1.com/awclick.php?mid=2678&amp;id=242611&amp;clickref=urlise"'
markup = markup.replace('"https://www.megabus.co.uk"', megabus, 1)
elif "nationalexpress" in markup:
replacement = '"https://nationalexpress.prf.hn/click/camref:1011ljPYw"'
markup = markup.replace('"http://nationalexpress.com"', replacement, 1)
markup = markup.replace('"http://www.nationalexpress.com"', replacement, 1)
markup = markup.replace('"https://www.nationalexpress.com"', replacement, 1)
return mark_safe(markup)
6 changes: 1 addition & 5 deletions busstops/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,12 @@ def setUpTestData(cls):
noc="VENT", name="Nu-Venture", vehicle_mode="bus", region_id="N"
)

fare_cap = PaymentMethod.objects.create(
name="£2 fare cap", url="http://example.com"
)
oyster = PaymentMethod.objects.create(
name="oyster card", url="http://example.com"
)
euros = PaymentMethod.objects.create(name="euros")

cls.chariots.payment_methods.set([fare_cap, oyster, euros])
cls.chariots.payment_methods.set([oyster, euros])
cls.service.operator.add(cls.chariots)
cls.inactive_service.operator.add(cls.chariots)

Expand Down Expand Up @@ -405,7 +402,6 @@ def test_service(self):
# payment methods:
self.assertContains(response, "euros")
self.assertContains(response, "Oyster card")
self.assertContains(response, ">Get around for £2<")
self.assertContains(response, '"http://example.com"')

def test_national_express_service(self):
Expand Down
11 changes: 6 additions & 5 deletions busstops/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def get_context_data(self, **kwargs):
)
elif self.object.name == "Megabus":
context["tickets_link"] = (
"https://www.awin1.com/cread.php?awinmid=2678&awinaffid=242611&ued=https%3A%2F%2Fuk.megabus.com"
"https://www.awin1.com/cread.php?awinmid=2678&awinaffid=242611"
)
elif self.object.name == "National Express":
context["tickets_link"] = (
Expand Down Expand Up @@ -1179,8 +1179,6 @@ def get_context_data(self, **kwargs):
):
if "app" in method.name and method.url:
context["app"] = method
elif "fare cap" in method.name and method.url:
context["fare_cap"] = method
else:
context["payment_methods"].append(method)
for operator in operators:
Expand All @@ -1194,9 +1192,12 @@ def get_context_data(self, **kwargs):
"text": "Buy tickets at National Express",
}
)
elif operator.name == "Megabus":
elif (
operator.name == "Megabus"
or self.object.service_code == "PH1020951:281"
): # Falcon
context["tickets_link"] = (
"https://www.awin1.com/cread.php?awinmid=2678&awinaffid=242611&ued=https%3A%2F%2Fuk.megabus.com"
"https://www.awin1.com/cread.php?awinmid=2678&awinaffid=242611"
)
context["links"].append(
{
Expand Down
2 changes: 1 addition & 1 deletion bustimes/management/commands/import_atco_cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def handle_archive(self, archive_name):

with zipfile.ZipFile(archive_name) as archive:
for filename in archive.namelist():
if filename.endswith(".cif") and "/archive/" not in filename.lower():
if filename.endswith(".cif") and "/archive/" not in filename.lower() and "/Y20/" not in filename.upper():
with archive.open(filename) as open_file:
self.handle_file(open_file)
assert self.stop_times == []
Expand Down
1 change: 1 addition & 0 deletions bustimes/management/commands/import_transxchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ def handle_service(self, filename: str, transxchange, txc_service, today, stops)
if (
not line_brand
and service.colour
and service.colour.use_name_as_brand
and service.colour.name
and service.colour.name != service.line_name
):
Expand Down
2 changes: 1 addition & 1 deletion bustimes/management/tests/test_import_bod.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_import_bod(self):
response,
"""Timetable data from \
<a href="https://data.bus-data.dft.gov.uk/category/dataset/35/" rel="nofollow">\
Lynx/Bus Open Data Service (BODS)</a>, <time datetime="2020-04-01">1 April 2020</time>.""",
Lynx/Bus Open Data Service (BODS)</a>, <time datetime="2020-04-01">1 April 2020</time>""",
)

# test views:
Expand Down
31 changes: 16 additions & 15 deletions bustimes/management/tests/test_import_transxchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,12 @@ def test_multiple_operators(self):
file has two Operators (SBLB and and BAIN) but only one operates any journeys
"""

with self.assertLogs(
"bustimes.management.commands.import_transxchange", "WARNING"
) as cm, patch("os.path.getmtime", return_value=1582385679):
with (
self.assertLogs(
"bustimes.management.commands.import_transxchange", "WARNING"
) as cm,
patch("os.path.getmtime", return_value=1582385679),
):
self.write_files_to_zipfile_and_import("EA.zip", ["SVRABAO421.xml"])
service = Service.objects.get()
self.assertTrue(service.current)
Expand Down Expand Up @@ -890,9 +893,12 @@ def test_difficult_layout(self):

@time_machine.travel("2021-06-28")
def test_different_notes_in_same_row(self):
with self.assertLogs(
"bustimes.management.commands.import_transxchange", "WARNING"
) as cm, patch("os.path.getmtime", return_value=0):
with (
self.assertLogs(
"bustimes.management.commands.import_transxchange", "WARNING"
) as cm,
patch("os.path.getmtime", return_value=0),
):
call_command("import_transxchange", FIXTURES_DIR / "twm_3-74-_-y11-1.xml")

self.assertEqual(
Expand Down Expand Up @@ -1042,7 +1048,10 @@ def test_services_nw(self):
@time_machine.travel("25 June 2016")
def test_do_service_scotland(self):
colour = ServiceColour.objects.create(
name="Navy Blue Line", foreground="#111111", background="#c0c0c0"
name="Navy Blue Line",
foreground="#111111",
background="#c0c0c0",
use_name_as_brand=True,
)
source = DataSource.objects.create(
name="S", url="ftp://ftp.tnds.basemap.co.uk/S.zip"
Expand Down Expand Up @@ -1201,14 +1210,6 @@ def test_megabus(self):
self.assertContains(
res, '<option selected value="2017-01-22">Sunday 22 January 2017</option>'
)
self.assertContains(
res,
"""<p>Book at <a
href="https://www.awin1.com/awclick.php?mid=2678&amp;id=242611&amp;clickref=urlise&amp;p=https%3A%2F%2Fuk.megabus.com"
rel="nofollow">
megabus.com</a> or 0900 1600900 (65p/min + network charges)</p>""",
html=True,
)
self.assertContains(res, "/js/timetable.")

timetable = res.context_data["timetable"]
Expand Down
9 changes: 5 additions & 4 deletions fixtures/operators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ SBDR:
PCLT:
name: Rural Link
MEGA:
url: https://uk.megabus.com
url: https://www.megabus.co.uk
NSLA:
url: http://www.gatwickairport.com/to-and-from/by-coach-or-bus/hotel-buses/
DOCC:
Expand Down Expand Up @@ -288,10 +288,9 @@ TYSW:
twitter: ""
YYTG:
name: Yorkshire Buses
# url: https://www.yorkshirebuses.co.uk/
url: https://www.yorkshirebuses.co.uk
phone: 0113 246 4914
email: [email protected]
twitter: YorkshireBuses_
email: [email protected]
WNGS:
url: https://www.diamondbuses.com/
MINS:
Expand Down Expand Up @@ -356,3 +355,5 @@ SUNB:
twitter: ""
ELNV:
url: https://ellenvale.co.uk/
SBLB:
name: Stagecoach North Scotland
1 change: 1 addition & 0 deletions frontend/js/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (process.env.NODE_ENV === "production") {
Sentry.init({
dsn: "https://[email protected]/1379883",
allowUrls: [/bustimes\.org\/static\//],
denyUrls: [/bustimes\.org\/static\/js\/consent.js/],
ignoreErrors: [
// ignore errors in third-party advert code
"Load failed",
Expand Down
Loading

0 comments on commit c4153d7

Please sign in to comment.