Beispiel #1
0
class NoteAdmin(ModelAdmin):
	columns = ('message', 'created',)


class Person(db.Model):
	name = CharField(max_length=50)
	surname = CharField(max_length=50)
	created = DateTimeField(default=datetime.datetime.now)

class PersonAdmin(ModelAdmin):
	columns = ('name','surname','created',)


auth = Auth(app, db)

admin = Admin(app, auth)
admin.register(Note, NoteAdmin)
admin.register(Person, PersonAdmin)
admin.setup()

api = RestAPI(app)
api.register(Note)
api.setup()

if __name__ == '__main__':
	auth.User.create_table(fail_silently=True)
	Note.create_table(fail_silently=True)
	Person.create_table(fail_silently=True)

	app.run()
Beispiel #2
0
            if request.form.get('message'):
                Note.create(
                    user=auth.get_logged_in_user(),
                    message=request.form['message'],
                )
        next = request.form.get('next') or self.dashboard_url()
        return redirect(next)
    
    def get_context(self):
        return {
            'note_list': Note.select().order_by(('created_date', 'desc')).paginate(1, 3)
        }


auth = Auth(app, db, user_model=User)
admin = Admin(app, auth)


class MessageAdmin(ModelAdmin):
    columns = ('user', 'content', 'pub_date',)

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


auth.register_admin(admin)
admin.register(Message, MessageAdmin)
admin.register(Note, NoteAdmin)
admin.register_panel('Notes', NotePanel)

Beispiel #3
0
        }

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.filter(join_date__gt=last_week).count()
        messages_this_week = Message.filter(pub_date__gt=last_week).count()
        return {
            'signups': signups_this_week,
            'messages': messages_this_week,
        }


admin = Admin(app, auth)


class MessageAdmin(ModelAdmin):
    columns = ('user', 'content', 'pub_date',)

class NoteAdmin(ModelAdmin):
    columns = ('user', 'message', '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)