By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

Filter posts by state and label

roundabout,
created on Monday, 29 July 2024, 10:05:26 (1722247526), received on Wednesday, 31 July 2024, 06:54:52 (1722408892)
Author identity: vlad <vlad.muntoiu@gmail.com>

c789166a8b4e3da4e9e58630b3f9d7f463fe6898

app.py

@@ -973,7 +973,22 @@ def repository_forum_search(username, repository):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                page_length = flask.request.args.get("per_page", default_page_length, type=int)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            results = Post.query.filter(Post.repo == repo_data).filter(Post.subject.ilike(f"%{query}%") | Post.message.ilike(f"%{query}%")).order_by(Post.last_updated.desc()).paginate(page=page_number, per_page=page_length)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            all_posts = Post.query.filter(Post.repo == repo_data)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            results = (all_posts
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                       .filter(Post.subject.ilike(f"%{query}%") | Post.message.ilike(f"%{query}%"))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                       .order_by(Post.last_updated.desc()))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if flask.request.args.get("state"):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                try:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    results = results.filter(Post.state == int(flask.request.args.get("state")))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                except ValueError:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    pass         # if state is not an integer, ignore it
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if flask.request.args.get("label"):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                results = results.filter(Post.labels.any(Label.identifier == flask.request.args.get("label")))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            results = results.paginate(page=page_number, per_page=page_length)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                if results.has_next:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    next_page = results.next_num
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -1002,7 +1017,9 @@ def repository_forum_search(username, repository):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    page_length=page_length,
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    next_page=next_page,
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    prev_page=prev_page,
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                num_pages=results.pages
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                num_pages=results.pages,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                require_state=flask.request.args.get("state"),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                require_label=flask.request.args.get("label"),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                )
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repository/repo-forum-search.html

@@ -10,6 +10,17 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    <x-vbox>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        <form class="hbox">
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                            <input type="text" name="q" placeholder="{% trans %}Search...{% endtrans %}" value="{{ query }}" aria-label="{% trans %}Search query{% endtrans %}">
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <select name="state" aria-label="{% trans %}State{% endtrans %}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            <option value="">{% trans %}all{% endtrans %}</option>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            <option value="0" {% if require_state == "0" %}selected{% endif %}>{% trans %}done{% endtrans %}</option>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            <option value="1" {% if require_state == "1" %}selected{% endif %}>{% trans %}active{% endtrans %}</option>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        </select>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <select name="label" aria-label="{% trans %}Label{% endtrans %}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            <option value="">{% trans %}all{% endtrans %}</option>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            {% for label in repo_data.labels %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                <option value="{{ label.identifier }}" {% if label.identifier == require_label %}selected{% endif %}>{{ label.name }}</option>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            {% endfor %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        </select>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                            <button type="submit">{% trans %}Search{% endtrans %}</button>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        </form>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        {% for post in results %}