Casper Van Gheluwe 11 лет назад
Родитель
Сommit
b3c00955da

+ 1 - 1
flaskbb/forum/forms.py

@@ -88,4 +88,4 @@ class SearchPageForm(Form):
             if type in types:
             if type in types:
                 results[type] = search_actions[type](query)
                 results[type] = search_actions[type](query)
 
 
-        return results
+        return results

+ 1 - 1
flaskbb/forum/models.py

@@ -692,4 +692,4 @@ class Category(db.Model):
         # and finally delete the category itself
         # and finally delete the category itself
         db.session.delete(self)
         db.session.delete(self)
         db.session.commit()
         db.session.commit()
-        return self
+        return self

+ 0 - 1
flaskbb/forum/views.py

@@ -516,4 +516,3 @@ def search():
         return render_template('forum/search_result.html', form=form, result=result)
         return render_template('forum/search_result.html', form=form, result=result)
 
 
     return render_template('forum/search_form.html', form=form)
     return render_template('forum/search_form.html', form=form)
-

+ 8 - 10
flaskbb/templates/admin/users.html

@@ -32,14 +32,7 @@
         </tr>
         </tr>
     </thead>
     </thead>
     <tbody>
     <tbody>
-        {% if not users.items %}
-        <tr>
-            <td colspan="6">
-                No users found matching your search query
-            </td>
-        </tr>
-        {% else %}
-            {% for user in users.items %}
+        {% for user in users.items %}
             <tr>
             <tr>
                 <td>{{ user.id }}</td>
                 <td>{{ user.id }}</td>
                 <td><a href="{{ url_for('user.profile', username=user.username) }}">{{ user.username }}</a></td>
                 <td><a href="{{ url_for('user.profile', username=user.username) }}">{{ user.username }}</a></td>
@@ -51,8 +44,13 @@
                     <a href="{{ url_for('admin.delete_user', user_id = user.id) }}">Delete</a>
                     <a href="{{ url_for('admin.delete_user', user_id = user.id) }}">Delete</a>
                 </td>
                 </td>
             </tr>
             </tr>
-            {% endfor %}
-        {% endif %}
+        {% else %}
+            <tr>
+                <td colspan="6">
+                    No users found matching your search query
+                </td>
+            </tr>
+        {% endfor %}
     </tbody>
     </tbody>
 </table>
 </table>
 {% endblock %}
 {% endblock %}

+ 172 - 184
flaskbb/templates/forum/search_result.html

@@ -14,63 +14,61 @@
 
 
         <table class="table table-bordered">
         <table class="table table-bordered">
             <tbody>
             <tbody>
-            {% if result['post'].all() %}
-                {% for post in result['post'].all() %}
-                <tr>
-                    <td>
-                        <table class="table table-borderless">
-                            <tr>
-                                {% if post.user_id %}
-                                    {% if post.user.avatar %}
-                                        <td width="1">
-                                            <img src="{{ post.user.avatar }}" alt="Avatar" height="100" width="100">
-                                        </td>
-                                    {% endif %}
-                                    <td>
-                                        <a href="{{ post.user.url }}">
-                                            <span style="font-weight:bold">{{ post.user.username }}</span> <!-- TODO: Implement userstyles -->
-                                        </a>
-                                        {%- if post.user|is_online %}
-                                            <span class="label label-success">Online</span>
-                                        {%- else %}
-                                            <span class="label label-default">Offline</span>
-                                        {%- endif %}
-                                        <div class="profile primary-group">
-                                            {{ post.user.primary_group.name }}
-                                        </div>
-                                    </td>
-
-                                    <td class="pull-right">
-                                        Posts: {{ post.user.post_count }}<br />
-                                        Registered since: {{ post.user.date_joined|format_date('%b %d %Y') }}<br />
-                                    </td>
-                                {% else %}
-                                    <td>
-                                        <strong>{{ post.username }}</strong>
-                                        <br />
-                                        Guest
+            {% for post in result['post'].all() %}
+            <tr>
+                <td>
+                    <table class="table table-borderless">
+                        <tr>
+                            {% if post.user_id %}
+                                {% if post.user.avatar %}
+                                    <td width="1">
+                                        <img src="{{ post.user.avatar }}" alt="Avatar" height="100" width="100">
                                     </td>
                                     </td>
                                 {% endif %}
                                 {% endif %}
-                            </tr>
-                        </table>
-                    </td>
-                </tr>
+                                <td>
+                                    <a href="{{ post.user.url }}">
+                                        <span style="font-weight:bold">{{ post.user.username }}</span> <!-- TODO: Implement userstyles -->
+                                    </a>
+                                    {%- if post.user|is_online %}
+                                        <span class="label label-success">Online</span>
+                                    {%- else %}
+                                        <span class="label label-default">Offline</span>
+                                    {%- endif %}
+                                    <div class="profile primary-group">
+                                        {{ post.user.primary_group.name }}
+                                    </div>
+                                </td>
+
+                                <td class="pull-right">
+                                    Posts: {{ post.user.post_count }}<br />
+                                    Registered since: {{ post.user.date_joined|format_date('%b %d %Y') }}<br />
+                                </td>
+                            {% else %}
+                                <td>
+                                    <strong>{{ post.username }}</strong>
+                                    <br />
+                                    Guest
+                                </td>
+                            {% endif %}
+                        </tr>
+                    </table>
+                </td>
+            </tr>
 
 
-                <tr>
-                    <td>
-                        <div class="post_body" id="pid{{ post.id }}">
-                            {% autoescape false %}
-                            {{ post.content|markup }}
-                            {% endautoescape %}
-                        </div>
-                    </td>
-                </tr>
-                {% endfor %}
+            <tr>
+                <td>
+                    <div class="post_body" id="pid{{ post.id }}">
+                        {% autoescape false %}
+                        {{ post.content|markup }}
+                        {% endautoescape %}
+                    </div>
+                </td>
+            </tr>
             {% else %}
             {% else %}
-                <tr>
-                    <td>No posts found matching your search criteria</td>
-                </tr>
-            {% endif %}
+            <tr>
+                <td>No posts found matching your search criteria</td>
+            </tr>
+            {% endfor %}
             </tbody>
             </tbody>
         </table>
         </table>
     {% endif %}
     {% endif %}
@@ -89,21 +87,19 @@
             </tr>
             </tr>
             </thead>
             </thead>
             <tbody>
             <tbody>
-            {% if result['user'].all() %}
-                {% for user in result['user'].all() %}
-                    <tr>
-                        <td>{{ user.id }}</td>
-                        <td><a href="{{ user.url }}">{{ user.username }}</a></td>
-                        <td>{{ user.post_count }}</td>
-                        <td>{{ user.date_joined|format_date('%b %d %Y') }}</td>
-                        <td>{{ user.primary_group.name }}</td>
-                    </tr>
-                {% endfor %}
+            {% for user in result['user'].all() %}
+                <tr>
+                    <td>{{ user.id }}</td>
+                    <td><a href="{{ user.url }}">{{ user.username }}</a></td>
+                    <td>{{ user.post_count }}</td>
+                    <td>{{ user.date_joined|format_date('%b %d %Y') }}</td>
+                    <td>{{ user.primary_group.name }}</td>
+                </tr>
             {% else %}
             {% else %}
                 <tr>
                 <tr>
                     <td colspan="5">No users found matching your search criteria</td>
                     <td colspan="5">No users found matching your search criteria</td>
                 </tr>
                 </tr>
-            {% endif %}
+            {% endfor %}
             </tbody>
             </tbody>
         </table>
         </table>
     {% endif %}
     {% endif %}
@@ -125,54 +121,50 @@
             </thead>
             </thead>
 
 
             <tbody>
             <tbody>
+            {% for topic in result['topic'].all() %}
+                <tr>
+                    <td width="4%">
+                        {% if topic.locked %}
+                            <span class="fa fa-locked" style="font-size: 2em"></span>
+                        {% else %}
+                            <span class="fa fa-comment-o" style="font-size: 2em"></span>
+                        {% endif %}
 
 
-            {% if result['topic'].all() %}
-                {% for topic in result['topic'].all() %}
-                    <tr>
-                        <td width="4%">
-                            {% if topic.locked %}
-                                <span class="fa fa-locked" style="font-size: 2em"></span>
+                    </td>
+                    <td>
+                        <div>
+                            <a href="{{ topic.url }}">{{ topic.title }}</a>
+                            <!-- Topic Pagination -->
+                            {{ topic_pages(topic, config["POSTS_PER_PAGE"]) }}
+                            <br />
+                            {% if topic.user_id %}
+                                <small>by <a href="{{ topic.user.url }}">{{ topic.user.username }}</a></small>
                             {% else %}
                             {% else %}
-                                <span class="fa fa-comment-o" style="font-size: 2em"></span>
+                                <small>by {{ topic.username }}</small>
                             {% endif %}
                             {% endif %}
+                        </div>
+                    </td>
+                    <td>
+                        {{ topic.post_count }}
+                    </td>
+                    <td>
+                        {{ topic.views }}
+                    </td>
+                    <td>
+                        <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />
 
 
-                        </td>
-                        <td>
-                            <div>
-                                <a href="{{ topic.url }}">{{ topic.title }}</a>
-                                <!-- Topic Pagination -->
-                                {{ topic_pages(topic, config["POSTS_PER_PAGE"]) }}
-                                <br />
-                                {% if topic.user_id %}
-                                    <small>by <a href="{{ topic.user.url }}">{{ topic.user.username }}</a></small>
-                                {% else %}
-                                    <small>by {{ topic.username }}</small>
-                                {% endif %}
-                            </div>
-                        </td>
-                        <td>
-                            {{ topic.post_count }}
-                        </td>
-                        <td>
-                            {{ topic.views }}
-                        </td>
-                        <td>
-                            <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />
-
-                            {% if topic.last_post.user_id %}
-                                <small>by <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a></small>
-                            {% else %}
-                                <small>{{ topic.last_post.username }}</small>
-                            {% endif %}
-                        </td>
-                    </tr>
-                {% endfor %}
+                        {% if topic.last_post.user_id %}
+                            <small>by <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a></small>
+                        {% else %}
+                            <small>{{ topic.last_post.username }}</small>
+                        {% endif %}
+                    </td>
+                </tr>
             {% else %}
             {% else %}
                 <tr>
                 <tr>
                     <td colspan="5">No topics found matching your search criteria</td>
                     <td colspan="5">No topics found matching your search criteria</td>
                 </tr>
                 </tr>
-            {% endif %}
-
+            {% endfor %}
             </tbody>
             </tbody>
         </table>
         </table>
     {% endif %}
     {% endif %}
@@ -190,90 +182,86 @@
             </tr>
             </tr>
             </thead>
             </thead>
             <tbody class="forumbody">
             <tbody class="forumbody">
-            {% if result['forum'].all() %}
-                {% for forum in result['forum'].all() %}
-                <tr>
-                    <td align="center" valign="center" width="4%">
-
-                        {% if forum[0].external %}
-                        <span class="fa fa-external-link" style="font-size: 2em"></span>
-                    </td>
-
-                    <td valign="top">
-                        <strong><a href="{{ forum[0].external }}">{{ forum[0].title }}</a></strong>
-
-                        <div class="forum-description">
-                            {% autoescape false %}
-                            {{ forum[0].description|markup }}
-                            {% endautoescape %}
-                        </div>
-                    </td>
-
-                    <td valign="top" align="center" style="white-space: nowrap">-</td>
-                    <td valign="top" align="center" style="white-space: nowrap">-</td>
-                    <td valign="top" align="right" style="white-space: nowrap">-</td>
-                    <!-- End external -->
-                    {% else %}
+            {% for forum in result['forum'].all() %}
+            <tr>
+                <td align="center" valign="center" width="4%">
+
+                    {% if forum.external %}
+                    <span class="fa fa-external-link" style="font-size: 2em"></span>
+                </td>
+
+                <td valign="top">
+                    <strong><a href="{{ forum.external }}">{{ forum.title }}</a></strong>
+
+                    <div class="forum-description">
+                        {% autoescape false %}
+                        {{ forum.description|markup }}
+                        {% endautoescape %}
+                    </div>
+                </td>
+
+                <td valign="top" align="center" style="white-space: nowrap">-</td>
+                <td valign="top" align="center" style="white-space: nowrap">-</td>
+                <td valign="top" align="right" style="white-space: nowrap">-</td>
+                <!-- End external -->
+                {% else %}
+
+                {% if forum.locked %}
+                    <span class="fa fa-lock" style="font-size: 2em"></span>
+                {% else %}
+                    <span class="fa fa-comments-o" style="font-size: 2em"></span>
+                {% endif %}
+
+                </td>
+
+                <td valign="top">
+                    <strong><a href="{{ forum.url }}">{{ forum.title }}</a></strong>
+
+                    <div class="forum-description">
+                        {% autoescape false %}
+                        {{ forum.description|markup }}
+                        {% endautoescape %}
+                        {% if forum.show_moderators %}
+                            <div class="forum-moderators">
+                                Moderators:
+                                {% for moderator in forum.moderators %}
+                                    <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
+                                {% endfor %}
+                            </div>
+                        {% endif %}
+                    </div>
+                </td>
+
+                <td valign="top" align="center" style="white-space: nowrap">{{ forum.topic_count }}</td>
+                <td valign="top" align="center" style="white-space: nowrap">{{ forum.post_count }}</td>
+
+                <td valign="top" align="right" style="white-space: nowrap">
+                    {% if forum.last_post_id %}
+                        <a href="{{ forum.last_post.url }}" title="{{ forum.last_post.topic.title }}">
+                            <strong>{{ forum.last_post.topic.title|crop_title }}</strong>
+                        </a>
+                        <br />
+                        {{ forum.last_post.date_created|time_since }}<br />
+
+                        {% if forum.last_post.user_id %}
+                            by <a href="{{ url_for('user.profile', username=forum.last_post.user.username) }}">{{ forum.last_post.user.username }}</a>
+                        {% else %}
+                            {{ forum.last_post.username }}
+                        {% endif %}
 
 
-                    {% if forum[0].locked %}
-                        <span class="fa fa-lock" style="font-size: 2em"></span>
-                    {% elif forum[0]|forum_is_unread(forum[1], current_user) %}
-                        <span class="fa fa-comments" style="font-size: 2em"></span>
                     {% else %}
                     {% else %}
-                        <span class="fa fa-comments-o" style="font-size: 2em"></span>
+                        No posts
                     {% endif %}
                     {% endif %}
-
-                    </td>
-
-                    <td valign="top">
-                        <strong><a href="{{ forum[0].url }}">{{ forum[0].title }}</a></strong>
-
-                        <div class="forum-description">
-                            {% autoescape false %}
-                            {{ forum[0].description|markup }}
-                            {% endautoescape %}
-                            {% if forum[0].show_moderators %}
-                                <div class="forum-moderators">
-                                    Moderators:
-                                    {% for moderator in forum[0].moderators %}
-                                        <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
-                                    {% endfor %}
-                                </div>
-                            {% endif %}
-                        </div>
-                    </td>
-
-                    <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].topic_count }}</td>
-                    <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].post_count }}</td>
-
-                    <td valign="top" align="right" style="white-space: nowrap">
-                        {% if forum[0].last_post_id %}
-                            <a href="{{ forum[0].last_post.url }}" title="{{ forum[0].last_post.topic.title }}">
-                                <strong>{{ forum[0].last_post.topic.title|crop_title }}</strong>
-                            </a>
-                            <br />
-                            {{ forum[0].last_post.date_created|time_since }}<br />
-
-                            {% if forum[0].last_post.user_id %}
-                                by <a href="{{ url_for('user.profile', username=forum[0].last_post.user.username) }}">{{ forum[0].last_post.user.username }}</a>
-                            {% else %}
-                                {{ forum[0].last_post.username }}
-                            {% endif %}
-
-                        {% else %}
-                            No posts
-                        {% endif %}
-                        {% endif %}
-                    </td>
-                </tr>
-                {% endfor %}
+                    {% endif %}
+                </td>
+            </tr>
             {% else %}
             {% else %}
-                <tr>
-                    <td colspan="5">
-                        No forums found matching your search criteria
-                    </td>
-                </tr>
-            {% endif %}
+            <tr>
+                <td colspan="5">
+                    No forums found matching your search criteria
+                </td>
+            </tr>
+            {% endfor %}
             </tbody>
             </tbody>
         </table>
         </table>
     {% endif %}
     {% endif %}