search: Add url-names
This commit is contained in:
parent
74ba0896cf
commit
c31ecb93bb
|
@ -15,39 +15,39 @@ class SearchForm(FlaskForm):
|
|||
class AdvancedSearchForm(SearchForm):
|
||||
def generate_choices():
|
||||
choices = {'Forum': [
|
||||
'Tous',
|
||||
'Actualités',
|
||||
'Aide et questions',
|
||||
'Forum des projets',
|
||||
'Vie communautaire',
|
||||
('all-forum', 'Tous les forums'),
|
||||
('news-forum', 'Actualités'),
|
||||
('help-and-questions-forum', 'Aide et questions'),
|
||||
('projects-forum', 'Forum des projets'),
|
||||
('community-forum', 'Vie communautaire'),
|
||||
], 'Programmes': [
|
||||
'Tous',
|
||||
'Jeux',
|
||||
'Utilitaires',
|
||||
'Logiciels'
|
||||
('all-programs', 'Tous les programmes'),
|
||||
('games-programs', 'Jeux'),
|
||||
('utilities-programs', 'Utilitaires'),
|
||||
('software-programs', 'Logiciels')
|
||||
], 'Utilisateurs': [
|
||||
'Tous'
|
||||
('all-users', 'Tous les utilisateurs')
|
||||
], 'Tutoriels': [
|
||||
'Tous',
|
||||
'Basic',
|
||||
'C/C++',
|
||||
'Arduino',
|
||||
'Python'
|
||||
('all-tutorials', 'Tous les tutoriels'),
|
||||
('basic-tutorials', 'Basic'),
|
||||
('c-cpp-tutorials', 'C/C++'),
|
||||
('arduino-tutorials', 'Arduino'),
|
||||
('python-tutorials', 'Python')
|
||||
], 'Sprites': [
|
||||
'Tous',
|
||||
'Personnages',
|
||||
'Environnements',
|
||||
'Objets',
|
||||
'Interfaces'
|
||||
('all-sprites', 'Tous les sprites'),
|
||||
('characters-sprites', 'Personnages'),
|
||||
('environnement-sprites', 'Environnements'),
|
||||
('objects-sprites', 'Objets'),
|
||||
('interfaces-sprites', 'Interfaces')
|
||||
]}
|
||||
# Forum reserved for admins and moderators
|
||||
f = Forum.query.filter_by(url='/admin').first()
|
||||
if (current_user.is_authenticated and current_user.can_access_forum(f)):
|
||||
choices['Forum'].append('Administration')
|
||||
choices['Forum'].append('administration-forum', 'Administration')
|
||||
# Forum reserved to members of CreativeCalc
|
||||
f = Forum.query.filter_by(url='/creativecalc').first()
|
||||
if (current_user.is_authenticated and current_user.can_access_forum(f)):
|
||||
choices['Forum'].append('CreativeCalc')
|
||||
choices['Forum'].append('creativecalc-forum', 'CreativeCalc')
|
||||
return choices
|
||||
|
||||
sortBy = SelectField('Trier',
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
from app import app, db
|
||||
from app.forms.search import AdvancedSearchForm, SearchForm
|
||||
from app.forms.search import AdvancedSearchForm
|
||||
from app.models.post import Post
|
||||
from app.models.comment import Comment
|
||||
from app.models.topic import Topic
|
||||
from app.models.forum import Forum
|
||||
from app.models.program import Program
|
||||
from app.utils.render import render
|
||||
from sqlalchemy import text, func, Date
|
||||
from sqlalchemy import func, Date
|
||||
from flask import request
|
||||
from flask_sqlalchemy import Pagination
|
||||
|
||||
|
||||
SEARCH_RESULTS_PER_PAGE = 20
|
||||
|
||||
|
||||
def paginate(data, page, per_page):
|
||||
# Based on page and per_page info, calculate start and end index of items to keep
|
||||
# Based on page and per_page info, calculate start and end index of items
|
||||
start_index = (page - 1) * per_page
|
||||
end_index = start_index + per_page
|
||||
|
||||
|
@ -24,11 +24,15 @@ def paginate(data, page, per_page):
|
|||
# Create Pagination object
|
||||
return Pagination(None, page, per_page, len(data), items)
|
||||
|
||||
|
||||
def websearch_to_tsquery_multilang(search):
|
||||
return func.websearch_to_tsquery('french', search).op('||')(func.websearch_to_tsquery('english', search))
|
||||
return func.websearch_to_tsquery('french', search).op(
|
||||
'||')(func.websearch_to_tsquery('english', search))
|
||||
|
||||
|
||||
def to_tsvector_multilang(text):
|
||||
return func.to_tsvector('french', text).op('||')(func.to_tsvector('english', text))
|
||||
return func.to_tsvector('french', text).op(
|
||||
'||')(func.to_tsvector('english', text))
|
||||
|
||||
|
||||
@app.route('/rechercher/')
|
||||
|
|
Loading…
Reference in New Issue