def index(): menu = 'societe' submenu = 'entreprise' context = 'domaine' title_page = 'Parametre - Domaines' search = False q = request.args.get('q') if q: search = True try: page = int(request.args.get('page', 1)) except ValueError: page = 1 datas = Domaine.query() pagination = Pagination(css_framework='bootstrap3', page=page, total=datas.count(), search=search, record_name='domaines') if datas.count() > 10: if page == 1: offset = 0 else: page -= 1 offset = page * 10 datas = datas.fetch(limit=10, offset=offset) return render_template('domaine/index.html', **locals())
def unique_code_validator(form, field): code_unique = Domaine.query( Domaine.code == field.data ).count() if code_unique: if not form.id.data: raise wtf.ValidationError('Ce code est deja utilise dans le domaine.') else: code = Domaine.get_by_id(int(form.id.data)) if code.code != field.data: raise wtf.ValidationError('Ce code est deja utilise dans le domaine.')