# HG changeset patch # User Nicolas Chauvat # Date 1581782895 -3600 # Node ID 7347715bf0eece68b3158776bb3d65b695d26fc8 # Parent ec05a333f02cfde1809ce67f67a033c5dec60121 [doc] replace tabs with spaces (and make linter happy) diff -r ec05a333f02c -r 7347715bf0ee doc/book/devrepo/datamodel/definition.rst --- a/doc/book/devrepo/datamodel/definition.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devrepo/datamodel/definition.rst Sat Feb 15 17:08:15 2020 +0100 @@ -466,7 +466,7 @@ __permissions__ = {'read': ('managers', 'users'), 'add': ('managers', RRQLExpression('U has_update_permission S')), 'delete': ('managers', RRQLExpression('U has_update_permission S')) - } + } In the above example, user will be allowed to add/delete `my_relation` if he has the `update` permission on the subject of the relation. diff -r ec05a333f02c -r 7347715bf0ee doc/book/devrepo/repo/hooks.rst --- a/doc/book/devrepo/repo/hooks.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devrepo/repo/hooks.rst Sat Feb 15 17:08:15 2020 +0100 @@ -35,11 +35,11 @@ events = ('before_add_entity', 'before_update_entity') def __call__(self): - if 'age' in self.entity.cw_edited: + if 'age' in self.entity.cw_edited: if 0 <= self.entity.age <= 120: return - msg = self._cw._('age must be between 0 and 120') - raise ValidationError(self.entity.eid, {'age': msg}) + msg = self._cw._('age must be between 0 and 120') + raise ValidationError(self.entity.eid, {'age': msg}) In our example the base `__select__` is augmented with an `is_instance` selector matching the desired entity type. diff -r ec05a333f02c -r 7347715bf0ee doc/book/devrepo/vreg.rst --- a/doc/book/devrepo/vreg.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devrepo/vreg.rst Sat Feb 15 17:08:15 2020 +0100 @@ -300,18 +300,18 @@ .. sourcecode:: python class UserLink(component.Component): - '''if the user is the anonymous user, build a link to login else a link - to the connected user object with a logout link - ''' - __regid__ = 'loggeduserlink' + '''if the user is the anonymous user, build a link to login else a link + to the connected user object with a logout link + ''' + __regid__ = 'loggeduserlink' - def call(self): - if self._cw.session.anonymous_session: - # display login link - ... - else: - # display a link to the connected user object with a loggout link - ... + def call(self): + if self._cw.session.anonymous_session: + # display login link + ... + else: + # display a link to the connected user object with a loggout link + ... The proper way to implement this with |cubicweb| is two have two different classes sharing the same identifier but with different selectors so you'll get @@ -320,21 +320,21 @@ .. sourcecode:: python class UserLink(component.Component): - '''display a link to the connected user object with a loggout link''' - __regid__ = 'loggeduserlink' - __select__ = component.Component.__select__ & authenticated_user() + '''display a link to the connected user object with a loggout link''' + __regid__ = 'loggeduserlink' + __select__ = component.Component.__select__ & authenticated_user() - def call(self): + def call(self): # display useractions and siteactions - ... + ... class AnonUserLink(component.Component): - '''build a link to login''' - __regid__ = 'loggeduserlink' - __select__ = component.Component.__select__ & anonymous_user() + '''build a link to login''' + __regid__ = 'loggeduserlink' + __select__ = component.Component.__select__ & anonymous_user() - def call(self): - # display login link + def call(self): + # display login link ... The big advantage, aside readability once you're familiar with the diff -r ec05a333f02c -r 7347715bf0ee doc/book/devweb/edition/examples.rst --- a/doc/book/devweb/edition/examples.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devweb/edition/examples.rst Sat Feb 15 17:08:15 2020 +0100 @@ -56,42 +56,42 @@ .. sourcecode:: python def sender_value(form, field): - return '%s <%s>' % (form._cw.user.dc_title(), form._cw.user.get_email()) + return '%s <%s>' % (form._cw.user.dc_title(), form._cw.user.get_email()) def recipient_choices(form, field): - return [(e.get_email(), e.eid) + return [(e.get_email(), e.eid) for e in form.cw_rset.entities() - if e.get_email()] + if e.get_email()] def recipient_value(form, field): - return [e.eid for e in form.cw_rset.entities() + return [e.eid for e in form.cw_rset.entities() if e.get_email()] class MassMailingForm(forms.FieldsForm): - __regid__ = 'massmailing' + __regid__ = 'massmailing' - needs_js = ('cubicweb.widgets.js',) - domid = 'sendmail' - action = 'sendmail' + needs_js = ('cubicweb.widgets.js',) + domid = 'sendmail' + action = 'sendmail' - sender = ff.StringField(widget=TextInput({'disabled': 'disabled'}), - label=_('From:'), - value=sender_value) + sender = ff.StringField(widget=TextInput({'disabled': 'disabled'}), + label=_('From:'), + value=sender_value) - recipient = ff.StringField(widget=CheckBox(), - label=_('Recipients:'), - choices=recipient_choices, - value=recipients_value) + recipient = ff.StringField(widget=CheckBox(), + label=_('Recipients:'), + choices=recipient_choices, + value=recipients_value) - subject = ff.StringField(label=_('Subject:'), max_length=256) + subject = ff.StringField(label=_('Subject:'), max_length=256) - mailbody = ff.StringField(widget=AjaxWidget(wdgtype='TemplateTextField', - inputid='mailbody')) + mailbody = ff.StringField(widget=AjaxWidget(wdgtype='TemplateTextField', + inputid='mailbody')) - form_buttons = [ImgButton('sendbutton', "javascript: $('#sendmail').submit()", - _('send email'), 'SEND_EMAIL_ICON'), - ImgButton('cancelbutton', "javascript: history.back()", - stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')] + form_buttons = [ImgButton('sendbutton', "javascript: $('#sendmail').submit()", + _('send email'), 'SEND_EMAIL_ICON'), + ImgButton('cancelbutton', "javascript: history.back()", + stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')] Let's detail what's going on up there. Our form will hold four fields: @@ -125,13 +125,13 @@ .. sourcecode:: python class MassMailingFormView(form.FormViewMixIn, EntityView): - __regid__ = 'massmailing' - __select__ = is_instance(IEmailable) & authenticated_user() + __regid__ = 'massmailing' + __select__ = is_instance(IEmailable) & authenticated_user() - def call(self): - form = self._cw.vreg['forms'].select('massmailing', self._cw, - rset=self.cw_rset) - form.render(w=self.w) + def call(self): + form = self._cw.vreg['forms'].select('massmailing', self._cw, + rset=self.cw_rset) + form.render(w=self.w) As you see, we simply define a view with proper selector so it only apply to a result set containing :class:`IEmailable` entities, and so that only users in the diff -r ec05a333f02c -r 7347715bf0ee doc/book/devweb/js.rst --- a/doc/book/devweb/js.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devweb/js.rst Sat Feb 15 17:08:15 2020 +0100 @@ -142,7 +142,7 @@ function removeBookmark(beid) { d = asyncRemoteExec('delete_bookmark', beid); d.addCallback(function(boxcontent) { - reloadComponent('bookmarks_box', '', 'boxes', 'bookmarks_box'); + reloadComponent('bookmarks_box', '', 'boxes', 'bookmarks_box'); document.location.hash = '#header'; updateMessage(_("bookmark has been removed")); }); diff -r ec05a333f02c -r 7347715bf0ee doc/book/devweb/views/reledit.rst --- a/doc/book/devweb/views/reledit.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/book/devweb/views/reledit.rst Sat Feb 15 17:08:15 2020 +0100 @@ -136,14 +136,14 @@ from cubicweb.web.views import reledit class DeactivatedAutoClickAndEditFormView(reledit.AutoClickAndEditFormView): - def _should_edit_attribute(self, rschema): - return False + def _should_edit_attribute(self, rschema): + return False - def _should_edit_attribute(self, rschema, role): - return False + def _should_edit_attribute(self, rschema, role): + return False def registration_callback(vreg): - vreg.register_and_replace(DeactivatedAutoClickAndEditFormView, - reledit.AutoClickAndEditFormView) + vreg.register_and_replace(DeactivatedAutoClickAndEditFormView, + reledit.AutoClickAndEditFormView) diff -r ec05a333f02c -r 7347715bf0ee doc/tutorials/advanced/part02_security.rst --- a/doc/tutorials/advanced/part02_security.rst Sat Feb 08 22:20:45 2020 +0100 +++ b/doc/tutorials/advanced/part02_security.rst Sat Feb 15 17:08:15 2020 +0100 @@ -117,25 +117,25 @@ from cubicweb.schema import ERQLExpression VISIBILITY_PERMISSIONS = { - 'read': ('managers', - ERQLExpression('X visibility "public"'), - ERQLExpression('X may_be_read_by U')), - 'add': ('managers',), - 'update': ('managers', 'owners',), - 'delete': ('managers', 'owners'), - } + 'read': ('managers', + ERQLExpression('X visibility "public"'), + ERQLExpression('X may_be_read_by U')), + 'add': ('managers',), + 'update': ('managers', 'owners',), + 'delete': ('managers', 'owners'), + } AUTH_ONLY_PERMISSIONS = { - 'read': ('managers', 'users'), - 'add': ('managers',), - 'update': ('managers', 'owners',), - 'delete': ('managers', 'owners'), - } + 'read': ('managers', 'users'), + 'add': ('managers',), + 'update': ('managers', 'owners',), + 'delete': ('managers', 'owners'), + } CLASSIFIERS_PERMISSIONS = { - 'read': ('managers', 'users', 'guests'), - 'add': ('managers',), - 'update': ('managers', 'owners',), - 'delete': ('managers', 'owners'), - } + 'read': ('managers', 'users', 'guests'), + 'add': ('managers',), + 'update': ('managers', 'owners',), + 'delete': ('managers', 'owners'), + } from cubicweb_folder.schema import Folder from cubicweb_file.schema import File