# 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
            )
            mb.is_staff = True
            mb.save()


def parse_dv(dump):
    # delivery: name, network, state, description
    # product: name, delivery, price, quantity_per_package, unit, quantity_limit, unit_weight, quantum, description, place
    print(" * deliveries")
    CONVERT_STATE = {k: v for k, v in "AA BB CC DD FE".split()}
    for dv in dump.delivery.values():
        dv_db, _ = m.Delivery.objects.get_or_create(
            name=dv.name,
            network_id=dump.network[dv.network].new_id,
            defaults={"state": CONVERT_STATE[dv.state], "description": dv.description},
        )
        dv.new_id = dv_db.id
    print(" * products")
    PRODUCT_FIELDS = "name price quantity_per_package unit quantity_limit unit_weight quantum description place".split()
    n = len(dump.product)
    p = int(n / 100)
    for i, pd in enumerate(dump.product.values()):
        if i % p == 0:
            sys.stdout.write(f"({i}/{n}) ")
            sys.stdout.flush()
        pd_db, _ = m.Product.objects.get_or_create(
            name=pd.name,
            delivery_id=dump.delivery[pd.delivery].new_id,
            defaults={k: getattr(pd, k) for k in PRODUCT_FIELDS},
        )

# 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_civam.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

            )
            mb.is_staff = True
            mb.save()


def parse_dv(dump):
    # delivery: name, network, state, description
    # product: name, delivery, price, quantity_per_package, unit, quantity_limit, unit_weight, quantum, description, place
    print(" * deliveries")
    CONVERT_STATE = {k: v for k, v in "AA BB CC DD FE".split()}
    for dv in dump.delivery.values():
        dv_db, _ = m.Delivery.objects.get_or_create(
            name=dv.name,
            network_id=dump.network[dv.network].new_id,
            defaults={"state": CONVERT_STATE[dv.state], "description": dv.description},
        )
        dv.new_id = dv_db.id
    print(" * products")
    PRODUCT_FIELDS = "name price quantity_per_package unit quantity_limit unit_weight quantum description place".split()
    n = len(dump.product)
    p = int(n / 100)
    for i, pd in enumerate(dump.product.values()):
        if i % p == 0:
            sys.stdout.write(f"({i}/{n}) ")
            sys.stdout.flush()
        pd_db, _ = m.Product.objects.get_or_create(
            name=pd.name,
            delivery_id=dump.delivery[pd.delivery].new_id,
            defaults={k: getattr(pd, k) for k in PRODUCT_FIELDS},
        )

        pd.new_id = pd_db.id