mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 06:44:21 +00:00
✨ Add sync_flows to the admin page
This commit is contained in:
parent
c13733960e
commit
e8d26eccf7
5 changed files with 75 additions and 9 deletions
|
@ -19,6 +19,17 @@ class ProjectAdmin(CoreAdmin):
|
|||
"name",
|
||||
)
|
||||
|
||||
ordering = (
|
||||
"slug",
|
||||
)
|
||||
|
||||
|
||||
@admin.action(description="Syncronize DataFlows (slow, be patient!)")
|
||||
def sync_flows_admin(modeladmin, request, queryset):
|
||||
for datasource in queryset:
|
||||
datasource: models.DataSource
|
||||
datasource.sync_flows()
|
||||
|
||||
|
||||
@admin.register(models.DataSource)
|
||||
class DataSourceAdmin(CoreAdmin):
|
||||
|
@ -33,6 +44,14 @@ class DataSourceAdmin(CoreAdmin):
|
|||
"last_sync",
|
||||
)
|
||||
|
||||
ordering = (
|
||||
"last_sync",
|
||||
)
|
||||
|
||||
actions = (
|
||||
sync_flows_admin,
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
(
|
||||
None, {
|
||||
|
@ -94,5 +113,11 @@ class DataFlowAdmin(CoreAdmin):
|
|||
|
||||
list_display = (
|
||||
"datasource",
|
||||
"id",
|
||||
"sdmx_id",
|
||||
"description",
|
||||
)
|
||||
|
||||
ordering = (
|
||||
"datasource",
|
||||
"sdmx_id",
|
||||
)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2 on 2021-04-18 17:51
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0002_auto_20210415_1453'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='dataflow',
|
||||
old_name='id',
|
||||
new_name='sdmx_id',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2 on 2021-04-18 17:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0003_rename_id_dataflow_sdmx_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='dataflow',
|
||||
name='surrogate_id',
|
||||
field=models.BigAutoField(help_text='Internal id used by Django to identify this DataFlow.', primary_key=True, serialize=False, verbose_name='Surrogate id'),
|
||||
),
|
||||
]
|
|
@ -9,6 +9,7 @@ import json
|
|||
import abc
|
||||
import datetime
|
||||
import logging
|
||||
import pytz
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -278,18 +279,22 @@ class DataSource(models.Model):
|
|||
log.info(f"Syncing DataFlows of {self!r}...")
|
||||
for description, sdmx_id in zip(flows, flows.index):
|
||||
|
||||
db_flow = DataFlow.objects.update_or_create(
|
||||
db_flow, _created = DataFlow.objects.update_or_create(
|
||||
**{
|
||||
"datasource": self,
|
||||
"id": sdmx_id,
|
||||
"sdmx_id": sdmx_id,
|
||||
},
|
||||
defaults={
|
||||
"last_update": datetime.datetime.now(),
|
||||
"description": description,
|
||||
}
|
||||
)
|
||||
db_flow.save()
|
||||
log.info(f"Synced {db_flow}!")
|
||||
log.debug(f"Synced {db_flow}!")
|
||||
|
||||
log.debug(f"Updating last_sync value of {self!r}")
|
||||
self.last_sync = datetime.datetime.now()
|
||||
self.save()
|
||||
log.info(f"Finished syncing DataFlows of {self!r}")
|
||||
|
||||
def __str__(self):
|
||||
return self.id
|
||||
|
@ -302,7 +307,7 @@ class DataFlow(models.Model):
|
|||
See `this page <https://ec.europa.eu/eurostat/online-help/redisstat-admin/en/TECH_A_main/>`_ for more details.
|
||||
"""
|
||||
|
||||
surrogate_id = models.IntegerField(
|
||||
surrogate_id = models.BigAutoField(
|
||||
"Surrogate id",
|
||||
help_text="Internal id used by Django to identify this DataFlow.",
|
||||
primary_key=True,
|
||||
|
@ -314,7 +319,7 @@ class DataFlow(models.Model):
|
|||
on_delete=models.RESTRICT,
|
||||
)
|
||||
|
||||
id = models.CharField(
|
||||
sdmx_id = models.CharField(
|
||||
"SDMX id",
|
||||
help_text="Internal string used in SDMX communication to identify the DataFlow.",
|
||||
max_length=64,
|
||||
|
@ -327,7 +332,7 @@ class DataFlow(models.Model):
|
|||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"[{self.datasource}] {self.id}"
|
||||
return f"[{self.datasource}] {self.sdmx_id}"
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
|
|
|
@ -46,7 +46,7 @@ class DataFlowSerializer(serializers.ModelSerializer):
|
|||
fields = [
|
||||
"surrogate_id",
|
||||
"datasource",
|
||||
"id",
|
||||
"sdmx_id",
|
||||
"description",
|
||||
]
|
||||
read_only_fields = [
|
||||
|
|
Loading…
Reference in a new issue