Ejemplo n.º 1
0
def get_current_user(controller):
    """
    A function to obtain current login user.
    """
    from aha import Config
    config = Config()
    authobj = config.auth_obj()
    user = authobj.get_user(controller)
    return user
Ejemplo n.º 2
0
    def make_form(self, controller):
        """
        A method to make form.
        """
        config = Config()
        authobj = config.auth_obj()
        user = authobj.get_user(controller)
        form = None
        if controller.content.blog_object().auth_comment and not user:
            form = controller.get_form('comment_add_auth', controller)
        if form == None:
            form = controller.get_form('comment_add', controller)

        form.action = controller.content.get_path()+'/postcomment'
        return form
Ejemplo n.º 3
0
    def do_validate(self, state, controller):
        """
        A validator method for edit transition
        """
        from aha import Config
        config = Config()
        authobj = config.auth_obj()
        user = authobj.get_user(controller)

        if controller.content.blog_object().auth_comment:
            # require authentication
            # when blog.auth_comment = True
            if not user:
                controller.session['referer'] = \
                config.site_root+controller.content.get_path()+'/postcomment'
                controller.session.put()
                authobj.auth_redirect(controller)

        if controller.content.blog_object().auth_comment and user:
            from aha.widget.field import HiddenField
            controller.form['author_name'].args.update(readonly = 'readonly')
            controller.form['author_name'].default = user.get('nickname', '')
            del controller.form['email']
            del controller.form['url']
            controller.form['url'] = \
                    HiddenField(name = 'url', default = user.get('icon_url', ''))

        state = FC.INITIAL
        controller.blog = controller.content.blog_object()
        if controller.request.POST and \
            ('author_name' in controller.request.POST or
             'author_name2' in controller.request.POST):
            if not controller.request.POST:
                return FC.INITIAL
            e = controller.form.validate(dict([(x, controller.request.get(x))
                                    for x in controller.request.arguments()]))
            if e:
                # Some error occured
                return FC.FAILURE
            else:
                return FC.SUCCESS

        return FC.INITIAL
Ejemplo n.º 4
0
 def add_new_object(cls, v, ins):
     """
     A method to obtain new object
     """
     from aha import Config
     config = Config()
     f = ins.request.body_file.vars["body"]
     v['content_type'] = guess_type(f.filename)[0]
     v['filename'] = f.filename
     if not v.get('name', None):
         v['name'] = v['filename']
     if not v.get('title', None):
         v['title'] = v['name']
     cu = config.auth_obj().get_user(ins)
     v['creator'] = cu.get('nickname', '') or cu.get('email', '')
     d = {}
     [d.update({str(k): v[k]}) for k in v]
     o = cls.MODEL(**d)
     o.put()
     return o
Ejemplo n.º 5
0
 def add_new_object(cls, v, ins):
     """
     A method to obtain new object
     """
     from aha import Config
     config = Config()
     f = ins.request.body_file.vars["body"]
     v['content_type'] = detect_imagetype(v['body'])
     i = images.Image(v['body'])
     v['width'], v['height'] = i.width, i.height
     v['filename'] = f.filename
     if not v.get('name', None):
         v['name'] = v['filename']
     if not v.get('title', None):
         v['title'] = v['name']
     cu = config.auth_obj().get_user(ins)
     v['creator'] = cu.get('nickname', '') or cu.get('nickname', '')
     d = {}
     [d.update({str(k): v[k]}) for k in v]
     o = cls.MODEL(**d)
     o.put()
     return o