archetype.schemaextender and Grok adapters - plone

How it is possible to register archetypes.schemaextenders with five.grok.
The attempt:
class QuickNavExtender(grok.Adapter):
"""
Define schema fiddler which injects a new field to every item.
"""
# This field comes on every AT content item
grok.adapts(ISchemaExtender)
grok.provider(ISchemaExtender)
grok.context(IBaseContent)
#adapts(IBaseContent)
implements(ISchemaExtender)
fields = [
ExtensionBooleanField("quicknav",
widget = atapi.BooleanWidget(
label="Quick jump navigation",
description="Allow in-page jumping by navigation links"
),
# On which edit tab this field appears
schemata = "settings"
)
]
... is not being picked up.
But if you add this ZCML snippet and fall back Zope 3 style registration it works:
<adapter factory=".extender.QuickNavExtender"
provides="archetypes.schemaextender.interfaces.ISchemaExtender" />

I think you want:
class QuickNavExtender(grok.Adapter):
grok.context(IBaseContent)
grok.implements(ISchemaExtender)
# fields here...

Related

alfresco search results : -> add parameter to search item url

I wanted to change the url of search result,
I found that this is an aikau page ,
The faceted-search page returns multiple results ,
If we click on search result item which is document then it's redirects us to document-details page ,
as shown in image the url /share/page/site/swsdp/document-details?nodeRef=workspace://SpacesStore/5fa74ad3-9b5b-461b-9df5-de407f1f4fe7 i wanted to add one parameter here
like this /share/page/site/swsdp/document-details?nodeRef=workspace://SpacesStore/5fa74ad3-9b5b-461b-9df5-de407f1f4fe7&searchTerm=web is there any way to add this parameter,
please help.
searchTerm=web
I have overrided aikau widget FCTSRCH_SEARCH_RESULT with my custom widget files by
var searchResultWidget = widgetUtils.findObject(model.jsonModel.widgets, "id", "FCTSRCH_SEARCH_RESULT");
if(searchResultWidget) {
searchResultWidget.name = "custom/alfresco/search/AlfSearchResult";
}
So my widget FCTSRCH_SEARCH_RESULT will be like this
{
id: "FCTSRCH_SEARCH_RESULT",
name: "custom/alfresco/search/AlfSearchResult",
config: {
enableContextMenu: false
}
}
and able to call my custom widget js file and changed the url.

How to add additional classes to django form field

I've just recently learned about:
Form.error_css_class
Form.required_css_class
Docs: https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.error_css_class
So by defining 'error_css_class' and 'required_css_class' in forms
class MyForm(forms.Form):
error_css_class = 'error'
required_css_class = 'required'
name = forms.CharField(...)
I can do:
<div class="field-wrapper {{ form.name.css_classes }}">
...
</div>
This will output:
<div class="field-wrapper required">
...
</div>
However I want to add additional classes to the field, e.g I would like to add 'text name' css class for the "name" field. And reading the docs, I think its possible.
https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.BoundField.css_classes
After reading the above I tried to do
self.fields['name'].css_classes('name text')
That doesn't work. I get
'CharField' object has no attribute 'css_classes'
I also tried
name = forms.CharField(css_classes='name text')
TypeError
__init__() got an unexpected keyword argument 'css_classes'
I know I can add extra attr to field widget
self.fields['name'].widget.attrs['class'] = 'name text'
But I want to add css classes to field wrapper.
I could write a custom templatetag... to check field name/type and return appropriate css classes... but if there is something builtin .. I would love to keep my templates clean :-).
Also hardcoding css classes per field is not an option .. as the form fields are dynamic.
Any help will be appreciated.
I figured out how to do it using a custom BoundField
from django.forms import forms
class CustomBoundField(forms.BoundField):
def css_classes(self, extra_classes=None):
# logic for determining css_classes has been omitted
extra_classes = ['name', 'text']
return super(CustomBoundField, self).css_classes(extra_classes=extra_classes)
In my forms, I overide getitem
def __getitem__(self, name):
try:
field = self.fields[name]
except KeyError:
raise KeyError('Key %r not found in Form' % name)
return CustomBoundField(self, field, name)

z3c.form and Plone - add custom css file to a form without using a custom template

In a project I'm working on we've defined a simple z3c.form, it looks like this.
class IImportCandidateForm(Interface):
csv_file = NamedFile(title=_(u'CSV file'))
class ImportForm(form.Form):
fields = field.Fields(IImportForm)
ignoreContext = True
def updateWidget(self):
super(ImportForm, self).updateWidget()
... snip ...
#button.buttonAndHandler(u'Import')
def handleImport(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorMessage
return
file = data["csv_file"].data
Is there a way to associate a custom css file with this form without first wrapping it in a custom page template with the form?
No, there isn't. Unless you use a form wrapper, the form's template renders only the form and not the entire page.
In you are using this form in a custom view, you have a class style added to the body class (something like template-yourviewname). So you can add you CSS rules to a main CSS resource, loaded in every page, but prefix every rule with .template-yourviewname.

Disable "Advanced ..." in workflow status menu in Plone

I want to disable the "Advanced ..." (content_status_history) link in the workflow status menu for other roles except Managers and Site Administrators. Is there a permission that I can use to do this? Or is this link's permission coupled with the presence of a transition?
The link's presence is coupled to there being a workflow transition. The form it links to offers additional options to set for the transitions that are available on the current object. There is no permission that controls it's presence; the menu item is hardcoded.
From the plone.app.contentmenu.menu source:
if len(results) > 0:
results.append({ 'title' : _(u'label_advanced', default=u'Advanced...'),
'description' : '',
'action' : url + '/content_status_history',
'selected' : False,
'icon' : None,
'extra' : {'id': 'advanced', 'separator': 'actionSeparator', 'class': 'kssIgnore'},
'submenu' : None,
})
To provide your own implementation (perhaps using a subclass that removes the last option again if certain conditions are met), you'd have to use an override to redefine the browser:menu registration.
In your overrides.zcml you'd have to point to your own implementation using the following browser:menu declaration:
<browser:menu
id="plone_contentmenu_workflow"
title="The 'workflow' menu - allows the user to execute workflow transitions"
class=".yourmodule.YourWorkflowMenu"
/>
then in yourmodule.py create a YourWorkflowMenu class, something like:
from plone.app.contentmenu.menu import WorkflowMenu
class YourWorkflowMenu(WorkflowMenu):
def getMenuItems(self, context, request):
results = super(YourWorkflowMenu, self).getMenuItems(context, request)
if len(results) > 0 and someothercondition:
# Remove status history menu item ('Advanced...')
results = [r for r in results
if not r['action'].endswith('/content_status_history')]
return results
You should be able to hide the menu item by adding
a#advanced {
display: none;
}
to your styles.
That's a pragmatic solution compared the bloated former clean solution.

CKEditor.net table class

In a asp.net C# webapp I'm using the CKEditor 3.6.2 and I'm facing the following problem:
In my stylesheet I have a CSS class to use in tables and I'm trying to bring this class already filled in the "Table properties", "Advanced" tab and the "Stylesheet Classes" field.
I want to bring this field filled with the string "blue_table", which is the name of my CSS class. I'm working with the source of the "table" plugin. I have figured out how to change the value of fields like width and height, but the one I want is the "Stylesheet Classes" field.
Do any of you know to to set a default value for this field?
You don't have to edit the ckeditor.js file to customise the editor. You can add the following either to config.js and use it site wide or on any page where you're using CKEditor (inside a script tag as below, after the editor fields you're using).
<script type="text/javascript">
CKEDITOR.on( 'dialogDefinition', function( ev ) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested on (the Table dialog).
if ( dialogName == 'table' ) {
// Set the tab
var advTab = dialogDefinition.getContents( 'advanced');
// Grab the field
var stylesField = advTab.get('advCSSClasses');
// Set the default value
stylesField['default'] = 'blue_table';
}
});
</script>
This is modified from the CKEditor documentation. The hardest part is working out the IDs and names for all the fields used in the dialogs.
Finally I found the answer. This property is in the dialogadvtab, in the property "advCSSClasses". The thing is that this plugin is inside the core js, I mean the ckeditor.js.
I had to do this :
children :
[
{
id : 'advCSSClasses',
att : 'class',
type : 'text',
label : lang.cssClasses,
'default' : 'blue_table',
setup : setupAdvParams,
commit : commitAdvParams
}
]
The "problem" now is that I had to do it in the ckeditor.js, which is not a good practice. The problem is solved, but not int the best way.

Resources