Exemple #1
0
    def get_context(self):
        last_week = datetime.datetime.now() - datetime.timedelta(days=7)
        signups_this_week = User.select().where(User.join_date > last_week).count()
        messages_this_week = Message.select().where(Message.pub_date > last_week).count()
        return {
            'signups': signups_this_week,
            'messages': messages_this_week,
        }


admin = Admin(app, auth, branding='Admin the boat')


class MessageAdmin(ModelAdmin):
    columns = ('user', 'content', 'pub_date',)
    foreign_key_lookups = {'user': '******'}
    filter_fields = ('user', 'content', 'pub_date', 'user__username')

class NoteAdmin(ModelAdmin):
    columns = ('user', 'message', 'created_date',)
    exclude = ('created_date',)


auth.register_admin(admin)
#admin.register(Relationship)
admin.register(Message, MessageAdmin)
admin.register(Note, NoteAdmin)
admin.register_panel('Notes', NotePanel)
admin.register_panel('User stats', UserStatsPanel)
Exemple #2
0
class GroupAdmin(Base):
    columns = ('id', 'leader', 'title', 'finished', 'created', 'modified')


class ProductAdmin(Base):
    columns = ('id', 'title', 'content', 'price', 'group', 'photo', 'created', 'modified')


class PurchaseAdmin(Base):
    columns = ('id', 'buyer', 'product', 'amount', 'created', 'modified')


class UserAdmin(Base):
    columns = ['id', 'username', 'active', 'admin']

    def save_model(self, instance, form, adding=False):
        orig_password = instance.password
        user = super(UserAdmin, self).save_model(instance, form, adding)
        if orig_password != form.password.data:
            user.set_password(form.password.data)
            user.save()
        return user


admin = Admin(app, auth, branding=u'团购助手后台')
auth.register_admin(admin, UserAdmin)
admin.register(WXUser, WXUserAdmin)
admin.register(Group, GroupAdmin)
admin.register(Product, ProductAdmin)
admin.register(Purchase, PurchaseAdmin)
Exemple #3
0
# -*- coding: utf-8 -*-
"""
Admin dashboard.
Configures the admin interface.
"""

from flask_peewee.admin import Admin

from app import app
from auth import auth
from user import User
from product import Product
from customer import Customer

#
# Setup the admin interface.
#
admin = Admin(app, auth)
auth.register_admin(admin)

#
# Register the models available in the admin interface.
#
admin.register(User)
admin.register(Customer)
admin.register(Product)

# Enable the admin interface.
admin.setup()
import datetime

from flask_peewee.admin import Admin, ModelAdmin, AdminPanel

from app import app
from auth import auth
from models import User, Relationship


class UserStatsPanel(AdminPanel):
    template_name = 'admin/user_stats.html'

    def get_context(self):
        last_week = datetime.datetime.now() - datetime.timedelta(days=7)
        signups_this_week = User.select().where(User.joined > last_week).count()
        return {
            'signups': signups_this_week,
        }

class UserAdmin(ModelAdmin):
    # it doesn't work yet because flask-peewe has error
    columns = ('email', 'active', 'admin', 'joined')


admin = Admin(app, auth, branding=app.config['BRAND'])
auth.register_admin(admin, UserAdmin)

admin.register_panel('User stats', UserStatsPanel)

admin.register(Relationship)