gaetk2.admin package¶
This package implemets automatic administration facilities. It aims to be a mix of the concepts of Django Admin and the Google App Engine Admin Console. It is aimed to be used not by Developers, Dev Ops or System Administrators but by the regular staff using your application - so it apptempts to give you less opportunity to shoot your self in the foot.
It also aims at giving you building blocks for your own user facing pages.
These Services provided by the Admin-Package are automatically available at /admin2/ in your URL-Tree.
With minimal configuration you can get an admin site as above. Just add a
file admin_gaetk2.py
e.g. in modules/pay/
or any other directory
within your the modules
directory:
from gaetk2.admin import site
from gaetk2.admin.layout import AdminLayout
from . import pay_models
class MyLayout(AdminLayout):
links = [
('SEPA-Dateien',
'https://console.cloud.google.com/storage/browser/foobar'),
]
site.registerlayoutclass(MyLayout)
site.registermodel(pay_models.pay_Lastschriftmandat)
site.registermodel(pay_models.pay_IPNRecord)
site.registermodel(pay_models.pay_Kontovorgang)
Files named modules/**/admin_gaetk2.py
are automatically found an
included in the Admin Site.
Adding Datastore Models to the Admin Site¶
You have to manually add all ndb models you want to have in the Admin Site
in like this to admin_gaetk2.py
:
from gaetk2.admin import site
from . import pay_models
site.registermodel(pay_models.pay_Lastschriftmandat)
gaetk2.admin.modeladmin.ModelAdmin
is the main mechanism for changing the automatically generated admin interface. You intantiate it for each model you want to have administered:
class LastschriftmandatAdmin(ModelAdmin):
list_fields = ['ist_aktiv', 'last_used',
'kundennr', 'kontoinhaber', 'iban', 'updated_at', 'created_at']
queries = {
'aktiv': pay_models.pay_Lsm.query(pay_models.pay_Lsm.ist_aktiv==True),
'nicht aktiv': pay_models.pay_Lsm.query(pay_models.pay_Lsm.ist_aktiv==False),
'alle': pay_models.pay_Lsm.query(),
}
site.registermodel(pay_models.pay_Lsm, LastschriftmandatAdmin)
Todo
- KundeForm = model_form(
- m_Kunde, exclude=[‘designator’, ‘empfaengernr’, ‘updated_at’, ‘created_at’, ‘name1’, ‘name2’], field_args={ ‘owner’: {‘default’: ‘cyberlogi’}, ‘email’: {‘validators’: [express_email_validator]}, })
Todo
- rename
application_id
to topic everywhere - reimplement search
Package contents¶
-
class
gaetk2.admin.modeladmin.
ModelAdmin
(model, admin_site, topic=None)[source]¶ Admin Model - Implements CRUD for NDB
-
read_only
= True¶ User is not allowed to do any changes to the database for this Models Entities.
-
deletable
= False¶ User is allowed to delete Entities via the admin interface.
-
list_per_page
= 50¶ Number of items per page.
-
order_field
= u'-created_at'¶ Sorting. Beware of datastore indices!
-
ordering
= u''¶ TBD Mit ‘order_field’ laesst sich die Sortierung bei der Anzeige der Model-Instanzen im Admin-Bereich anpassen. Als Default werden die Datensaetze in absteigender Reihenfolge ihrer Erzeugung sortiert, jedoch kann jede Admin-Klasse die Sortierung mit ‘order_field’ beeinflussen, indem sie ein bel. anderes Feld dort angibt.
-
post_create_hooks
= []¶ List of functions to be called with the newly created object as the sole parameter.
-
db_key_field
= None¶ Standardmaessig lassen wir die App Engine fuer das Model automatisch einen Key generieren. Es besteht jedoch in der Admin-Klasse die Moeglichkeit, via ‘db_key_field=[propertyname]’ ein Feld festzulegen, dessen Inhalt im Formular als Key beim Erzeugen der Instanz genutzt wird.
-
topic
= None¶ The Topic (Application Name in Django) under which the Model is listed in the admin GUI.
-
queries
= {}¶ TBD
-
list_fields
= ()¶ Names of fields to show in Entity listing.
If you do not want to show all the files you can give a tuple of fields to show:
list_fields = ('designator', 'name', 'plz', 'ort', 'email')
TBD: relation to fields / only.
-
detail_fields
= ()¶ TBD
-
get_queryset
(request)[source]¶ Gib das QuerySet für die Admin-Seite zurück
Es wird die gewünschte Sortierung durchgeführt.
-
change_view
(handler, object_id, extra_context=None)[source]¶ View zum Bearbeiten eines vorhandenen Objekts
-
delete_view
(handler, extra_context=None)[source]¶ Request zum Löschen von (mehreren) Objekten behandeln.
Redirectet bei Erfolg zur Objektliste. extra_context ist für die Signatur erforderlich, wird aber nicht genutzt.
-
export_view_csv
(handler, extra_context=None)[source]¶ Request zum Exportieren von allen Objekten behandeln.
extra_context ist für die Signatur erforderlich, wird aber nicht genutzt.
-
-
class
gaetk2.admin.sitemodel.
AdminSite
[source]¶ Registry for Models and other Stuff to be administered via Web GUI.
Cenceptually Our Grandparent - Django Admin - Lives in a world of “Applications” out of which your Django Installation is composed.
GAETK2 does not follow this approach very much. We assum each Model/Kind Name is unique in the whole deployed Web-Application and don’t use djangos term “application” to avoid confusion. We speak of “Topics” whose sole purpose is to organize contant in the admin interface.