Skip to content

seeder

django_spire.metric.visual.seeding.seeder

VISUAL_VALUE_POINTS = 30 module-attribute

VisualSeeder

Bases: Seeder

Source code in django_spire/contrib/seeding/seeder.py
def __init__(self, count: int = 1, verbose: bool = True) -> None:
    self.seeds: list[Seed] = []
    self._model_object_ids: list[int | str] = []
    self._count: int = count
    self.verbose: bool = verbose

cache_enabled = False class-attribute instance-attribute

model_class = models.Visual class-attribute instance-attribute

fields_seeds = {'id': Seeder.exclude(), 'name': Seeder.ordered.choice([seed['name'] for seed in VISUAL_SEEDS], wrap=True), 'description': Seeder.ordered.choice([seed['description'] for seed in VISUAL_SEEDS], wrap=True), 'kind': Seeder.ordered.choice([seed['kind'] for seed in VISUAL_SEEDS], wrap=True), 'is_active': Seeder.static(True), 'is_deleted': Seeder.static(False)} class-attribute instance-attribute

__post_seed_database__

Source code in django_spire/metric/visual/seeding/seeder.py
def __post_seed_database__(self) -> None:
    visuals_by_name = {visual.name: visual for visual in self.queryset}
    statistic_updates = []

    for index, seed in enumerate(VISUAL_SEEDS):
        visual = visuals_by_name.get(seed['name'])
        if visual is None:
            continue

        statistic = self._statistic_for(seed)
        if statistic is None:
            continue

        if visual.statistic_id != statistic.pk:
            visual.statistic = statistic
            statistic_updates.append(visual)

        self._seed_visual_conditions(visual, statistic)
        self._seed_visual_references(visual, index, seed)
        self._seed_visual_values(visual, statistic)

    models.Visual.objects.bulk_update(statistic_updates, ['statistic'])

VisualRegionSeeder

Bases: Seeder

Source code in django_spire/contrib/seeding/seeder.py
def __init__(self, count: int = 1, verbose: bool = True) -> None:
    self.seeds: list[Seed] = []
    self._model_object_ids: list[int | str] = []
    self._count: int = count
    self.verbose: bool = verbose

cache_enabled = False class-attribute instance-attribute

model_class = models.VisualRegion class-attribute instance-attribute

fields_seeds = {'id': Seeder.exclude(), 'key': Seeder.ordered.choice([seed['key'] for seed in VISUAL_REGION_SEEDS], wrap=True), 'title': Seeder.ordered.choice([seed['title'] for seed in VISUAL_REGION_SEEDS], wrap=True), 'is_live_updated': Seeder.ordered.choice([seed['is_live_updated'] for seed in VISUAL_REGION_SEEDS], wrap=True), 'is_active': Seeder.static(True), 'is_deleted': Seeder.static(False)} class-attribute instance-attribute

__post_seed_database__

Source code in django_spire/metric/visual/seeding/seeder.py
def __post_seed_database__(self) -> None:
    visuals_by_name = {visual.name: visual for visual in models.Visual.objects.active()}
    seeds_by_key = {seed['key']: seed for seed in VISUAL_REGION_SEEDS}
    updates = []

    for region in self.queryset:
        seed = seeds_by_key.get(region.key)
        if seed is None:
            continue

        visual = visuals_by_name.get(seed['visual_name'])
        if visual is None or visual.pk == region.visual_id:
            continue

        region.visual = visual
        updates.append(region)

    models.VisualRegion.objects.bulk_update(updates, ['visual'])