added Search form, not working yet
This commit is contained in:
48
suivi/search.py
Normal file
48
suivi/search.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from django.views.generic.edit import FormMixin, ProcessFormView
|
||||
from django import forms
|
||||
|
||||
from django.shortcuts import redirect
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
|
||||
search_text = forms.CharField(64, widget=forms.widgets.TextInput(attrs={'placeholder':"NotYetImplemented"}))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['prefix'] = 'search'
|
||||
return super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
#Do search and store result
|
||||
self.result = None
|
||||
|
||||
def is_valid(self):
|
||||
valid = super().is_valid()
|
||||
if not self.result:
|
||||
return False
|
||||
return valid
|
||||
|
||||
class SearchFormMixin(FormMixin):
|
||||
""" Add 'search_form' to context.
|
||||
Made compatible with NoteFormMixin using 'prefix' argument in get_form
|
||||
"""
|
||||
def get_form(self, prefix):
|
||||
if prefix == 'search':
|
||||
return SearchForm()
|
||||
return super().get_form(prefix)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['search_form'] = self.get_form('search')
|
||||
return context
|
||||
|
||||
""" What to do ?
|
||||
|
||||
- We shall use 'django-watson', need to install it
|
||||
|
||||
- Create view to parse search_form data then redirect
|
||||
- Link form in menu_sujets to this view
|
||||
"""
|
||||
|
||||
class SearchFormProcessView(ProcessFormView):
|
||||
pass
|
||||
@@ -1,9 +1,14 @@
|
||||
{% load bootstrap3 %}
|
||||
<li class="app-menu">
|
||||
{% load bootstrap3 %}<li class="app-menu">
|
||||
<a href="{% url 'sujets:liste' %}">Liste des sujets
|
||||
<span class="pull-right">{% bootstrap_icon "list" %}</span></a>
|
||||
</li>
|
||||
{% if user.is_superuser %}{% load bootstrap3 %}
|
||||
{% if search_form %}
|
||||
<form class="navbar-form app-menu" method="POST" action="search/">
|
||||
{% bootstrap_form search_form show_label=False %}
|
||||
{% bootstrap_button 'Chercher' button_type='submit' %}
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if user.is_superuser %}
|
||||
<li class="dropdown app-menu">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
Administration <b class="caret"></b>
|
||||
|
||||
@@ -6,6 +6,7 @@ from sujets.models import Sujet
|
||||
from .forms import *
|
||||
from notes.mixins import NoteFormMixin
|
||||
from notes.forms import AutoNoteForm
|
||||
from .search import SearchFormMixin, SearchFormProcessView
|
||||
# Create your views here.
|
||||
from website import decorators as website
|
||||
webpage = website.webpage(
|
||||
@@ -17,7 +18,7 @@ webpage = website.webpage(
|
||||
|
||||
|
||||
@webpage
|
||||
class IndexView(NoteFormMixin, generic.TemplateView):
|
||||
class IndexView(SearchFormMixin, NoteFormMixin, generic.TemplateView):
|
||||
class PageInfo:
|
||||
title = "Suivi des bénéficiaires"
|
||||
header = "Suivi"
|
||||
|
||||
Reference in New Issue
Block a user