Browse Source

It works!

Committing so I can work on my computer as well.
sh4nks 10 years ago
parent
commit
20f9c37f28

+ 7 - 2
flaskbb/management/views.py

@@ -13,7 +13,7 @@ import os
 from datetime import datetime
 
 from flask import (Blueprint, current_app, request, redirect, url_for, flash,
-                   __version__ as flask_version)
+                   jsonify, __version__ as flask_version)
 from flask_login import current_user
 from flask_plugins import get_all_plugins, get_plugin, get_plugin_from_all
 from flask_babelex import gettext as _
@@ -192,13 +192,18 @@ def banned_users():
                            search_form=search_form)
 
 
+@management.route("/users/ban", methods=["POST"])
 @management.route("/users/<int:user_id>/ban", methods=["POST"])
 @moderator_required
-def ban_user(user_id):
+def ban_user(user_id=None):
     if not can_ban_user(current_user):
         flash(_("You do not have the permissions to ban this user."), "danger")
         return redirect(url_for("management.overview"))
 
+    if request.is_xhr:
+        print "I AM A XHR REQUEST"
+        return jsonify(message="success", status=200)
+
     user = User.query.filter_by(id=user_id).first_or_404()
 
     # Do not allow moderators to ban admins

+ 24 - 0
flaskbb/static/js/management.js

@@ -0,0 +1,24 @@
+/**
+ * management.js
+ */
+var csrftoken = $('meta[name=csrf-token]').attr('content');
+$(document).ready(function() {
+
+    $('#ban_users').click(function(event) {
+        event.preventDefault();
+
+        $.ajax({
+            beforeSend: function(xhr, settings) {
+                if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
+                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
+                }
+            },
+            url: MANAGEMENT_URL + "/users/ban",
+            method: "POST",
+            data: { ids: [3, 4] },
+            success: function(result) {
+                console.log(result);
+            }
+        });
+    })
+});

+ 0 - 1
flaskbb/templates/forum/new_post.html

@@ -4,7 +4,6 @@
 {% extends theme("layout.html") %}
 
 {% block css %}
-    {{ super() }}
     <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-markdown.min.css') }}">
 {% endblock %}
 

+ 0 - 1
flaskbb/templates/forum/new_topic.html

@@ -4,7 +4,6 @@
 {% extends theme("layout.html") %}
 
 {% block css %}
-    {{ super() }}
     <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-markdown.min.css') }}">
 {% endblock %}
 

+ 0 - 1
flaskbb/templates/forum/topic.html

@@ -3,7 +3,6 @@
 {% set active_forum_nav=True %}
 
 {% block css %}
-    {{ super() }}
     <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-markdown.min.css') }}">
 {% endblock %}
 

+ 12 - 1
flaskbb/templates/layout.html

@@ -11,18 +11,27 @@
             {%- endif -%}
         {% endblock %}
         </title>
+
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <meta name="description" content="FlaskBB is a forum software written in Flask">
         <meta name="author" content="FlaskBB Team">
 
         <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
 
-        {% block css %}
+        {% block stylesheets %}
         <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css') }}" >
         <link rel="stylesheet" href="{{ url_for('static', filename='css/code.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/flaskbb.css') }}">
         {% endblock %}
+
+        {# for extra stylesheets. e.q. a template has to add something #}
+        {% block css %}
+        {% endblock %}
+
+        {# for various extra things #}
+        {% block head_extra %}
+        {% endblock %}
     </head>
 
     <body>
@@ -121,11 +130,13 @@
             </div>
             {% endblock %}
 
+        {# standard javascript libs #}
         {% block javascript %}
         <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
         <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
         {% endblock %}
 
+        {# space for extra scripts - to use in other templates #}
         {% block scripts %}
         {% endblock %}
     </body>

+ 13 - 0
flaskbb/templates/management/management_layout.html

@@ -1,4 +1,10 @@
 {% extends theme("layout.html") %}
+
+{% block head_extra %}
+{# include the csrf token here because we access it in the javascript #}
+<meta name="csrf-token" content="{{ csrf_token() }}">
+{% endblock %}
+
 {% block content %}
 {%- from theme('macros.html') import navlink with context -%}
 
@@ -20,3 +26,10 @@
 {% block management_content %}{% endblock %}
 
 {% endblock %}
+
+{% block scripts %}
+<script>
+    var MANAGEMENT_URL = "/admin";
+</script>
+<script src="{{ url_for('static', filename='js/management.js') }}"></script>
+{% endblock %}

+ 1 - 1
flaskbb/templates/management/users.html

@@ -42,7 +42,7 @@
                 <th>{% trans %}Posts{% endtrans %}</th>
                 <th>{% trans %}Date registered{% endtrans %}</th>
                 <th>{% trans %}Group{% endtrans %}</th>
-                <th>{% trans %}Manage{% endtrans %}</th>
+                <th><button class="btn btn-danger" id="ban_users">{% trans %}Ban{% endtrans %}</button></th>
             </tr>
         </thead>
         <tbody>

+ 9 - 1
flaskbb/themes/bootstrap2/templates/layout.html

@@ -17,13 +17,21 @@
 
         <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
 
-        {% block css %}
+        {% block stylesheets %}
         <link rel="stylesheet" href="{{ url_for('static', filename='css/code.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
         <link rel="stylesheet" href="{{ theme_static('css/bootstrap-theme.min.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/flaskbb.css') }}">
         {% endblock %}
+
+        {# for extra stylesheets. e.q. a template has to add something #}
+        {% block css %}
+        {% endblock %}
+
+        {# for various extra things #}
+        {% block head_extra %}
+        {% endblock %}
     </head>
 
     <body>

+ 10 - 1
flaskbb/themes/bootstrap3/templates/layout.html

@@ -11,18 +11,27 @@
             {%- endif -%}
         {% endblock %}
         </title>
+
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <meta name="description" content="FlaskBB is a forum software written in Flask">
         <meta name="author" content="FlaskBB Team">
 
         <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
 
-        {% block css %}
+        {% block stylesheets %}
         <link rel="stylesheet" href="{{ url_for('static', filename='css/code.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css') }}">
         <link rel="stylesheet" href="{{ url_for('static', filename='css/flaskbb.css') }}">
         {% endblock %}
+
+        {# for extra stylesheets. e.q. a template has to add something #}
+        {% block css %}
+        {% endblock %}
+
+        {# for various extra things #}
+        {% block head_extra %}
+        {% endblock %}
     </head>
 
     <body>