pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

Why MenuCategory is defined as a string and it is inconvenient to add an icon. #1730

Open allphfa opened 6 years ago

allphfa commented 6 years ago

Can't we use it? We need to patch it.

a = MenuCategory('Info', icon_type=ICON_TYPE_GLYPH, icon_value='icon-desktop')

admin.add_view(UserA(User, category=a, menu_icon_type=ICON_TYPE_GLYPH, menu_icon_value='icon-desktop'))
admin.add_view(ModelView(Role, category=a, menu_icon_type=ICON_TYPE_GLYPH, menu_icon_value='icon-desktop'))

base.html line: 6

    <title>{%- block title -%}{% if admin_view.category %}
      {% if admin_view.category.__class__ == ''.__class__ %}
          {{ admin_view.category }}
      {% else %}
          {{ admin_view.category.name }}
      {% endif %}
       - {% endif %}{{ admin_view.name }} - {{ admin_view.admin.name }}
      {% endblock %}</title>

layout.html line: 29

          <a class="dropdown-toggle" href="javascript:void(0)">
            {% if item.__class__ != ''.__class__ %}
                {% set item = item.name %}
            {% endif %}
            {{ menu_icon(item) }} <span class="menu-text">{{ item.name }}</span><b class="arrow icon-angle-down"></b>
          </a>

This is a complete theme.

admin theme

ljluestc commented 4 months ago

from flask import Flask
from flask_admin import Admin, BaseView, expose
from flask_admin.contrib.mongoengine import ModelView
from flask_admin.menu import MenuCategory

app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'

# Define your models (User and Role) here using MongoEngine

# Custom Menu Categories
info_category = MenuCategory('Info', icon_type='glyph', icon_value='icon-desktop')

# Custom Views
class UserA(BaseView):
    @expose('/')
    def index(self):
        # Your view logic here
        return self.render('user_a.html')

# Setup Flask-Admin
admin = Admin(app, name='Admin Panel', template_mode='bootstrap3')

# Add views to Flask-Admin
admin.add_view(UserA(name='User A', category=info_category, menu_icon_type='glyph', menu_icon_value='icon-desktop'))
admin.add_view(ModelView(Role, category=info_category, menu_icon_type='glyph', menu_icon_value='icon-desktop'))

if __name__ == '__main__':
    app.run(debug=True)