# Path: nuit/views.py
# class SearchableListView(ListView):
#     '''
#     Render a list of objects that's searchable.
#     '''
#     # pylint: disable=R0901
#     # pylint: disable=E1101
#     #: The fields the search will be performed on, using ``queryset.filter``.
#     search_fields = ()
# 
#     def get_context_data(self, **kwargs):
#         context = super(SearchableListView, self).get_context_data(**kwargs)
#         if self.search_fields:
#             context['search'] = True
#             query = self.request.GET.get('q')
#             if query:
#                 context['search_query'] = query
#         return context
# 
#     def get_queryset(self):
#         queryset = super(SearchableListView, self).get_queryset()
#         if self.search_fields:
#             query = self.request.GET.get('q')
#             if query is None:
#                 return queryset
#             queryset = self.search_queryset(queryset, query)
#         return queryset
# 
#     def search_queryset(self, queryset, search_term):
#         query = Q()
#         for field in self.search_fields:
#             lookup = 'icontains'
#             if not isinstance(field, string_types):
#                 field, lookup = field
#             query = query | Q(**{'%s__%s' % (field, lookup): search_term})
#         return queryset.filter(query)
# 
# Path: example_project/demo/models.py
# class Publisher(models.Model):
#     #title = models.CharField(max_length=30, choices=(('Mr', 'Mr'), ('Mrs', 'Mrs'), ('Miss', 'Miss'), ('Dr', 'Dr')), default='Mr')
#     #first_name = models.CharField(max_length=30)
#     #last_name = models.CharField(max_length=30)
#     name = models.CharField(max_length=30)
#     address = models.CharField(max_length=50)
#     city = models.CharField(max_length=60)
#     state_province = models.CharField(max_length=30)
#     country = models.CharField(max_length=50)
#     website = models.URLField()
#     sleazy = models.BooleanField()
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: example_project/demo/forms.py
# class PublisherForm(ModelForm):
#     name = CharField(help_text='The name of the publisher')
#     class Meta:
#         model = Publisher
#         fields = ('name', 'address', 'city', 'state_province', 'country', 'website', 'sleazy')
#     def clean(self):
#         raise ValidationError('Something went wrong')


from django.shortcuts import render
from nuit.views import SearchableListView
from .models import Publisher
from .forms import PublisherForm
from django.contrib import messages
from django.contrib.auth.decorators import permission_required

class MyListView(SearchableListView):
    model = Publisher
    template_name = 'demo/list_view.html'
    paginate_by = 15
    search_fields = ('name', ('address', 'iexact'))

def kitchen_sink(request):
    messages.set_level(request, messages.DEBUG)
    messages.add_message(request, messages.DEBUG, 'Debug Message')
    messages.add_message(request, messages.INFO, 'Info Message')
    messages.add_message(request, messages.SUCCESS, 'Success Message')
    messages.add_message(request, messages.WARNING, 'Warning Message')
    messages.add_message(request, messages.ERROR, 'Error Message')
    return render(request, 'demo/kitchensink.html', {})

def test_form(request):
    if request.method == 'POST':
        form = PublisherForm(request.POST)
        if form.is_valid():
            pass
    else:

# Path: nuit/views.py
# class SearchableListView(ListView):
#     '''
#     Render a list of objects that's searchable.
#     '''
#     # pylint: disable=R0901
#     # pylint: disable=E1101
#     #: The fields the search will be performed on, using ``queryset.filter``.
#     search_fields = ()
# 
#     def get_context_data(self, **kwargs):
#         context = super(SearchableListView, self).get_context_data(**kwargs)
#         if self.search_fields:
#             context['search'] = True
#             query = self.request.GET.get('q')
#             if query:
#                 context['search_query'] = query
#         return context
# 
#     def get_queryset(self):
#         queryset = super(SearchableListView, self).get_queryset()
#         if self.search_fields:
#             query = self.request.GET.get('q')
#             if query is None:
#                 return queryset
#             queryset = self.search_queryset(queryset, query)
#         return queryset
# 
#     def search_queryset(self, queryset, search_term):
#         query = Q()
#         for field in self.search_fields:
#             lookup = 'icontains'
#             if not isinstance(field, string_types):
#                 field, lookup = field
#             query = query | Q(**{'%s__%s' % (field, lookup): search_term})
#         return queryset.filter(query)
# 
# Path: example_project/demo/models.py
# class Publisher(models.Model):
#     #title = models.CharField(max_length=30, choices=(('Mr', 'Mr'), ('Mrs', 'Mrs'), ('Miss', 'Miss'), ('Dr', 'Dr')), default='Mr')
#     #first_name = models.CharField(max_length=30)
#     #last_name = models.CharField(max_length=30)
#     name = models.CharField(max_length=30)
#     address = models.CharField(max_length=50)
#     city = models.CharField(max_length=60)
#     state_province = models.CharField(max_length=30)
#     country = models.CharField(max_length=50)
#     website = models.URLField()
#     sleazy = models.BooleanField()
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: example_project/demo/forms.py
# class PublisherForm(ModelForm):
#     name = CharField(help_text='The name of the publisher')
#     class Meta:
#         model = Publisher
#         fields = ('name', 'address', 'city', 'state_province', 'country', 'website', 'sleazy')
#     def clean(self):
#         raise ValidationError('Something went wrong')


# Path: example_project/demo/views.py
from django.shortcuts import render
from nuit.views import SearchableListView
from .models import Publisher
from .forms import PublisherForm
from django.contrib import messages
from django.contrib.auth.decorators import permission_required


class MyListView(SearchableListView):
    model = Publisher
    template_name = 'demo/list_view.html'
    paginate_by = 15
    search_fields = ('name', ('address', 'iexact'))

def kitchen_sink(request):
    messages.set_level(request, messages.DEBUG)
    messages.add_message(request, messages.DEBUG, 'Debug Message')
    messages.add_message(request, messages.INFO, 'Info Message')
    messages.add_message(request, messages.SUCCESS, 'Success Message')
    messages.add_message(request, messages.WARNING, 'Warning Message')
    messages.add_message(request, messages.ERROR, 'Error Message')
    return render(request, 'demo/kitchensink.html', {})

def test_form(request):
    if request.method == 'POST':
        form = PublisherForm(request.POST)
        if form.is_valid():
            pass
    else:

        form = PublisherForm()