# Path: floreal/models.py
# class IdentifiedBySlug(models.Model):
#     class Meta:
# class Mapped(models.Model):
#     class Meta:
# class FlorealUser(IdentifiedBySlug, Mapped):
# class NetworkSubgroup(IdentifiedBySlug):
#     class Meta:
# class NetworkMembership(models.Model):
#     class Meta:
# class Network(IdentifiedBySlug, Mapped):
#     class Meta:
# class Delivery(IdentifiedBySlug):
#     class Meta:
# class Product(models.Model):
#     class Meta:
# class Purchase(models.Model):
#     class Meta:
# class Bestof(models.Model):
#     class Meta:
# class JournalEntry(models.Model):
# class AdminMessage(models.Model):
#     def slug_prefix(self):
#     def save(self, **kwargs):
#     def __str__(self):
#     def slug_prefix(self):
#     def display_name(self):
#     def display_number(self):
#     def uri(self):
#     def has_some_admin_rights(self):
#     def __str__(self) -> str:
#     def __str__(self):
#     def __str__(self):
#     def description_text(self):
#     def grouped(self):
#     def save(self, **kwargs):
#     def __str__(self):
#     def state_name(self):
#     def description_text(self):
#     def freeze_overdue_deliveries(cls):
#     def __str__(self):
#     def _normalize_unit(cls, u):
#     def save(
#         self, force_insert=False, force_update=False, using=None, update_fields=None
#     ):
#     def left(self):
#     def description_text(self):
#     def price(self):
#     def weight(self):
#     def packages(self):
#     def out_of_package(self):
#     def max_quantity(self):
#     def __str__(self, specify_user=False):
#     def __str__(self):
#     def update(cls):
#     def log(cls, u, fmt, *args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     (PREPARATION, ORDERING_ALL, ORDERING_ADMIN, FROZEN, TERMINATED) = "ABCDE"
#     STATE_CHOICES = {
#         PREPARATION: "En préparation",
#         ORDERING_ALL: "Ouverte",
#         ORDERING_ADMIN: "Admins",
#         FROZEN: "Gelée",
#         TERMINATED: "Terminée",
#     }
#     UNIT_AUTO_TRANSLATE = {
#         "1": "pièce",
#         "piece": "pièce",
#         "kilo": "kg",
#         "gr": "g",
#         "unité": "pièce",
#         "unite": "pièce",
#     }
#     UNIT_TRANSLATE_REGEXP = re.compile(r"""
#         ^
#         ([0-9]+) 
#         (?:  [,.]  ([0-9]+)  )?
#         \s*
#         ([A-Za-z]+)
#         $""", re.VERBOSE)


from django.core.management.base import BaseCommand
from types import SimpleNamespace
from floreal import models as m
from markdown import markdown
from django.db import IntegrityError, DataError
import json
import sys
        subkey = x.pk
        dump.__dict__.setdefault(key, {})[subkey] = val
    return dump


# In [12]: for k, v in dump.__dict__.items():
#     ...:     first_val = list(v.values())[0]
#     ...:     subkeys = list(first_val.__dict__.keys())
#     ...:     print(f"{k}: {', '.join(subkeys)}")


def parse_structure(dump):
    # network: name, auto_validate, description, staff
    # subgroup: name, network, extra_user, auto_validate, staff, users
    # user: password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined, groups, user_permissions

    print(" * filtering and creating users")
    USER_FIELDS = "password is_superuser username first_name last_name email is_staff date_joined".split()
    purchaser_user_ids = {pc.user for pc in dump.purchase.values()}
    staff_user_ids = (
        {u for sg in dump.subgroup.values() for u in sg.staff}
        | {u for nw in dump.network.values() for u in nw.staff}
        | {k for k, v in dump.user.items() if v.is_staff}
    )
    kept_user_ids = purchaser_user_ids | staff_user_ids
    deleted_user_ids = set()
    for uid, u in dump.user.items():
        if not u.is_active or uid not in kept_user_ids:
            deleted_user_ids.add(uid)  # Don't bother with people who never bought or left
        else:

# Path: floreal/models.py
# class IdentifiedBySlug(models.Model):
#     class Meta:
# class Mapped(models.Model):
#     class Meta:
# class FlorealUser(IdentifiedBySlug, Mapped):
# class NetworkSubgroup(IdentifiedBySlug):
#     class Meta:
# class NetworkMembership(models.Model):
#     class Meta:
# class Network(IdentifiedBySlug, Mapped):
#     class Meta:
# class Delivery(IdentifiedBySlug):
#     class Meta:
# class Product(models.Model):
#     class Meta:
# class Purchase(models.Model):
#     class Meta:
# class Bestof(models.Model):
#     class Meta:
# class JournalEntry(models.Model):
# class AdminMessage(models.Model):
#     def slug_prefix(self):
#     def save(self, **kwargs):
#     def __str__(self):
#     def slug_prefix(self):
#     def display_name(self):
#     def display_number(self):
#     def uri(self):
#     def has_some_admin_rights(self):
#     def __str__(self) -> str:
#     def __str__(self):
#     def __str__(self):
#     def description_text(self):
#     def grouped(self):
#     def save(self, **kwargs):
#     def __str__(self):
#     def state_name(self):
#     def description_text(self):
#     def freeze_overdue_deliveries(cls):
#     def __str__(self):
#     def _normalize_unit(cls, u):
#     def save(
#         self, force_insert=False, force_update=False, using=None, update_fields=None
#     ):
#     def left(self):
#     def description_text(self):
#     def price(self):
#     def weight(self):
#     def packages(self):
#     def out_of_package(self):
#     def max_quantity(self):
#     def __str__(self, specify_user=False):
#     def __str__(self):
#     def update(cls):
#     def log(cls, u, fmt, *args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     (PREPARATION, ORDERING_ALL, ORDERING_ADMIN, FROZEN, TERMINATED) = "ABCDE"
#     STATE_CHOICES = {
#         PREPARATION: "En préparation",
#         ORDERING_ALL: "Ouverte",
#         ORDERING_ADMIN: "Admins",
#         FROZEN: "Gelée",
#         TERMINATED: "Terminée",
#     }
#     UNIT_AUTO_TRANSLATE = {
#         "1": "pièce",
#         "piece": "pièce",
#         "kilo": "kg",
#         "gr": "g",
#         "unité": "pièce",
#         "unite": "pièce",
#     }
#     UNIT_TRANSLATE_REGEXP = re.compile(r"""
#         ^
#         ([0-9]+) 
#         (?:  [,.]  ([0-9]+)  )?
#         \s*
#         ([A-Za-z]+)
#         $""", re.VERBOSE)


# Path: floreal/management/commands/from_caracole.py
from django.core.management.base import BaseCommand
from types import SimpleNamespace
from floreal import models as m
from markdown import markdown
from django.db import IntegrityError, DataError
import json
import sys

        subkey = x.pk
        dump.__dict__.setdefault(key, {})[subkey] = val
    return dump


# In [12]: for k, v in dump.__dict__.items():
#     ...:     first_val = list(v.values())[0]
#     ...:     subkeys = list(first_val.__dict__.keys())
#     ...:     print(f"{k}: {', '.join(subkeys)}")


def parse_structure(dump):
    # network: name, auto_validate, description, staff
    # subgroup: name, network, extra_user, auto_validate, staff, users
    # user: password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined, groups, user_permissions

    print(" * filtering and creating users")
    USER_FIELDS = "password is_superuser username first_name last_name email is_staff date_joined".split()
    purchaser_user_ids = {pc.user for pc in dump.purchase.values()}
    staff_user_ids = (
        {u for sg in dump.subgroup.values() for u in sg.staff}
        | {u for nw in dump.network.values() for u in nw.staff}
        | {k for k, v in dump.user.items() if v.is_staff}
    )
    kept_user_ids = purchaser_user_ids | staff_user_ids
    deleted_user_ids = set()
    for uid, u in dump.user.items():
        if not u.is_active or uid not in kept_user_ids:
            deleted_user_ids.add(uid)  # Don't bother with people who never bought or left
        else:

            u_db, _ = m.User.objects.get_or_create(