コード例 #1
0
ファイル: views.py プロジェクト: mdornseif/appengine-toolkit
    def dispatch(self):
        """Handler, der die richtige Methode für die Aktion aufruft"""

        args = self.request.route_args
        application, model, action_or_objectid = args

        model_class = site.get_model_class(application, model)
        if not model_class:
            raise gaetk.handler.HTTP404_NotFound('No model %s' % ('%s.%s' % (application, model)))
        admin_class = site.get_admin_class(model_class)

        logging.info("%s %s", action_or_objectid, self.request.route_args)
        # Bestimme Route! Da könnte man dann auch einen Handler mit angeben.
        # Das muss irgendwie besser gehen als Keys und Actions zu mischen.
        if action_or_objectid == 'add':
            if admin_class.read_only:
                raise gaetk.handler.HTTP403_Forbidden
            admin_class.add_view(self)
        elif action_or_objectid == 'export_xls':
            admin_class.export_view_xls(self)
        elif action_or_objectid == 'export_csv':
            admin_class.export_view_csv(self)
        elif action_or_objectid == 'delete':
            if admin_class.read_only:
                raise gaetk.handler.HTTP403_Forbidden
            elif not admin_class.deletable:
                self.add_message('danger', u"I'm sorry Dave, I'm afraid I can't do that")
                raise gaetk.handler.HTTP302_Found(location=self.request.referer)
            else:
                admin_class.delete_view(self)
        else:
            if admin_class.read_only:
                raise gaetk.handler.HTTP403_Forbidden
            admin_class.change_view(self, action_or_objectid,
                                    extra_context=dict(app=application, model=model))
コード例 #2
0
ファイル: views.py プロジェクト: mdornseif/appengine-toolkit
    def get(self, application, model):
        """Rendert eine Liste aller registrierten Modells."""

        model_class = site.get_model_class(application, model)
        if not model_class:
            raise gaetk.handler.HTTP404_NotFound('No model %s' % ('%s.%s' % (application, model)))
        admin_class = site.get_admin_class(model_class)

        # unsupported: Link-Fields (oder wie das heißt)
        # unsupported: callables in List_fields
        query = admin_class.get_queryset(self.request)
        template_values = self.paginate(
            query, defaultcount=admin_class.list_per_page, datanodename='object_list', calctotal=False)
        template_values.update(
            admin_class=admin_class,
            app=application,
            model=model,
            model_class=model_class)

        self.render(template_values, 'admin/list.html')