def prepare(_next, self):
        """Hook after prepare and set 'portrait' as image widget to
        ``self.form``.
        """
        _next(self)
        if not self.portrait_support:
            return
        model = self.model
        request = self.request
        if request.has_permission('edit_user', model.parent):
            mode = 'edit'
        else:
            mode = 'display'
        cfg = ugm_general(model)
        image_attr = cfg.attrs['users_portrait_attr']
        image_accept = cfg.attrs['users_portrait_accept']
        image_width = int(cfg.attrs['users_portrait_width'])
        image_height = int(cfg.attrs['users_portrait_height'])
        image_data = model.attrs.get(image_attr)
        if image_data:
            image_value = {
                'file': BytesIO(image_data),
                'mimetype': 'image/jpeg',
            }
            image_url = make_url(request, node=model,
                                 resource='portrait_image')
        else:
            image_value = UNSET
            resource = 'cone.ugm.static/images/default_portrait.jpg'
            image_url = make_url(request, node=model.root, resource=resource)
        portrait_widget = factory(
            'field:label:error:image',
            name='portrait',
            value=image_value,
            props={
                'label': _('portrait', default='Portrait'),
                'src': image_url,
                'alt': _('portrait', default='Portrait'),
                'accept': image_accept,
                'minsize': (image_width, image_height),
                'crop': {
                    'size': (image_width, image_height),
                    'fitting': True,
                }
            },
            mode=mode)
        save_widget = self.form['save']
        self.form.insertbefore(portrait_widget, save_widget)
def prepare ( _next , self ) : _next ( self ) if not self . portrait_support : return model = self . model request = self . request if request . has_permission ( 'edit_user' , model . parent ) : mode = 'edit' else : mode = 'display' cfg = ugm_general ( model ) image_attr = cfg . attrs [ 'users_portrait_attr' ] image_accept = cfg . attrs [ 'users_portrait_accept' ] image_width = int ( cfg . attrs [ 'users_portrait_width' ] ) image_height = int ( cfg . attrs [ 'users_portrait_height' ] ) image_data = model . attrs . get ( image_attr ) if image_data : image_value = { 'file' : BytesIO ( image_data ) , 'mimetype' : 'image/jpeg' , } image_url = make_url ( request , node = model , resource = 'portrait_image' ) else : image_value = UNSET resource = 'cone.ugm.static/images/default_portrait.jpg' image_url = make_url ( request , node = model . root , resource = resource ) portrait_widget = factory ( 'field:label:error:image' , name = 'portrait' , value = image_value , props = { 'label' : _ ( 'portrait' , default = 'Portrait' ) , 'src' : image_url , 'alt' : _ ( 'portrait' , default = 'Portrait' ) , 'accept' : image_accept , 'minsize' : ( image_width , image_height ) , 'crop' : { 'size' : ( image_width , image_height ) , 'fitting' : True , } } , mode = mode ) save_widget = self . form [ 'save' ] self . form . insertbefore ( portrait_widget , save_widget )
Hook after prepare and set 'portrait' as image widget to
        ``self.form``.