Compare commits
2 Commits
c60a105b2d
...
b8fd85e0f6
Author | SHA1 | Date | |
---|---|---|---|
b8fd85e0f6 | |||
0d622302ac |
@ -1,4 +1,5 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db.models.signals import pre_save
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
@ -6,3 +7,8 @@ class TrainvelGTFSConfig(AppConfig):
|
|||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "trainvel.gtfs"
|
name = "trainvel.gtfs"
|
||||||
verbose_name = _("Trainvel - GTFS")
|
verbose_name = _("Trainvel - GTFS")
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from trainvel.gtfs import signals
|
||||||
|
|
||||||
|
pre_save.connect(signals.keep_gtfs_feed_modification_date, sender="gtfs.GTFSFeed")
|
||||||
|
@ -368,6 +368,7 @@ class Command(BaseCommand):
|
|||||||
stop_times.clear()
|
stop_times.clear()
|
||||||
|
|
||||||
if os.path.exists(os.path.join(zip_dir, "transfers.txt")):
|
if os.path.exists(os.path.join(zip_dir, "transfers.txt")):
|
||||||
|
Transfer.objects.filter(Q(from_stop__gtfs_feed_id=gtfs_code) | Q(to_stop__gtfs_feed_id=gtfs_code)).delete()
|
||||||
transfers = []
|
transfers = []
|
||||||
for transfer_dict in read_csv("transfers.txt"):
|
for transfer_dict in read_csv("transfers.txt"):
|
||||||
transfer_dict: dict
|
transfer_dict: dict
|
||||||
|
14
trainvel/gtfs/signals.py
Normal file
14
trainvel/gtfs/signals.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from trainvel.gtfs.models import GTFSFeed
|
||||||
|
|
||||||
|
|
||||||
|
def keep_gtfs_feed_modification_date(instance: GTFSFeed, raw: bool = True, **_kwargs):
|
||||||
|
"""
|
||||||
|
Keep the last_modified and etag fields from the existing GTFSFeed instance when saving a new one.
|
||||||
|
"""
|
||||||
|
if raw and GTFSFeed.objects.filter(pk=instance.pk).exists():
|
||||||
|
# If a GTFSFeed instance is being saved from a raw query,
|
||||||
|
# we want to keep the last_modified and etag fields from the existing instance.
|
||||||
|
# This is useful when loading initial data from a fixture, for example.
|
||||||
|
old_instance = GTFSFeed.objects.get(pk=instance.pk)
|
||||||
|
instance.last_modified = old_instance.last_modified
|
||||||
|
instance.etag = old_instance.etag
|
Loading…
x
Reference in New Issue
Block a user