def __init__(self, controller):

        defaults = dict(
            query_factory=default_query_factory,
            create_factory=default_create_factory,
            title=inflector.titleize(controller.proper_name),
            plural=inflector.underscore(controller.name),
            singular=inflector.underscore(
                inflector.singularize(controller.name)),
            ModelForm=model_form(controller.meta.Model),
            display_properties=sorted([
                name for name, property in
                controller.meta.Model._properties.items()
            ]),
            redirect=controller.uri(action='list') if controller.uri_exists(
                action='list') else None,
            form_action=None,
            form_encoding='application/x-www-form-urlencoded',
            flash_messages=True,
            layouts={
                None: 'layouts/default.html',
                'admin': 'layouts/admin.html'
            })

        for k, v in defaults.iteritems():
            if not hasattr(self, k):
                setattr(self, k, v)
Esempio n. 2
0
    def add_properties(s, cls):
        if not s.Mixin in cls.__bases__:
            cls.__bases__ += (s.Mixin, )

        if not hasattr(cls, 'Model'):
            import_form_base = '.'.join(cls.__module__.split('.')[:-2])
            # Attempt to import the model automatically
            model_name = inflector.singularize(cls.__name__)
            try:
                module = __import__(
                    '%s.models.%s' %
                    (import_form_base, inflector.underscore(model_name)),
                    fromlist=['*'])
                setattr(cls, 'Model', getattr(module, model_name))
            except (ImportError, AttributeError):
                raise RuntimeError(
                    "Scaffold coudn't automatically determine a model class for handler %s, please assign it a Model class variable."
                    % cls.__name__)

        if cls.ModelForm == None:
            cls.ModelForm = model_form(cls.Model)

        # self.scaffold.method
        methods = inspect.getmembers(s.Handler, predicate=inspect.ismethod)
        for n, f in methods:
            cls.scaffold[n] = f.__func__
Esempio n. 3
0
    def edit(self, key):
        """
        Non-admin user can only edit questions created by himself/herself.
        """
        question = self.util.decode_key(key).get()

        if question.created_by != self.user:
            return 403

        QuestionForm = model_form(self.meta.Model, exclude=("votes", "views", ))
        self.scaffold.ModelForm = QuestionForm 
        return scaffold.edit(self, key) 
Esempio n. 4
0
    def __init__(self, controller):

        defaults = dict(
            title=inflector.titleize(controller.proper_name),
            plural=inflector.underscore(controller.name),
            singular=inflector.underscore(inflector.singularize(controller.name)),
            ModelForm=model_form(controller.meta.Model),
            display_properties=[name for name, property in controller.meta.Model._properties.items()],
            redirect=controller.uri(action="list") if controller.uri_exists(action="list") else None,
            form_action=None,
            form_encoding="application/x-www-form-urlencoded",
            flash_messages=True,
        )

        for k, v in defaults.iteritems():
            if not hasattr(self, k):
                setattr(self, k, v)
Esempio n. 5
0
    def __init__(self, controller):

        defaults = dict(
            query_factory=default_query_factory,
            create_factory=default_create_factory,
            title=inflector.titleize(controller.proper_name),
            plural=inflector.underscore(controller.name),
            singular=inflector.underscore(inflector.singularize(controller.name)),
            ModelForm=model_form(controller.meta.Model),
            display_properties=sorted([name for name, property in controller.meta.Model._properties.items()]),
            redirect=controller.uri(action="list") if controller.uri_exists(action="list") else None,
            form_action=None,
            form_encoding="application/x-www-form-urlencoded",
            flash_messages=True,
            layouts={None: "layouts/default.html", "admin": "layouts/admin.html"},
        )

        for k, v in defaults.iteritems():
            if not hasattr(self, k):
                setattr(self, k, v)
Esempio n. 6
0
    def add_properties(s, cls):
        if not s.Mixin in cls.__bases__:
            cls.__bases__ += (s.Mixin,)

        if not hasattr(cls, 'Model'):
            import_form_base = '.'.join(cls.__module__.split('.')[:-2])
            # Attempt to import the model automatically
            model_name = inflector.singularize(cls.__name__)
            try:
                module = __import__('%s.models.%s' % (import_form_base, inflector.underscore(model_name)), fromlist=['*'])
                setattr(cls, 'Model', getattr(module, model_name))
            except (ImportError, AttributeError):
                raise RuntimeError("Scaffold coudn't automatically determine a model class for handler %s, please assign it a Model class variable." % cls.__name__)

        if cls.ModelForm == None:
            cls.ModelForm = model_form(cls.Model)

        # self.scaffold.method
        methods = inspect.getmembers(s.Handler, predicate=inspect.ismethod)
        for n, f in methods:
            cls.scaffold[n] = f.__func__
Esempio n. 7
0
    def __init__(self, controller):

        defaults = dict(
            title=inflector.titleize(controller.proper_name),
            plural=inflector.underscore(controller.name),
            singular=inflector.underscore(
                inflector.singularize(controller.name)),
            ModelForm=model_form(controller.meta.Model),
            display_properties=[
                name for name, property in
                controller.meta.Model._properties.items()
            ],
            redirect=controller.uri(action='list') if controller.uri_exists(
                action='list') else None,
            form_action=None,
            form_encoding='application/x-www-form-urlencoded',
            flash_messages=True)

        for k, v in defaults.iteritems():
            if not hasattr(self, k):
                setattr(self, k, v)
Esempio n. 8
0
 class Scaffold:
     """ global configuration """
     # properties of model to show to user when controlling model
     # [!] if only property to show, add comma at the end. e.g.: =("title",)
     display_properties = ("title", "content", "created_by", "votes", "views")
     ModelForm = model_form(Question, exclude=("votes", "views"))