Commit 6eee7ddb authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[doc] replace tabs with spaces (and make linter happy)

parent ec05a333f02c
...@@ -466,7 +466,7 @@ simplify greatly complex security definition and upgrade. ...@@ -466,7 +466,7 @@ simplify greatly complex security definition and upgrade.
__permissions__ = {'read': ('managers', 'users'), __permissions__ = {'read': ('managers', 'users'),
'add': ('managers', RRQLExpression('U has_update_permission S')), 'add': ('managers', RRQLExpression('U has_update_permission S')),
'delete': ('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 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. the `update` permission on the subject of the relation.
......
...@@ -35,11 +35,11 @@ into `mycube/hooks.py`. If this file were to grow too much, we can easily have a ...@@ -35,11 +35,11 @@ into `mycube/hooks.py`. If this file were to grow too much, we can easily have a
events = ('before_add_entity', 'before_update_entity') events = ('before_add_entity', 'before_update_entity')
def __call__(self): def __call__(self):
if 'age' in self.entity.cw_edited: if 'age' in self.entity.cw_edited:
if 0 <= self.entity.age <= 120: if 0 <= self.entity.age <= 120:
return return
msg = self._cw._('age must be between 0 and 120') msg = self._cw._('age must be between 0 and 120')
raise ValidationError(self.entity.eid, {'age': msg}) raise ValidationError(self.entity.eid, {'age': msg})
In our example the base `__select__` is augmented with an `is_instance` selector In our example the base `__select__` is augmented with an `is_instance` selector
matching the desired entity type. matching the desired entity type.
......
...@@ -300,18 +300,18 @@ Here is a quick example: ...@@ -300,18 +300,18 @@ Here is a quick example:
.. sourcecode:: python .. sourcecode:: python
class UserLink(component.Component): class UserLink(component.Component):
'''if the user is the anonymous user, build a link to login else a link '''if the user is the anonymous user, build a link to login else a link
to the connected user object with a logout link to the connected user object with a logout link
''' '''
__regid__ = 'loggeduserlink' __regid__ = 'loggeduserlink'
def call(self): def call(self):
if self._cw.session.anonymous_session: if self._cw.session.anonymous_session:
# display login link # display login link
... ...
else: else:
# display a link to the connected user object with a loggout link # 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 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 classes sharing the same identifier but with different selectors so you'll get
...@@ -320,21 +320,21 @@ the correct one according to the context. ...@@ -320,21 +320,21 @@ the correct one according to the context.
.. sourcecode:: python .. sourcecode:: python
class UserLink(component.Component): class UserLink(component.Component):
'''display a link to the connected user object with a loggout link''' '''display a link to the connected user object with a loggout link'''
__regid__ = 'loggeduserlink' __regid__ = 'loggeduserlink'
__select__ = component.Component.__select__ & authenticated_user() __select__ = component.Component.__select__ & authenticated_user()
def call(self): def call(self):
# display useractions and siteactions # display useractions and siteactions
... ...
class AnonUserLink(component.Component): class AnonUserLink(component.Component):
'''build a link to login''' '''build a link to login'''
__regid__ = 'loggeduserlink' __regid__ = 'loggeduserlink'
__select__ = component.Component.__select__ & anonymous_user() __select__ = component.Component.__select__ & anonymous_user()
def call(self): def call(self):
# display login link # display login link
... ...
The big advantage, aside readability once you're familiar with the The big advantage, aside readability once you're familiar with the
......
...@@ -56,42 +56,42 @@ Here is the source code: ...@@ -56,42 +56,42 @@ Here is the source code:
.. sourcecode:: python .. sourcecode:: python
def sender_value(form, field): 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): def recipient_choices(form, field):
return [(e.get_email(), e.eid) return [(e.get_email(), e.eid)
for e in form.cw_rset.entities() for e in form.cw_rset.entities()
if e.get_email()] if e.get_email()]
def recipient_value(form, field): 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()] if e.get_email()]
class MassMailingForm(forms.FieldsForm): class MassMailingForm(forms.FieldsForm):
__regid__ = 'massmailing' __regid__ = 'massmailing'
needs_js = ('cubicweb.widgets.js',) needs_js = ('cubicweb.widgets.js',)
domid = 'sendmail' domid = 'sendmail'
action = 'sendmail' action = 'sendmail'
sender = ff.StringField(widget=TextInput({'disabled': 'disabled'}), sender = ff.StringField(widget=TextInput({'disabled': 'disabled'}),
label=_('From:'), label=_('From:'),
value=sender_value) value=sender_value)
recipient = ff.StringField(widget=CheckBox(), recipient = ff.StringField(widget=CheckBox(),
label=_('Recipients:'), label=_('Recipients:'),
choices=recipient_choices, choices=recipient_choices,
value=recipients_value) 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', mailbody = ff.StringField(widget=AjaxWidget(wdgtype='TemplateTextField',
inputid='mailbody')) inputid='mailbody'))
form_buttons = [ImgButton('sendbutton', "javascript: $('#sendmail').submit()", form_buttons = [ImgButton('sendbutton', "javascript: $('#sendmail').submit()",
_('send email'), 'SEND_EMAIL_ICON'), _('send email'), 'SEND_EMAIL_ICON'),
ImgButton('cancelbutton', "javascript: history.back()", ImgButton('cancelbutton', "javascript: history.back()",
stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')] stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')]
Let's detail what's going on up there. Our form will hold four fields: Let's detail what's going on up there. Our form will hold four fields:
...@@ -125,13 +125,13 @@ To see this form, we still have to wrap it in a view. This is pretty simple: ...@@ -125,13 +125,13 @@ To see this form, we still have to wrap it in a view. This is pretty simple:
.. sourcecode:: python .. sourcecode:: python
class MassMailingFormView(form.FormViewMixIn, EntityView): class MassMailingFormView(form.FormViewMixIn, EntityView):
__regid__ = 'massmailing' __regid__ = 'massmailing'
__select__ = is_instance(IEmailable) & authenticated_user() __select__ = is_instance(IEmailable) & authenticated_user()
def call(self): def call(self):
form = self._cw.vreg['forms'].select('massmailing', self._cw, form = self._cw.vreg['forms'].select('massmailing', self._cw,
rset=self.cw_rset) rset=self.cw_rset)
form.render(w=self.w) form.render(w=self.w)
As you see, we simply define a view with proper selector so it only apply to a 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 result set containing :class:`IEmailable` entities, and so that only users in the
......
...@@ -142,7 +142,7 @@ standard bookmark and refresh the UI, while keeping the UI responsive. ...@@ -142,7 +142,7 @@ standard bookmark and refresh the UI, while keeping the UI responsive.
function removeBookmark(beid) { function removeBookmark(beid) {
d = asyncRemoteExec('delete_bookmark', beid); d = asyncRemoteExec('delete_bookmark', beid);
d.addCallback(function(boxcontent) { d.addCallback(function(boxcontent) {
reloadComponent('bookmarks_box', '', 'boxes', 'bookmarks_box'); reloadComponent('bookmarks_box', '', 'boxes', 'bookmarks_box');
document.location.hash = '#header'; document.location.hash = '#header';
updateMessage(_("bookmark has been removed")); updateMessage(_("bookmark has been removed"));
}); });
......
...@@ -136,14 +136,14 @@ below somewhere in your cube's views: ...@@ -136,14 +136,14 @@ below somewhere in your cube's views:
from cubicweb.web.views import reledit from cubicweb.web.views import reledit
class DeactivatedAutoClickAndEditFormView(reledit.AutoClickAndEditFormView): class DeactivatedAutoClickAndEditFormView(reledit.AutoClickAndEditFormView):
def _should_edit_attribute(self, rschema): def _should_edit_attribute(self, rschema):
return False return False
def _should_edit_attribute(self, rschema, role): def _should_edit_attribute(self, rschema, role):
return False return False
def registration_callback(vreg): def registration_callback(vreg):
vreg.register_and_replace(DeactivatedAutoClickAndEditFormView, vreg.register_and_replace(DeactivatedAutoClickAndEditFormView,
reledit.AutoClickAndEditFormView) reledit.AutoClickAndEditFormView)
...@@ -117,25 +117,25 @@ attribute and relation. Here is the code to add to :file:`schema.py`: ...@@ -117,25 +117,25 @@ attribute and relation. Here is the code to add to :file:`schema.py`:
from cubicweb.schema import ERQLExpression from cubicweb.schema import ERQLExpression
VISIBILITY_PERMISSIONS = { VISIBILITY_PERMISSIONS = {
'read': ('managers', 'read': ('managers',
ERQLExpression('X visibility "public"'), ERQLExpression('X visibility "public"'),
ERQLExpression('X may_be_read_by U')), ERQLExpression('X may_be_read_by U')),
'add': ('managers',), 'add': ('managers',),
'update': ('managers', 'owners',), 'update': ('managers', 'owners',),
'delete': ('managers', 'owners'), 'delete': ('managers', 'owners'),
} }
AUTH_ONLY_PERMISSIONS = { AUTH_ONLY_PERMISSIONS = {
'read': ('managers', 'users'), 'read': ('managers', 'users'),
'add': ('managers',), 'add': ('managers',),
'update': ('managers', 'owners',), 'update': ('managers', 'owners',),
'delete': ('managers', 'owners'), 'delete': ('managers', 'owners'),
} }
CLASSIFIERS_PERMISSIONS = { CLASSIFIERS_PERMISSIONS = {
'read': ('managers', 'users', 'guests'), 'read': ('managers', 'users', 'guests'),
'add': ('managers',), 'add': ('managers',),
'update': ('managers', 'owners',), 'update': ('managers', 'owners',),
'delete': ('managers', 'owners'), 'delete': ('managers', 'owners'),
} }
from cubicweb_folder.schema import Folder from cubicweb_folder.schema import Folder
from cubicweb_file.schema import File from cubicweb_file.schema import File
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment