# 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/views/getters.py
# def model_getter(cls):
#     def f(x):
# def must_be_prod_or_staff(request, network=None):
# def must_be_staff(request, network: Union[m.Network, int, str, None] = None) -> None:


from floreal import models as m
from collections import defaultdict
from django.template.loader import get_template
from django.http import HttpResponse
from django.core.mail import send_mail, send_mass_mail
from django.conf import settings
from django.shortcuts import redirect, render
from .getters import get_network
from django.template.context_processors import csrf
from django.template.base import Template
from django.template.context import Context
# -*- coding: utf-8 -*-



def render_text(template_name, ctx):
    t = get_template(template_name)
    text_unicode = t.render(ctx)
    return text_unicode


def non_html_response(name_bits, name_extension, content):
    """Common helper to serve PDF and Excel content."""
    mime_type = "text/plain; charset=utf-8"
    response = HttpResponse(content_type=mime_type)
    response.write(content)
    return response


def invoice_mail_form(request, network):
    nw = get_network(network)
    
    if request.method == "POST":
        P = request.POST
        recipients = {u.strip() for u in P["recipients"].split(",")}
        return send_invoice_mail(
            request, network, recipients, P["subject"], P["body"]
        )
    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/views/getters.py
# def model_getter(cls):
#     def f(x):
# def must_be_prod_or_staff(request, network=None):
# def must_be_staff(request, network: Union[m.Network, int, str, None] = None) -> None:


# Path: floreal/views/invoice_mail.py
from floreal import models as m
from collections import defaultdict
from django.template.loader import get_template
from django.http import HttpResponse
from django.core.mail import send_mail, send_mass_mail
from django.conf import settings
from django.shortcuts import redirect, render
from .getters import get_network
from django.template.context_processors import csrf
from django.template.base import Template
from django.template.context import Context

# -*- coding: utf-8 -*-



def render_text(template_name, ctx):
    t = get_template(template_name)
    text_unicode = t.render(ctx)
    return text_unicode


def non_html_response(name_bits, name_extension, content):
    """Common helper to serve PDF and Excel content."""
    mime_type = "text/plain; charset=utf-8"
    response = HttpResponse(content_type=mime_type)
    response.write(content)
    return response


def invoice_mail_form(request, network):
    nw = get_network(network)
    
    if request.method == "POST":
        P = request.POST
        recipients = {u.strip() for u in P["recipients"].split(",")}
        return send_invoice_mail(
            request, network, recipients, P["subject"], P["body"]
        )
    else:        

        deliveries = m.Delivery.objects.filter(network_id=network, state=m.Delivery.FROZEN)