Exemple #1
0
    def admin_edit(self, key, *args):
        target = self.util.decode_key(key).get()
        target_level = target.level
        if self.administrator_level < target_level:
            return self.abort(403)

        def scaffold_before_validate(**kwargs):
            parser = kwargs["parser"]
            change_level = self.params.get_integer("level")
            def validate():
                if self.administrator_level < target_level:
                    parser.errors["level"] = u"您的權限等級 (%s) 低於目標值 (%s),您無法設置比您高等級的角色" % (self.administrator_level, target_level)
                    return False
                if self.administrator_level < change_level:
                    parser.errors["level"] = u"您的權限等級 (%s) 低於設定值 (%s),您無法設置比您高等級的值" % (self.administrator_level, change_level)
                    return False
                if change_level > 1000 < self.administrator_level and target_level != 9999:
                    parser.errors["level"] = u"權限等級最高為 999"
                    return False
                if target_level == 9999 and change_level != 9999:
                    parser.errors["level"] = u"此權限等級無法變更"
                    return False
                return parser.container.validate() if parser.container else False
            parser.validate = validate

        self.events.scaffold_before_validate += scaffold_before_validate
        return scaffold.edit(self, key)
Exemple #2
0
    def admin_edit(self, key, *args):
        def reload_settings(**kwargs):
            item = kwargs["item"]
            memcache_key = "setting." + self.namespace + "." + item.setting_key
            memcache.set(key=memcache_key, value=item.setting_value, time=10)
            self.components.flash_messages(
                u'設定已被儲存,不過,有些應用程實例可能正在執行中,您可能無法立即查看到變動後的設定。', 'warning')

        self.events.scaffold_after_save += reload_settings
        return scaffold.edit(self, key)
Exemple #3
0
    def admin_edit(self, key):
        def scaffold_after_apply(**kwargs):
            item = kwargs["item"]
            if item.name is u"" or item.name is None:
                import random
                item.name = '-'.join(
                    str(random.randint(1000, 9999)) for i in range(4))
                item.put()

        self.events.scaffold_after_apply += scaffold_after_apply
        return scaffold.edit(self, key)
    def admin_profile(self):
        target = self.administrator
        target_level = target.role.get().level
        if self.administrator_level < target_level:
            return self.abort(403)

        def scaffold_before_validate(**kwargs):
            parser = kwargs["parser"]
            change_level = parser.data["role"].get().level

            def validate():
                if self.administrator_level < change_level:
                    parser.errors["role"] = u"您的權限等級低於此角色"
                    return False
                return parser.container.validate(
                ) if parser.container else False

            parser.validate = validate

        self.events.scaffold_before_validate += scaffold_before_validate
        return scaffold.edit(self, self.administrator.key)
Exemple #5
0
 def admin_view(self, key):
     namespace_manager.set_namespace("shared.theme")
     self.context["item"] = self.util.decode_key(key).get()
     return scaffold.edit(self, key)