# Path: bread/utils.py
# def get_verbose_name(an_object, field_name, title_cap=True):
#     """Given a model or model instance, return the verbose_name of the model's field.
# 
#     If title_cap is True (the default), the verbose_name will be returned with the first letter
#     of each word capitalized which makes the verbose_name look nicer in labels.
# 
#     If field_name doesn't refer to a model field, raises a FieldDoesNotExist error.
#     """
#     # get_field() can raise FieldDoesNotExist which I simply propogate up to the caller.
#     try:
#         field = an_object._meta.get_field(field_name)
#     except TypeError:
#         # TypeError happens if the caller is very confused and passes an unhashable type such
#         # as {} or []. I convert that into a FieldDoesNotExist exception for simplicity.
#         raise FieldDoesNotExist("No field named {}".format(str(field_name)))
# 
#     verbose_name = field.verbose_name
# 
#     if title_cap:
#         # Title cap the label using this stackoverflow-approved technique:
#         # http://stackoverflow.com/questions/1549641/how-to-capitalize-the-first-letter-of-each-word-in-a-string-python
#         verbose_name = " ".join(word.capitalize() for word in verbose_name.split())
# 
#     return verbose_name
# 
# def validate_fieldspec(model, spec):
#     """
#     Given a model class and a string that refers to a possibly nested
#     field on that model (as used in `get_model_field`).
# 
#     Raises a ValidationError with a useful error message if the spec
#     does not appear to be valid.
# 
#     Otherwise just returns.
#     """
#     if not issubclass(model, Model):
#         raise TypeError(
#             "First argument to validate_fieldspec must be a "
#             "subclass of Model; it is %r" % model
#         )
#     parts = spec.split("__", 1)
#     rest_of_spec = parts[1] if len(parts) > 1 else None
# 
#     # What are the possibilities for what parts[0] is on our model?
#     # - It could be a field
#     #   - simple (not a key)
#     #   - key
#     # - It could be a non-field
#     #   - class variable
#     #   - method
#     # - It could not exist
# 
#     try:
#         field = model._meta.get_field(parts[0])
#     except FieldDoesNotExist:
#         # Not a field - is there an attribute of some sort?
#         if not hasattr(model, parts[0]):
#             raise ValidationError(
#                 "There is no field or attribute named '%s' on model '%s'"
#                 % (parts[0], model)
#             )
#         if rest_of_spec:
#             raise ValidationError(
#                 "On model '%s', '%s' is not a field, but the spec tries to refer through "
#                 "it to '%s'." % (model, parts[0], rest_of_spec)
#             )
#         attr = getattr(model, parts[0])
#         if callable(attr):
#             if has_required_args(attr):
#                 raise ValidationError(
#                     "On model '%s', '%s' is callable and has required arguments; it is not "
#                     "valid to use in a field spec" % (model, parts[0])
#                 )
#     else:
#         # It's a field
#         # Is it a key?
#         if isinstance(field, RelatedField):
#             # Yes, refers to another model
#             if rest_of_spec:
#                 # Recurse!
#                 validate_fieldspec(model=field.related_model, spec=rest_of_spec)
#             # Well, it's okay if it just returns a reference to another record
#         else:
#             # Simple field
#             # Is there more spec?
#             if rest_of_spec:
#                 raise ValidationError(
#                     "On model '%s', '%s' is not a key field, but the spec tries to refer through "
#                     "it to '%s'." % (model, parts[0], rest_of_spec)
#                 )
#             # Simple field, no more spec, looks good


import json
from functools import reduce
from operator import or_
from urllib.parse import urlencode
from django.conf import settings
from django.contrib.admin.utils import lookup_needs_distinct
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Permission
from django.contrib.auth.views import redirect_to_login
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import (
    EmptyResultSet,
    FieldError,
    ImproperlyConfigured,
    PermissionDenied,
)
from django.db.models import Model, Q
from django.forms.models import modelform_factory
from django.http.response import HttpResponseBadRequest
from django.urls import path, reverse_lazy
from vanilla import CreateView, DeleteView, DetailView, ListView, UpdateView
from .utils import get_verbose_name, validate_fieldspec
    browse_view = BrowseView
    read_view = ReadView
    edit_view = EditView
    add_view = AddView
    delete_view = DeleteView

    exclude = []  # Names of fields not to show
    views = "BREAD"
    base_template = setting("DEFAULT_BASE_TEMPLATE", "base.html")
    namespace = ""
    template_name_pattern = None
    plural_name = None
    form_class = None

    def __init__(self):
        self.name = self.model._meta.object_name.lower()
        self.views = self.views.upper()

        if not self.plural_name:
            self.plural_name = self.name + "s"

        if not issubclass(self.model, Model):
            raise TypeError(
                "'model' argument for Bread must be a "
                "subclass of Model; it is %r" % self.model
            )

        if self.browse_view.columns:
            for colspec in self.browse_view.columns:
                column = colspec[1]

# Path: bread/utils.py
# def get_verbose_name(an_object, field_name, title_cap=True):
#     """Given a model or model instance, return the verbose_name of the model's field.
# 
#     If title_cap is True (the default), the verbose_name will be returned with the first letter
#     of each word capitalized which makes the verbose_name look nicer in labels.
# 
#     If field_name doesn't refer to a model field, raises a FieldDoesNotExist error.
#     """
#     # get_field() can raise FieldDoesNotExist which I simply propogate up to the caller.
#     try:
#         field = an_object._meta.get_field(field_name)
#     except TypeError:
#         # TypeError happens if the caller is very confused and passes an unhashable type such
#         # as {} or []. I convert that into a FieldDoesNotExist exception for simplicity.
#         raise FieldDoesNotExist("No field named {}".format(str(field_name)))
# 
#     verbose_name = field.verbose_name
# 
#     if title_cap:
#         # Title cap the label using this stackoverflow-approved technique:
#         # http://stackoverflow.com/questions/1549641/how-to-capitalize-the-first-letter-of-each-word-in-a-string-python
#         verbose_name = " ".join(word.capitalize() for word in verbose_name.split())
# 
#     return verbose_name
# 
# def validate_fieldspec(model, spec):
#     """
#     Given a model class and a string that refers to a possibly nested
#     field on that model (as used in `get_model_field`).
# 
#     Raises a ValidationError with a useful error message if the spec
#     does not appear to be valid.
# 
#     Otherwise just returns.
#     """
#     if not issubclass(model, Model):
#         raise TypeError(
#             "First argument to validate_fieldspec must be a "
#             "subclass of Model; it is %r" % model
#         )
#     parts = spec.split("__", 1)
#     rest_of_spec = parts[1] if len(parts) > 1 else None
# 
#     # What are the possibilities for what parts[0] is on our model?
#     # - It could be a field
#     #   - simple (not a key)
#     #   - key
#     # - It could be a non-field
#     #   - class variable
#     #   - method
#     # - It could not exist
# 
#     try:
#         field = model._meta.get_field(parts[0])
#     except FieldDoesNotExist:
#         # Not a field - is there an attribute of some sort?
#         if not hasattr(model, parts[0]):
#             raise ValidationError(
#                 "There is no field or attribute named '%s' on model '%s'"
#                 % (parts[0], model)
#             )
#         if rest_of_spec:
#             raise ValidationError(
#                 "On model '%s', '%s' is not a field, but the spec tries to refer through "
#                 "it to '%s'." % (model, parts[0], rest_of_spec)
#             )
#         attr = getattr(model, parts[0])
#         if callable(attr):
#             if has_required_args(attr):
#                 raise ValidationError(
#                     "On model '%s', '%s' is callable and has required arguments; it is not "
#                     "valid to use in a field spec" % (model, parts[0])
#                 )
#     else:
#         # It's a field
#         # Is it a key?
#         if isinstance(field, RelatedField):
#             # Yes, refers to another model
#             if rest_of_spec:
#                 # Recurse!
#                 validate_fieldspec(model=field.related_model, spec=rest_of_spec)
#             # Well, it's okay if it just returns a reference to another record
#         else:
#             # Simple field
#             # Is there more spec?
#             if rest_of_spec:
#                 raise ValidationError(
#                     "On model '%s', '%s' is not a key field, but the spec tries to refer through "
#                     "it to '%s'." % (model, parts[0], rest_of_spec)
#                 )
#             # Simple field, no more spec, looks good


# Path: bread/bread.py
import json
from functools import reduce
from operator import or_
from urllib.parse import urlencode
from django.conf import settings
from django.contrib.admin.utils import lookup_needs_distinct
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Permission
from django.contrib.auth.views import redirect_to_login
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import (
    EmptyResultSet,
    FieldError,
    ImproperlyConfigured,
    PermissionDenied,
)
from django.db.models import Model, Q
from django.forms.models import modelform_factory
from django.http.response import HttpResponseBadRequest
from django.urls import path, reverse_lazy
from vanilla import CreateView, DeleteView, DetailView, ListView, UpdateView
from .utils import get_verbose_name, validate_fieldspec

    browse_view = BrowseView
    read_view = ReadView
    edit_view = EditView
    add_view = AddView
    delete_view = DeleteView

    exclude = []  # Names of fields not to show
    views = "BREAD"
    base_template = setting("DEFAULT_BASE_TEMPLATE", "base.html")
    namespace = ""
    template_name_pattern = None
    plural_name = None
    form_class = None

    def __init__(self):
        self.name = self.model._meta.object_name.lower()
        self.views = self.views.upper()

        if not self.plural_name:
            self.plural_name = self.name + "s"

        if not issubclass(self.model, Model):
            raise TypeError(
                "'model' argument for Bread must be a "
                "subclass of Model; it is %r" % self.model
            )

        if self.browse_view.columns:
            for colspec in self.browse_view.columns:
                column = colspec[1]

                validate_fieldspec(self.model, column)